Whisper Library
 All Classes Functions Variables Typedefs Enumerations Friends
whisper_library::IpHeaderv4 Class Reference

Represents an Ipv4 header. More...

Public Member Functions

 IpHeaderv4 ()
 Constructor that initializes all fields with 0.
 
 IpHeaderv4 (vector< bool > frame)
 Constructor that extracts the Ipv4 header from a network frame. More...
 
 ~IpHeaderv4 ()
 Destructor.
 
void calculateHeaderLength ()
 Calculates the length of the header and sets the corresponding field. More...
 
void calculateChecksum ()
 Calculates the checksum and sets the corresponding field.
 
void print ()
 Prints the content of the ip header as hexadecimal.
 
string info ()
 Creates a string which lists all fields and values in humanly readable form. More...
 
vector< bool > toVector ()
 
unsigned int version ()
 Returns the IP-Version (4 or 6) (4 bit)
 
unsigned int ipHeaderLength ()
 Returns the length of the IP header : length * 32 bit (4 bit)
 
unsigned int typeOfService ()
 Returns the type of service, which is used for packet prioritization (8 bit)
 
unsigned int totalLength ()
 Returns the total length of the packet in byte(maximum 65536 Byte = 64 KiB) (16 bit)
 
unsigned int identification ()
 Returns the unique identifier to reassemble fragmented IP-Datagrams (16 bit)
 
bool flagReserved ()
 Returns the reserved flag, has to be 0 (1 bit)
 
bool flagDontFragment ()
 Returns the 'don't fragment' bit.
 
bool flagFragmented ()
 Returns a flag that indicates, wether there are more fragments coming or not (0 if only or last fragment) (1 bit)
 
unsigned int offset ()
 Returns the fragment position (0 if not fragmented) (12 bit)
 
unsigned int timeToLive ()
 Returns the time to live, drop packet if 0, reduce at each hop (4 bit)
 
unsigned int protocol ()
 Returns the application layer protocol id (4 bit)
 
unsigned int checksum ()
 Returns the Ip header checksum (16 bit)
 
unsigned long sourceIp ()
 Returns the Ip address of the sender (32 bit)
 
string sourceIpDotted ()
 Returns the ip address of the sender in dotted form.
 
unsigned long destinationIp ()
 Returns the Ip address of the receiver(32 bit)
 
string destinationIpDotted ()
 Returns the Ip address of the receiver in dotted form.
 
void setVersion (unsigned int version)
 Sets the IP-Version (4 or 6) (4 bit)
 
void setTypeOfService (unsigned int tos)
 Sets the type of service, which is used for packet prioritization (8 bit)
 
void setTotalLength (unsigned int total_length)
 Sets the total length of the packet in byte (maximum 65536 Byte = 64 KiB) (16 bit)
 
void setIdentification (unsigned int identification)
 Sets the unique identifier to reassemble fragmented IP-Datagrams (16 bit)
 
void setFlagReserved (bool flag)
 Sets the reserved flag, has to be 0 (1 bit)
 
void setFlagdontFragment (bool flag)
 Sets the 'don't fragment' bit.
 
void setFlagFragmented (bool flag)
 Sets a flag that indicates, wether there are more fragments coming or not (0 if only or last fragment) (1 bit)
 
void setOffset (unsigned int offset)
 Sets the fragment position (0 if not fragmented) (12 bit)
 
void setTimeToLive (unsigned int ttl)
 Sets the time to live, drop packet if 0, reduce at each hop (4 bit)
 
void setProtocol (unsigned int protocol_id)
 Sets the application layer protocol id (4 bit)
 
void setSourceIp (unsigned long source_ip)
 Sets the Ip address of the sender (32 bit)
 
void setSourceIp (string source_ip)
 Sets the ip address of the sender in dotted form.
 
void setDestinationIp (unsigned long destination_ip)
 Sets the Ip address of the receiver(32 bit)
 
void setDestinationIp (string destination_ip)
 Sets the Ip address of the receiver in dotted form.
 

Static Public Attributes

static const unsigned int TCP = 6
 Protocol id of tcp.
 
static const unsigned int UDP = 17
 Protocol id of udp.
 

Private Member Functions

string ipToDotted (unsigned long ip)
 Converts an ip to its dotted form. More...
 
unsigned long ipToUlong (string ip)
 Converts an ip to decimal. More...
 

Private Attributes

unsigned char * m_head
 Holds the 20 byte ip header.
 

Detailed Description

Represents an Ipv4 header.

This class provides getters and setters for all Ipv4 header fields, except the options-field. The content is exported as binary by using 'toVector'.

Constructor & Destructor Documentation

whisper_library::IpHeaderv4::IpHeaderv4 ( vector< bool >  frame)

Constructor that extracts the Ipv4 header from a network frame.

Parameters
framebinary network frame in little endian

Member Function Documentation

void whisper_library::IpHeaderv4::calculateHeaderLength ( )

Calculates the length of the header and sets the corresponding field.

Since the options field is not supported yet, the default value '5' is set (5x32bit)

string whisper_library::IpHeaderv4::info ( )

Creates a string which lists all fields and values in humanly readable form.

Returns
String with all field values
string whisper_library::IpHeaderv4::ipToDotted ( unsigned long  ip)
private

Converts an ip to its dotted form.

Parameters
ipip as decimal
Returns
ip in dotted form
unsigned long whisper_library::IpHeaderv4::ipToUlong ( string  ip)
private

Converts an ip to decimal.

Parameters
ipip in dotted form
Returns
ip as decimal
vector< bool > whisper_library::IpHeaderv4::toVector ( )

Converts the ip header to binary /return binary representation of the ip header in little endian