42#define IPV4_HDR_FLAGS_RESERVED (0x04)
43#define IPV4_HDR_FLAGS_DF (0x02)
44#define IPV4_HDR_FLAGS_MF (0x01)
72typedef struct __attribute__((packed)) {
137 return ((hdr->
v_ihl) >> 4);
148 assert(ihl >= 20 && ihl <= 60);
152 hdr->
v_ihl |= 0x0f & (ihl >> 2);
164 return (hdr->
v_ihl & 0x0f) << 2;
176 hdr->
fl_fo.
u8[0] |= (0xe0 & (flags << 5));
188 return (((hdr->
fl_fo.
u8[0]) >> 5) & 0x07);
200 hdr->
fl_fo.
u8[0] |= (0x1f & (fo >> 8));
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Functions to work with different byte orders.
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
static uint8_t ipv4_hdr_get_flags(ipv4_hdr_t *hdr)
Gets the value of the Version Control Flags field of hdr.
static void ipv4_hdr_set_flags(ipv4_hdr_t *hdr, uint8_t flags)
Sets the Version Control Flags field of hdr.
static void ipv4_hdr_set_ihl(ipv4_hdr_t *hdr, uint16_t ihl)
Sets the Internet Header Length field of hdr.
static uint16_t ipv4_hdr_get_ihl(ipv4_hdr_t *hdr)
Gets the value of the Internet Header Length field of hdr.
static uint8_t ipv4_hdr_get_version(ipv4_hdr_t *hdr)
Gets the value of the version field of hdr.
static uint16_t ipv4_hdr_get_fo(ipv4_hdr_t *hdr)
Gets the value of the Fragment Offset field of hdr.
static void ipv4_hdr_set_version(ipv4_hdr_t *hdr)
Sets the version field of hdr to 4.
static void ipv4_hdr_set_fo(ipv4_hdr_t *hdr, uint16_t fo)
Sets the Fragment Offset field of hdr.
IPv4 address type and helper functions definitions.
Data type to represent an IPv4 packet header.
network_uint16_t tl
total length of the datagram
ipv4_addr_t src
source address of this packet
uint8_t protocol
protocol of this packet
uint8_t v_ihl
Version and Internet Header Length.
network_uint16_t csum
checksum of this packet
ipv4_addr_t dst
destination address of this packet
network_uint16_t fl_fo
Version control flags and Fragment Offset.
uint8_t ttl
time to live for this packet
network_uint16_t id
identification value of packet
uint8_t ts
type of service of packet
uint8_t u8[2]
8 bit representation
Data type to represent an IPv4 address.