bool IcmpData::match_echo_reply(const uint16_t identifier,
const uint16_t sequence_number) const
-{ return false; };
+{ return false; }
bool IcmpData::match_destination_unreachable(const uint16_t identifier,
const uint16_t sequence_number) const
-{ return false; };
+{ return false; }
inline std::size_t IcmpData::get_size()
-{ return size; };
+{ return size; }
uint32_t IcmpData::calc_checksum_part() const
{ return raw_data.calc_checksum_part(); }
is.read(buf.get(), 4);
type = static_cast<uint8_t>(buf[0]);
code = static_cast<uint8_t>(buf[1]);
+
+ // first make the 2 checksum byte unsigned with same size
uint8_t checksum_msb = static_cast<uint8_t>(buf[2]);
uint8_t checksum_lsb = static_cast<uint8_t>(buf[3]);
- checksum = ( static_cast<uint16_t>(checksum_msb) << 8 )
- + static_cast<uint16_t>(checksum_lsb);
+
+ // now extend type, shift and add/or them
+ checksum = static_cast<uint16_t>(
+ (static_cast<uint16_t>(checksum_msb) << 8)
+ | static_cast<uint16_t>(checksum_lsb) );
+ // need the static_cast around the result since compiler casts everything
+ // to int before doing | or + if types are smaller than int
return is;
}
return ( Payload[ 0 ] >> 4 ) & 0x0F;
}
+uint16_t Ipv6Header::get_header_length() const
+{ return static_cast<uint16_t>(40); }
+
+uint16_t Ipv6Header::get_total_length() const
+{
+ // the compiler converts anything smaller than int to int when adding
+ // which results in a warning when assigning the result to uint16
+ return static_cast<uint16_t>( get_payload_length() + 40 );
+}
+
+// in IPv6, this corresponds to the "HOP limit"
+uint8_t Ipv6Header::get_time_to_live() const
+{ return get_hop_limit(); }
+
/**
* @brief Get the Differentiated Services, originally called Traffic Class.
*
uint8_t get_next_header() const;
uint8_t get_hop_limit() const;
- uint16_t get_header_length() const
- { return 40; }
+ uint16_t get_header_length() const;
- uint16_t get_total_length() const
- { return get_payload_length() + 40; }
+ uint16_t get_total_length() const;
// in IPv6, this corresponds to the "HOP limit"
- uint8_t get_time_to_live() const
- { return get_hop_limit(); }
+ uint8_t get_time_to_live() const;
boost::asio::ip::address get_source_address() const;
boost::asio::ip::address get_destination_address() const;