IcmpHeader::IcmpHeader()
{
- std::fill( Rep, Rep + sizeof(Rep), 0 );
+ std::fill( Payload, Payload + sizeof(Payload), 0 );
}
IcmpHeader::IcmpHeader(
uint16_t sequence_number
)
{
- std::fill( Rep, Rep + sizeof(Rep), 0 );
+ std::fill( Payload, Payload + sizeof(Payload), 0 );
set_type( type );
set_code( code );
IcmpHeader::IcmpType IcmpHeader::get_type() const
{
- uint8_t n = Rep[ 0 ];
+ uint8_t n = Payload[ 0 ];
IcmpHeader::IcmpType type = static_cast<IcmpHeader::IcmpType> ( n );
return type;
{
uint8_t n = type;
- Rep[ 0 ] = n;
+ Payload[ 0 ] = n;
}
uint8_t IcmpHeader::get_code() const
{
- return Rep[ 1 ];
+ return Payload[ 1 ];
}
void IcmpHeader::set_code( uint8_t code )
{
- Rep[ 1 ] = code;
+ Payload[ 1 ] = code;
}
uint16_t IcmpHeader::get_checksum() const
IcmpHeader &header
)
{
- return is.read( reinterpret_cast<char*> ( header.Rep ), 8 );
+ return is.read( reinterpret_cast<char *> ( header.Payload ), 8 );
}
std::ostream& operator<<(
const IcmpHeader &header
)
{
- return os.write( reinterpret_cast<const char*> ( header.Rep ), 8 );
+ return os.write( reinterpret_cast<const char *> ( header.Payload ), 8 );
}
-uint16_t IcmpHeader::decode( int a, int b ) const
+uint16_t IcmpHeader::decode( int left_byte, int right_byte ) const
{
- return ( Rep[ a ] << 8 ) + Rep[ b ];
+ return ( Payload[ left_byte ] << 8 ) + Payload[ right_byte ];
}
-void IcmpHeader::encode( int a, int b, uint16_t n )
+void IcmpHeader::encode( int left_byte, int right_byte, uint16_t value )
{
- Rep[ a ] = static_cast<uint8_t> ( n >> 8 );
- Rep[ b ] = static_cast<uint8_t> ( n & 0xFF );
+ Payload[ left_byte ] = static_cast<uint8_t> ( value >> 8 );
+ Payload[ right_byte ] = static_cast<uint8_t> ( value & 0xFF );
}
// Ipv4Header
//-----------------------------------------------------------------------------
+const int Ipv4Header::HeaderSizeInBytes = 20;
+
Ipv4Header::Ipv4Header()
{
- fill( Rep, Rep + sizeof(Rep), 0 );
+ fill( Payload, Payload + sizeof(Payload), 0 );
}
uint8_t Ipv4Header::get_version() const
{
- return ( Rep[ 0 ] >> 4 ) & 0xF;
+ return ( Payload[ 0 ] >> 4 ) & 0xF;
}
uint16_t Ipv4Header::get_header_length() const
{
- return ( Rep[ 0 ] & 0xF ) * 4;
+ return ( Payload[ 0 ] & 0xF ) * 4;
}
uint8_t Ipv4Header::get_type_of_service() const
{
- return Rep[ 1 ];
+ return Payload[ 1 ];
}
uint16_t Ipv4Header::get_total_length() const
bool Ipv4Header::dont_fragment() const
{
- return ( ( Rep[ 6 ] & 0x40 ) != 0 );
+ return ( ( Payload[ 6 ] & 0x40 ) != 0 );
}
bool Ipv4Header::more_fragments() const
{
- return ( ( Rep[ 6 ] & 0x20 ) != 0 );
+ return ( ( Payload[ 6 ] & 0x20 ) != 0 );
}
uint16_t Ipv4Header::get_fragment_offset() const
uint8_t Ipv4Header::get_time_to_live() const
{
- return Rep[ 8 ];
+ return Payload[ 8 ];
}
uint8_t Ipv4Header::get_protocol() const
{
- return Rep[ 9 ];
+ return Payload[ 9 ];
}
uint16_t Ipv4Header::get_header_checksum() const
address_v4 Ipv4Header::get_source_address() const
{
address_v4::bytes_type bytes = { {
- Rep[ 12 ],
- Rep[ 13 ],
- Rep[ 14 ],
- Rep[ 15 ] } };
+ Payload[ 12 ],
+ Payload[ 13 ],
+ Payload[ 14 ],
+ Payload[ 15 ]
+ } };
return address_v4( bytes );
}
address_v4 Ipv4Header::get_destination_address() const
{
address_v4::bytes_type bytes = { {
- Rep[ 16 ],
- Rep[ 17 ],
- Rep[ 18 ],
- Rep[ 19 ] } };
+ Payload[ 16 ],
+ Payload[ 17 ],
+ Payload[ 18 ],
+ Payload[ 19 ]
+ } };
return address_v4( bytes );
}
Ipv4Header &header
)
{
- (void) is.read( reinterpret_cast<char*> ( header.Rep ), 20 );
+ (void) is.read(
+ reinterpret_cast<char*> ( header.Payload ),
+ Ipv4Header::HeaderSizeInBytes
+ );
+
if ( header.get_version() != 4 )
is.setstate( ios::failbit );
- streamsize options_length = (streamsize) header.get_header_length() - 20;
+ streamsize options_length =
+ (streamsize) header.get_header_length() -
+ Ipv4Header::HeaderSizeInBytes;
if ( options_length < 0 || 40 < options_length )
{
is.setstate( ios::failbit );
else
{
(void) is.read(
- reinterpret_cast<char*> ( header.Rep ) + 20,
+ reinterpret_cast<char*> ( header.Payload ) +
+ Ipv4Header::HeaderSizeInBytes,
options_length
);
}
return is;
}
-uint16_t Ipv4Header::decode( int a, int b ) const
+uint16_t Ipv4Header::decode( int left_byte, int right_byte ) const
{
- return ((Rep[ a ] << 8) + Rep[ b ]);
+ return ( (Payload[ left_byte ] << 8) + Payload[ right_byte ] );
}