// Icmpv4Header
//-----------------------------------------------------------------------------
+static const size_t HeaderSizeInBytes = 8;
+
Icmpv4Header::Icmpv4Header() :
MessageFormat()
{
set_icmp_message_format( header_type );
}
+size_t Icmpv4Header::get_header_length() const
+{
+ return HeaderSizeInBytes;
+}
+
std::istream& operator>>(
std::istream &is,
Icmpv4Header &header
void set_icmp_message_format( const Icmpv4Type type );
void set_icmp_message_format( std::istream &is );
+ size_t get_header_length() const;
+
friend std::istream& operator>>(
std::istream &is,
Icmpv4Header &header
is >> packet.IcmpPayloadHeader;
if (is.good())
{
- streamsize data_length = static_cast<streamsize>( packet.IpHeader.get_total_length() ) -
- static_cast<streamsize>( packet.IpHeader.get_header_length() );
+ streamsize data_length = static_cast<streamsize>( packet.IpHeader.get_total_length() )
+ - static_cast<streamsize>( packet.IpHeader.get_header_length() )
+ - static_cast<streamsize>( packet.IcmpPayloadHeader.get_header_length() );
if ( data_length < 0 )
{
- GlobalLogger.error() << "Error: invalid size for optional ICMP data: " << data_length << endl;
+ GlobalLogger.error() << "Error: invalid size for optional ICMP data: "
+ << data_length << endl;
is.setstate( ios::failbit );
}
else if ( data_length > 0 )
{
size_t options_size = static_cast<size_t>( data_length );
- scoped_array<uint8_t> scoped_data( new uint8_t[options_size] );
+ scoped_array<uint8_t> scoped_data( new uint8_t[options_size+1] ); // need a 0 after data
+ memset(scoped_data.get(), 0, (options_size+1)*sizeof(uint8_t));
char *char_data = reinterpret_cast<char *>( scoped_data.get() );
(void) is.read( char_data, data_length );
// Icmpv6Header
//-----------------------------------------------------------------------------
+static const size_t HeaderSizeInBytes = 4;
+
Icmpv6Header::Icmpv6Header() :
MessageFormat()
{
set_icmp_message_format( header_type );
}
+size_t Icmpv6Header::get_header_length() const
+{
+ return HeaderSizeInBytes;
+}
+
std::istream& operator>>(
std::istream &is,
Icmpv6Header &header
void set_icmp_message_format( const Icmpv6Type type );
void set_icmp_message_format( std::istream &is );
+ size_t get_header_length() const;
+
friend std::istream& operator>>(
std::istream &is,
Icmpv6Header &header
if ( header_version != 4 )
{
GlobalLogger.error() << "Error: invalid IP header version: " << static_cast<int>(header_version) << endl;
+
is.setstate( ios::failbit );
return is;
}
{
size_t options_size = static_cast<size_t>( options_length );
scoped_array<uint8_t> options_data( new uint8_t[options_size] );
+ memset(options_data.get(), 0, options_size*sizeof(uint8_t));
char *options_data_array = reinterpret_cast<char *>( options_data.get() );
(void) is.read( options_data_array, options_length );