All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Enumerations | Functions | Variables
net.h File Reference

Structures and functions for parsing raw network packets. More...

Go to the source code of this file.


#define ETHER_ADDR_LEN   6
#define ETHER_HDR_LEN   22
#define I_DF   0x4000
 Dont fragment flag. More...
#define IP_HDR_LEN   60
#define IP_HL(ip)   ((ip)->ip_vhl & 0x0f)
#define IP_MF   0x2000
 More fragments flag. More...
#define IP_OFFMASK   0x1fff
 Mask for fragmenting bits. More...
#define IP_V(ip)   (((ip)->ip_vhl & 0xf0) >> 4)
#define IP_VHL(v, hl)   ((v & 0x0f) << 4) | (hl & 0x0f)
#define MAX_RADIUS_LEN   4096
#define MIN_RADIUS_LEN   20
#define RADIUS_HDR_LEN   20


enum  fr_dlt {


struct CC_HINT (__packed__) ethernet_header
uint16_t fr_ip_header_checksum (uint8_t const *data, uint8_t ihl)
 Calculate IP header checksum. More...
ssize_t fr_link_layer_offset (uint8_t const *data, size_t len, int link_layer)
 Returns the length of the link layer header. More...
bool fr_link_layer_supported (int link_layer)
 Check whether fr_link_layer_offset can process a link_layer. More...
uint16_t fr_udp_checksum (uint8_t const *data, uint16_t len, uint16_t checksum, struct in_addr const src_addr, struct in_addr const dst_addr)
 Calculate UDP checksum. More...
int fr_udp_header_check (uint8_t const *data, uint16_t remaining, ip_header_t const *ip)
 Check UDP header is valid. More...


FR_NAME_NUMBER const fr_net_af_table []
 Strings for address families. More...
FR_NAME_NUMBER const fr_net_ip_proto_table []
 Strings for L4 protocols. More...
FR_NAME_NUMBER const fr_net_sock_type_table []
 Strings for socket types. More...

Detailed Description

Structures and functions for parsing raw network packets.

Arran Cudbard-Bell a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg

Definition in file net.h.

Macro Definition Documentation

#define ETHER_ADDR_LEN   6

Definition at line 53 of file net.h.

#define ETHER_HDR_LEN   22

Definition at line 63 of file net.h.

#define I_DF   0x4000

Dont fragment flag.

Definition at line 85 of file net.h.

#define IP_HDR_LEN   60

Definition at line 64 of file net.h.

#define IP_HL (   ip)    ((ip)->ip_vhl & 0x0f)

Definition at line 81 of file net.h.

#define IP_MF   0x2000

More fragments flag.

Definition at line 86 of file net.h.

#define IP_OFFMASK   0x1fff

Mask for fragmenting bits.

Definition at line 87 of file net.h.

#define IP_V (   ip)    (((ip)->ip_vhl & 0xf0) >> 4)

Definition at line 80 of file net.h.

#define IP_VHL (   v,
)    ((v & 0x0f) << 4) | (hl & 0x0f)

Definition at line 83 of file net.h.

#define MAX_RADIUS_LEN   4096

Definition at line 76 of file net.h.

#define MIN_RADIUS_LEN   20

Definition at line 77 of file net.h.

#define RADIUS_HDR_LEN   20

Definition at line 69 of file net.h.

Enumeration Type Documentation

enum fr_dlt

Definition at line 40 of file net.h.

Function Documentation

struct CC_HINT ( __packed__  )

< Header length, version.

< Type of service.

< Total length.

< identification.

< Fragment offset field.

< Time To Live.

< Protocol.

< Checksum.

< Src and Dst address

< Version, traffic class, flow label.

< Payload length

< Next header (protocol)

< IP Hop Limit

< Src and Dst address

< Source port.

< Destination port.

< UDP length.

< UDP checksum.

Definition at line 92 of file net.h.

uint16_t fr_ip_header_checksum ( uint8_t const *  data,
uint8_t  ihl 

Calculate IP header checksum.

Zero out IP header checksum in IP header before calling fr_ip_header_checksum to get 'expected' checksum.

dataPointer to the start of the IP header
ihlvalue of ip header length field (number of 32 bit words)

Definition at line 275 of file net.c.

ssize_t fr_link_layer_offset ( uint8_t const *  data,
size_t  len,
int  link_layer 

Returns the length of the link layer header.

Libpcap does not include a decoding function to skip the L2 header, but it does at least inform us of the type.

Unfortunately some headers are of variable length (like ethernet), so additional decoding logic is required.

No header data is returned, this is only meant to be used to determine how data to consume before attempting to parse the IP header.
datastart of packet data.
link_layervalue returned from pcap_linktype.
  • Length of the header.
  • -1 on failure.

Definition at line 95 of file net.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fr_link_layer_supported ( int  link_layer)

Check whether fr_link_layer_offset can process a link_layer.

link_layerto check.
  • true if supported.
  • false if not supported.

Definition at line 61 of file net.c.

+ Here is the caller graph for this function:

uint16_t fr_udp_checksum ( uint8_t const *  data,
uint16_t  len,
uint16_t  checksum,
struct in_addr const  src_addr,
struct in_addr const  dst_addr 

Calculate UDP checksum.

Zero out UDP checksum in UDP header before calling fr_udp_checksum to get 'expected' checksum.

dataPointer to the start of the UDP header
lenvalue of udp length field in host byte order. Must be validated to make sure it won't overrun data buffer.
checksumcurrent checksum, leave as 0 to just enable validation.
src_addrin network byte order.
dst_addrin network byte order.
  • 0 if the checksum is correct.
  • !0 if checksum is incorrect.

Definition at line 240 of file net.c.

+ Here is the caller graph for this function:

int fr_udp_header_check ( uint8_t const *  data,
uint16_t  remaining,
ip_header_t const *  ip 

Check UDP header is valid.

dataPointer to the start of the UDP header
remainingbits of received packet
ippointer to IP header structure
  • 1 if checksum is incorrect.
  • 0 if UDP payload lenght and checksum are correct
  • -1 on validation error.

Definition at line 186 of file net.c.

+ Here is the call graph for this function:

Variable Documentation


Definition at line 96 of file net.h.

FR_NAME_NUMBER const fr_net_af_table[]

Strings for address families.

Definition at line 48 of file net.c.

FR_NAME_NUMBER const fr_net_ip_proto_table[]

Strings for L4 protocols.

Definition at line 30 of file net.c.

FR_NAME_NUMBER const fr_net_sock_type_table[]

Strings for socket types.

Definition at line 39 of file net.c.


Definition at line 123 of file net.h.


Definition at line 113 of file net.h.

Definition at line 142 of file net.h.


Definition at line 134 of file net.h.