nmsg 1.1.2
Data Structures | Functions
ipdg.h File Reference

IP datagram parsing functions. More...

Go to the source code of this file.

Data Structures

struct  nmsg_ipdg
 Parsed IP datagram. More...
 

Functions

nmsg_res nmsg_ipdg_parse (struct nmsg_ipdg *dg, unsigned etype, size_t len, const u_char *pkt)
 Parse IP packets from the network layer, discarding fragments.
 
nmsg_res nmsg_ipdg_parse_pcap (struct nmsg_ipdg *dg, nmsg_pcap_t pcap, struct pcap_pkthdr *pkt_hdr, const u_char *pkt)
 Parse IP datagrams from the data link layer, performing reassembly if necessary.
 
nmsg_res nmsg_ipdg_parse_pcap_raw (struct nmsg_ipdg *dg, int datalink, const uint8_t *pkt, size_t len)
 Like nmsg_ipdg_parse_pcap(), but performs no fragment handling.
 

Detailed Description

IP datagram parsing functions.

These functions parse network packets or ethernet frames and return IP datagrams, performing reassembly if requested. Non-IP packets are discarded.

Definition in file ipdg.h.

Function Documentation

◆ nmsg_ipdg_parse()

nmsg_res nmsg_ipdg_parse ( struct nmsg_ipdg dg,
unsigned  etype,
size_t  len,
const u_char *  pkt 
)

Parse IP packets from the network layer, discarding fragments.

Populate a struct nmsg_ipdg indicating where the network, transport, and payload sections of the packet are and the length of the remaining packet at each of those sections.

This function operates on datagrams from the network layer.

Broken and fragmented datagrams are discarded.

Parameters
[out]dgcaller-allocated struct nmsg_ipdg which will be populated after a successful call.
[in]etypeETHERTYPE_* value. The only supported values are ETHERTYPE_IP and ETHERTYPE_IPV6.
[in]lenlength of the packet.
[in]pktpointer to the packet.
Returns
nmsg_res_success
nmsg_res_again

◆ nmsg_ipdg_parse_pcap()

nmsg_res nmsg_ipdg_parse_pcap ( struct nmsg_ipdg dg,
nmsg_pcap_t  pcap,
struct pcap_pkthdr *  pkt_hdr,
const u_char *  pkt 
)

Parse IP datagrams from the data link layer, performing reassembly if necessary.

Populate a struct nmsg_ipdg indicating where the network, transport, and payload sections of the datagram are and the length of the remaining packet at each of those sections.

This function operates on raw frames returned by libpcap from the data link layer. The packet beginning at 'pkt' must match the datalink type associated with 'pcap' and must be pkt_hdr->caplen octets long.

libpcap data link types DLT_EN10MB, DLT_RAW, and DLT_LINUX_SLL are supported.

Broken packets are discarded. All but the final fragment of a fragmented datagram are stored internally and nmsg_res_again is returned.

Parameters
[out]dgcaller-allocated struct nmsg_ipdg which will be populated after a successful call.
[in]pcapcaller-initialized nmsg_pcap object from whose pcap handle the packet 'pkt' was received.
[in]pkt_hdrpointer to the pcap packet header corresponding to 'pkt'.
[in]pktpointer to the packet.
Returns
nmsg_res_success
nmsg_res_again

◆ nmsg_ipdg_parse_pcap_raw()

nmsg_res nmsg_ipdg_parse_pcap_raw ( struct nmsg_ipdg dg,
int  datalink,
const uint8_t *  pkt,
size_t  len 
)

Like nmsg_ipdg_parse_pcap(), but performs no fragment handling.

Parameters
[out]dgcaller-allocated struct nmsg_ipdg which will be populated after a successful call.
[in]datalinklibpcap data link type.
[in]pktpointer to the packet.
[in]lenlength of the packet.