xorp

IpHeader4 Class Reference

IPv4 packet header. More...

#include <packet.hh>

Inheritance diagram for IpHeader4:
IpHeader4Writer

List of all members.

Public Member Functions

 IpHeader4 (const uint8_t *data)
const uint8_t * data () const
 Get the buffer data.
uint8_t ip_vhl () const
 Methods to get various IP header fields.
uint8_t ip_tos () const
uint16_t ip_len () const
uint16_t ip_id () const
uint16_t ip_off () const
uint8_t ip_ttl () const
uint8_t ip_p () const
uint16_t ip_sum () const
IPv4 ip_src () const
IPv4 ip_dst () const
uint16_t ip_len_host () const
uint8_t ip_version () const
 Get the IP protocol version of the header.
uint8_t ip_header_len () const
 Get the IPv4 packet header size (including any header options).
uint16_t ip_fragment_offset () const
 Get the IPv4 fragment offset (excluding the fragment flags).
uint16_t ip_fragment_flags () const
 Get the IPv4 fragment flags.
bool is_valid_version () const
 Test whether the IP header version is valid.
int fragment (size_t mtu, list< vector< uint8_t > > &fragments, bool do_checksum, string &error_msg) const
 Fragment an IPv4 packet.

Static Public Member Functions

static size_t size ()
 Get the IPv4 packet header size.

Static Public Attributes

static const size_t SIZE = 20
static const uint8_t IP_VERSION = 4

Static Protected Attributes

static const uint16_t FRAGMENT_OFFSET_MASK = 0x1fff
static const uint16_t FRAGMENT_FLAGS_MASK = 0xe000
static const uint16_t FRAGMENT_FLAGS_IP_DF = 0x4000
static const uint16_t FRAGMENT_FLAGS_IP_MF = 0x2000
static const uint8_t OPTIONS_IPOPT_EOL = 0
static const uint8_t OPTIONS_IPOPT_NOP = 1
static const size_t OPTIONS_IPOPT_OLEN = 1
static const uint8_t OPTIONS_COPIED_FLAG = 0x80
static const size_t _ip_vhl_sizeof = 1
static const size_t _ip_tos_sizeof = 1
static const size_t _ip_len_sizeof = 2
static const size_t _ip_id_sizeof = 2
static const size_t _ip_off_sizeof = 2
static const size_t _ip_ttl_sizeof = 1
static const size_t _ip_p_sizeof = 1
static const size_t _ip_sum_sizeof = 2
static const size_t _ip_src_sizeof = 4
static const size_t _ip_dst_sizeof = 4
static const size_t _ip_vhl_offset = 0
static const size_t _ip_tos_offset = _ip_vhl_offset + _ip_vhl_sizeof
static const size_t _ip_len_offset = _ip_tos_offset + _ip_tos_sizeof
static const size_t _ip_id_offset = _ip_len_offset + _ip_len_sizeof
static const size_t _ip_off_offset = _ip_id_offset + _ip_id_sizeof
static const size_t _ip_ttl_offset = _ip_off_offset + _ip_off_sizeof
static const size_t _ip_p_offset = _ip_ttl_offset + _ip_ttl_sizeof
static const size_t _ip_sum_offset = _ip_p_offset + _ip_p_sizeof
static const size_t _ip_src_offset = _ip_sum_offset + _ip_sum_sizeof
static const size_t _ip_dst_offset = _ip_src_offset + _ip_src_sizeof

Private Attributes

const uint8_t * _data
const uint8_t * _ip_vhl
const uint8_t * _ip_tos
const uint8_t * _ip_len
const uint8_t * _ip_id
const uint8_t * _ip_off
const uint8_t * _ip_ttl
const uint8_t * _ip_p
const uint8_t * _ip_sum
const uint8_t * _ip_src
const uint8_t * _ip_dst

Detailed Description

IPv4 packet header.

The IPv4 packet header has the following content:

ip_vhl (1 byte): // IP ver/hdrlen (version << 4 | header length >> 2) ip_tos (1 byte): // Type of service ip_len (2 bytes): // Total length ip_id (2 bytes): // Identification ip_off (2 bytes): // Fragment offset field (least-significant 13 bits) ip_ttl (1 byte): // Time to live ip_p (1 byte): // Protocol ip_sum (2 bytes): // Checksum ip_src (4 bytes): // Source address ip_dst (4 bytes): // Destination address


Member Function Documentation

const uint8_t* IpHeader4::data ( ) const [inline]

Get the buffer data.

Returns:
the buffer data.
int IpHeader4::fragment ( size_t  mtu,
list< vector< uint8_t > > &  fragments,
bool  do_checksum,
string &  error_msg 
) const

Fragment an IPv4 packet.

Note: If the original packet is not larger than the MTU, then the packet is not fragmented (i.e., fragments is empty), and the return value is XORP_OK.

Parameters:
mtuthe MTU for fragmenting the packet.
fragmentsthe return-by-reference fragments of the IPv4 packet.
do_checksumif true, compute and set the checksum in the IPv4 header, otherwise reset it to zero.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
uint16_t IpHeader4::ip_fragment_flags ( ) const [inline]

Get the IPv4 fragment flags.

Returns:
the IPv4 fragment flags.
uint16_t IpHeader4::ip_fragment_offset ( ) const [inline]

Get the IPv4 fragment offset (excluding the fragment flags).

Returns:
the IPv4 fragment offset (excluding the fragment flags).
uint8_t IpHeader4::ip_header_len ( ) const [inline]

Get the IPv4 packet header size (including any header options).

Returns:
the IPv4 packet header size (including any header options).
uint8_t IpHeader4::ip_version ( ) const [inline]

Get the IP protocol version of the header.

Returns:
the IP protocol version of the header.
bool IpHeader4::is_valid_version ( ) const [inline]

Test whether the IP header version is valid.

Returns:
true if the IP header version is valid, otherwise false.
static size_t IpHeader4::size ( ) [inline, static]

Get the IPv4 packet header size.

Note that this is the header size only without any header options.

Returns:
the IPv4 packet header size.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations