IPv4 header

IPv4 header types and helper functions.

void ipv4_hdr_set_version(ipv4_hdr_t * hdr)

Sets the version field of hdr to 6.

Parameters

hdr:Pointer to an IPv4 header.

uint8_t ipv4_hdr_get_version(ipv4_hdr_t * hdr)

Gets the value of the version field of hdr.

Parameters

hdr:Pointer to an IPv4 header.

Return values

  • Value of the version field of hdr.
void ipv4_hdr_set_ihl(ipv4_hdr_t * hdr, uint16_t ihl)

Sets the Internet Header Length field of hdr.

Parameters

hdr:Pointer to an IPv4 header.
ihl:Size in bytes of the Internet Header Length (including padding)

uint16_t ipv4_hdr_get_ihl(ipv4_hdr_t * hdr)

brief Gets the value of the Internet Header Length field of hdr

Parameters

hdr:Pointer to an IPv4 header.

Return values

  • Size in bytes of the Internet Header Length field of hdr
void ipv4_hdr_set_flags(ipv4_hdr_t * hdr, uint8_t flags)

Sets the Version Control Flags field of hdr.

Parameters

hdr:Pointer to an IPv4 header.
flags:The new value of flags

uint8_t ipv4_hdr_get_flags(ipv4_hdr_t * hdr)

brief Gets the value of the Version Control Flags field of hdr

Parameters

hdr:Pointer to an IPv4 header.

Return values

  • Value of the Version Control field of hdr
void ipv4_hdr_set_fo(ipv4_hdr_t * hdr, uint16_t fo)

Sets the Fragment Offset field of hdr.

Parameters

hdr:Pointer to an IPv4 header.
fo:The new value of fragment offset

uint16_t ipv4_hdr_get_fo(ipv4_hdr_t * hdr)

brief Gets the value of the Fragment Offset field of hdr

Parameters

hdr:Pointer to an IPv4 header.

Return values

  • Value of the Fragment Offset field of hdr
struct ipv4_hdr_t

Data type to represent an IPv4 packet header.

The structure of the header is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination Address                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

uint8_t v_ih

Version and Internet Header Length.

The version are the 4 most significant bits and the Internet Header Length the 4 next bit (see above).

This module provides helper functions to set, get, and check these fields accordingly:

uint8_t ts

type of service of packet

byteorder.h::network_uint16_t tl

total length of the datagram

byteorder.h::network_uint16_t id

identification value of packet

byteorder.h::network_uint16_t fl_fo

version control flags and Fragment Offset.

The flags are the 3 most significant bits, and the remaining 13 bits are the fragment offfset

This module provides helper functions to set, get, and check these fields accordingly:

uint8_t ttl

time to live for this packet

uint8_t protocol

protocol of this packet

byteorder.h::network_uint16_t csum

checksum of this packet

ipv4_addr_t src

source address of this packet

ipv4_addr_t dst

destination address of this packet