moved remaining implementations in ipv6header.h to cpp; avoid conversion warnings
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 13 Mar 2015 10:49:26 +0000 (11:49 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 13 Mar 2015 10:49:26 +0000 (11:49 +0100)
src/icmp/icmpdata.cpp
src/icmp/icmpheader.cpp
src/ip/ipv6header.cpp
src/ip/ipv6header.h

index f129508..3db5912 100644 (file)
@@ -38,14 +38,14 @@ IcmpData::IcmpData(const std::size_t size_arg)
 
 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();  }
index 5c1ee24..bad7a6e 100644 (file)
@@ -50,10 +50,17 @@ std::istream& IcmpHeader::read(std::istream &is)
     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;
 }
index 4faa518..adc91ca 100644 (file)
@@ -48,6 +48,20 @@ uint8_t Ipv6Header::get_version() const
     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.
  *
index 57db286..31fd8ef 100644 (file)
@@ -75,15 +75,12 @@ public:
     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;