//-----------------------------------------------------------------------------
IcmpMessagePayload::IcmpMessagePayload(
- size_t payload_size_in_bytes
+ const std::size_t &payload_size_in_bytes
) :
PayloadSizeInBytes( payload_size_in_bytes ),
Payload( new uint8_t[ payload_size_in_bytes ] )
{
+ BOOST_ASSERT( 0 < payload_size_in_bytes );
+
fill( Payload.get(), Payload.get() + PayloadSizeInBytes, 0 );
}
IcmpMessagePayload::~IcmpMessagePayload()
{
+ // Payload automatically delete by smart pointer scope end
}
const uint8_t& IcmpMessagePayload::operator[]( size_t offset ) const
{
+ BOOST_ASSERT( offset < PayloadSizeInBytes );
+
return Payload[ offset ];
}
uint8_t& IcmpMessagePayload::operator[]( size_t offset )
{
+ BOOST_ASSERT( offset < PayloadSizeInBytes );
+
return Payload[ offset ];
}
const int right_byte
) const
{
- int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
+ uint32_t value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
- BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits<uint16_t>::max() ) );
+ BOOST_ASSERT( value <= numeric_limits<uint16_t>::max() );
return static_cast<uint16_t> ( value );
}
istream& IcmpMessagePayload::read( istream &is )
{
char *data_array = reinterpret_cast<char *> ( Payload.get() );
- is.read( data_array, PayloadSizeInBytes );
+ (void) is.read( data_array, PayloadSizeInBytes );
- BOOST_ASSERT( is.gcount() == PayloadSizeInBytes );
+ BOOST_ASSERT( static_cast<size_t>(is.gcount()) == PayloadSizeInBytes );
return is;
}
#include <istream>
#include <ostream>
+#include <boost/noncopyable.hpp>
#include <boost/scoped_array.hpp>
+#define NONCOPYABLE( Class ) \
+ private: \
+ Class( const Class & ); \
+ Class & operator= ( const Class & );
+
//-----------------------------------------------------------------------------
// IcmpMessagePayload
//-----------------------------------------------------------------------------
class IcmpMessagePayload
{
public:
- IcmpMessagePayload( std::size_t payload_size_in_bytes );
+ explicit IcmpMessagePayload( const std::size_t &payload_size_in_bytes );
~IcmpMessagePayload();
const uint8_t& operator[]( std::size_t offset ) const;
std::ostream& write( std::ostream &os ) const;
private:
- const int PayloadSizeInBytes;
+ const std::size_t PayloadSizeInBytes;
boost::scoped_array<uint8_t> Payload;
+ NONCOPYABLE( IcmpMessagePayload )
};
#endif /* ICMPMESSAGEPAYLOAD_H */
uint16_t Ipv4Header::decode( int left_byte, int right_byte ) const
{
- int value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
+ uint32_t value = ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
- BOOST_ASSERT( ( 0 <= value ) && ( value <= numeric_limits<uint16_t>::max() ) );
+ BOOST_ASSERT( value <= numeric_limits<uint16_t>::max() );
return static_cast<uint16_t> ( value );
}