// IcmpPinger
//-----------------------------------------------------------------------------
+/// size of buffer used to read from socket in [bytes]
+static const std::size_t SOCKET_BUFFER_SIZE = 65536; // 64kB
+
/**
* @brief Parameterized constructor.
*
// IcmpPinger
//-----------------------------------------------------------------------------
-
-/// size of buffer used to read from socket in [bytes]
-const std::size_t SOCKET_BUFFER_SIZE = 65536; // 64kB
-
/**
* @brief This class performs an ICMP ping to host using Boost Asio.
* Scope: one object per host.
if (is.good())
is >> packet.IcmpPayloadHeader;
if (is.good())
- is >> packet.IcmpPayloadData;
+ {
+ streamsize data_length = static_cast<streamsize>( packet.IpHeader.get_total_length() ) -
+ static_cast<streamsize>( packet.IpHeader.get_header_length() );
+
+ if ( data_length < 0 )
+ {
+ 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] );
+ char *char_data = reinterpret_cast<char *>( scoped_data.get() );
+
+ (void) is.read( char_data, data_length );
+ packet.IcmpPayloadData = char_data;
+ }
+ }
return is;
}