Smart Home firewall
Profile-based Smart Home firewall
Macros | Enumerations | Functions
header.h File Reference

Parser for layer 3 and 4 headers (currently only IP, UDP and TCP) More...

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
#include "packet_utils.h"
Include dependency graph for header.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IPV6_HEADER_LENGTH   40
 
#define UDP_HEADER_LENGTH   8
 

Enumerations

enum  ip_protocol_t { ICMP = 1 , IGMP = 2 , TCP = 6 , UDP = 17 }
 

Functions

size_t get_ipv4_header_length (uint8_t *data)
 
size_t get_ipv6_header_length (uint8_t *data)
 
size_t get_udp_header_length (uint8_t *data)
 
size_t get_tcp_header_length (uint8_t *data)
 
size_t get_l3_header_length (uint8_t *data)
 
size_t get_headers_length (uint8_t *data)
 
uint16_t get_udp_payload_length (uint8_t *data)
 Retrieve the length of a UDP payload. More...
 
uint16_t get_dst_port (uint8_t *data)
 Retrieve the source port from a layer 4 header. More...
 
uint32_t get_ipv4_src_addr (uint8_t *data)
 Retrieve the source address from an IPv4 header. More...
 
uint32_t get_ipv4_dst_addr (uint8_t *data)
 Retrieve the destination address from an IPv4 header. More...
 
uint8_t * get_ipv6_src_addr (uint8_t *data)
 Retrieve the source address from an IPv6 header. More...
 
uint8_t * get_ipv6_dst_addr (uint8_t *data)
 Retrieve the destination address from an IPv6 header. More...
 

Detailed Description

Parser for layer 3 and 4 headers (currently only IP, UDP and TCP)

Parser for layer 3 and 4 headers. Currently supported protocols:

Date
2022-09-09

Enumeration Type Documentation

◆ ip_protocol_t

IP protocols assigned to their protocol number

Function Documentation

◆ get_dst_port()

uint16_t get_dst_port ( uint8_t *  data)

Retrieve the source port from a layer 4 header.

Parameters
datapointer to the start of the layer 4 header
Returns
destination port

◆ get_headers_length()

size_t get_headers_length ( uint8_t *  data)

Retrieve the length of a packet's layer-3 and layer-4 headers.

Parameters
dataa pointer to the start of the packet's layer-3 header
Returns
the size, in bytes, of the UDP header

◆ get_ipv4_dst_addr()

uint32_t get_ipv4_dst_addr ( uint8_t *  data)

Retrieve the destination address from an IPv4 header.

Parameters
datapointer to the start of the IPv4 header
Returns
destination IPv4 address, in network byte order

◆ get_ipv4_header_length()

size_t get_ipv4_header_length ( uint8_t *  data)

Retrieve the length of a packet's IPv4 header.

Parameters
dataa pointer to the start of the packet's IPv4 header
Returns
the size, in bytes, of the IPv4 header

◆ get_ipv4_src_addr()

uint32_t get_ipv4_src_addr ( uint8_t *  data)

Retrieve the source address from an IPv4 header.

Parameters
datapointer to the start of the IPv4 header
Returns
source IPv4 address, in network byte order

◆ get_ipv6_dst_addr()

uint8_t* get_ipv6_dst_addr ( uint8_t *  data)

Retrieve the destination address from an IPv6 header.

Parameters
datapointer to the start of the IPv6 header
Returns
destination IPv6 address, as a 16-byte array

◆ get_ipv6_header_length()

size_t get_ipv6_header_length ( uint8_t *  data)

Retrieve the length of a packet's IPv6 header.

Parameters
dataa pointer to the start of the packet's IPv6 header
Returns
the size, in bytes, of the IPv6 header

◆ get_ipv6_src_addr()

uint8_t* get_ipv6_src_addr ( uint8_t *  data)

Retrieve the source address from an IPv6 header.

Parameters
datapointer to the start of the IPv6 header
Returns
source IPv6 address, as a 16-byte array

◆ get_l3_header_length()

size_t get_l3_header_length ( uint8_t *  data)

Retrieve the length of a packet's layer 3 header (IPv4 or IPv6).

Parameters
dataa pointer to the start of the packet's layer 3 header
Returns
the size, in bytes, of the layer 3 header

◆ get_tcp_header_length()

size_t get_tcp_header_length ( uint8_t *  data)

Retrieve the length of a packet's TCP header.

Parameters
dataa pointer to the start of the packet's TCP (layer 4) header
Returns
the size, in bytes, of the UDP header

◆ get_udp_header_length()

size_t get_udp_header_length ( uint8_t *  data)

Retrieve the length of a packet's UDP header.

Parameters
dataa pointer to the start of the packet's UDP (layer 4) header
Returns
the size, in bytes, of the UDP header

◆ get_udp_payload_length()

uint16_t get_udp_payload_length ( uint8_t *  data)

Retrieve the length of a UDP payload.

Parameters
datapointer to the start of the UDP header
Returns
length of the UDP payload, in bytes