nmsg 1.1.2
Enumerations | Functions
pcap_input.h File Reference

Reassembled IP datagram interface to libpcap. More...

Go to the source code of this file.

Enumerations

enum  nmsg_pcap_type {
  nmsg_pcap_type_file ,
  nmsg_pcap_type_live
}
 

Functions

nmsg_pcap_t nmsg_pcap_input_open (pcap_t *phandle)
 Initialize a new nmsg_pcap_t input from a libpcap source.
 
nmsg_res nmsg_pcap_input_close (nmsg_pcap_t *pcap)
 Close an nmsg_pcap_t object and release all associated resources.
 
nmsg_res nmsg_pcap_input_read (nmsg_pcap_t pcap, struct nmsg_ipdg *dg, struct timespec *ts)
 Read an IP datagram from an nmsg_pcap_t input, performing reassembly if necessary.
 
nmsg_res nmsg_pcap_input_read_raw (nmsg_pcap_t pcap, struct pcap_pkthdr **pkt_hdr, const uint8_t **pkt_data, struct timespec *ts)
 Read a raw packet from an nmsg_pcap_t input.
 
nmsg_res nmsg_pcap_input_setfilter (nmsg_pcap_t pcap, const char *bpfstr)
 Set a bpf filter on an nmsg_pcap_t object.
 
nmsg_res nmsg_pcap_input_setfilter_raw (nmsg_pcap_t pcap, const char *bpfstr)
 Set a bpf filter on an nmsg_pcap_t object.
 
void nmsg_pcap_input_set_raw (nmsg_pcap_t pcap, bool raw)
 Set raw mode.
 
int nmsg_pcap_snapshot (nmsg_pcap_t pcap)
 Get the snapshot length of the underlying pcap handle.
 
nmsg_pcap_type nmsg_pcap_get_type (nmsg_pcap_t pcap)
 Get the type of the underlying pcap handle.
 
int nmsg_pcap_get_datalink (nmsg_pcap_t pcap)
 Get the datalink type of the underlying pcap handle.
 
bool nmsg_pcap_filter (nmsg_pcap_t pcap, const uint8_t *pkt, size_t len)
 Return the result of filtering a packet.
 

Detailed Description

Reassembled IP datagram interface to libpcap.

libpcap's frame-based interface is wrapped with calls to the ipdg.h interface and provides the caller with reassembled IP datagrams.

Callers should not call pcap_setfilter() on the pcap_t handle passed to nmsg_pcap_input_open() but should instead use nmsg_pcap_input_setfilter(). Since IP datagrams are reassembled in userspace, they must undergo reevaluation of the user-provided filter. nmsg_pcap_input_setfilter() and nmsg_pcap_input_read() handle this transparently.

Definition in file pcap_input.h.

Enumeration Type Documentation

◆ nmsg_pcap_type

enum nmsg_pcap_type

Definition at line 33 of file pcap_input.h.

Function Documentation

◆ nmsg_pcap_input_open()

nmsg_pcap_t nmsg_pcap_input_open ( pcap_t *  phandle)

Initialize a new nmsg_pcap_t input from a libpcap source.

Parameters
[in]phandlepcap_t handle (e.g., acquired from pcap_open_offline() or pcap_open_live()).
Returns
Opaque pointer that is NULL on failure or non-NULL on success.

◆ nmsg_pcap_input_close()

nmsg_res nmsg_pcap_input_close ( nmsg_pcap_t *  pcap)

Close an nmsg_pcap_t object and release all associated resources.

Parameters
[in]pcappointer to an nmsg_pcap_t object.

◆ nmsg_pcap_input_read()

nmsg_res nmsg_pcap_input_read ( nmsg_pcap_t  pcap,
struct nmsg_ipdg dg,
struct timespec *  ts 
)

Read an IP datagram from an nmsg_pcap_t input, performing reassembly if necessary.

Parameters
[in]pcapnmsg_pcap_t object.
[out]dgnmsg_ipdg structure to be filled.
[out]tstimespec structure indicating time of datagram reception.
Returns
nmsg_res_success
nmsg_res_pcap_error
nmsg_res_again

◆ nmsg_pcap_input_read_raw()

nmsg_res nmsg_pcap_input_read_raw ( nmsg_pcap_t  pcap,
struct pcap_pkthdr **  pkt_hdr,
const uint8_t **  pkt_data,
struct timespec *  ts 
)

Read a raw packet from an nmsg_pcap_t input.

Parameters
[in]pcapnmsg_pcap_t object.
[out]pkt_hdrLocation to store pcap packet header.
[out]pkt_dataLocation to store pcap packet data.
[out]tstimespec structure indicating time of packet reception.
Returns
nmsg_res_success
nmsg_res_pcap_error
nmsg_res_again

◆ nmsg_pcap_input_setfilter()

nmsg_res nmsg_pcap_input_setfilter ( nmsg_pcap_t  pcap,
const char *  bpfstr 
)

Set a bpf filter on an nmsg_pcap_t object.

This function performs additional transformation on the bpf filter text before passing the filter to pcap_compile() and pcap_setfilter().

Parameters
[in]pcapnmsg_pcap_t object.
[in]bpfstris a valid bpf filter expression that will be passed to pcap_compile().
Returns
nmsg_res_success
nmsg_res_failure

◆ nmsg_pcap_input_setfilter_raw()

nmsg_res nmsg_pcap_input_setfilter_raw ( nmsg_pcap_t  pcap,
const char *  bpfstr 
)

Set a bpf filter on an nmsg_pcap_t object.

This function is a thin wrapper for pcap_setfilter().

Parameters
[in]pcapnmsg_pcap_t object.
[in]bpfstris a valid bpf filter expression that will be passed to pcap_compile() and pcap_setfilter().
Returns
nmsg_res_success
nmsg_res_failure

◆ nmsg_pcap_input_set_raw()

void nmsg_pcap_input_set_raw ( nmsg_pcap_t  pcap,
bool  raw 
)

Set raw mode.

Parameters
[in]pcapnmsg_pcap_t object.
[in]rawTrue if raw packets should be passed, false if reassembled datagrams should be passed.

◆ nmsg_pcap_snapshot()

int nmsg_pcap_snapshot ( nmsg_pcap_t  pcap)

Get the snapshot length of the underlying pcap handle.

Parameters
[in]pcapnmsg_pcap_t object.
Returns
Pcap snapshot length.

◆ nmsg_pcap_get_type()

nmsg_pcap_type nmsg_pcap_get_type ( nmsg_pcap_t  pcap)

Get the type of the underlying pcap handle.

Parameters
[in]pcapnmsg_pcap_t object.
Returns
nmsg_pcap_type_file
nmsg_pcap_type_live

◆ nmsg_pcap_get_datalink()

int nmsg_pcap_get_datalink ( nmsg_pcap_t  pcap)

Get the datalink type of the underlying pcap handle.

Parameters
[in]pcapnmsg_pcap_t object.

◆ nmsg_pcap_filter()

bool nmsg_pcap_filter ( nmsg_pcap_t  pcap,
const uint8_t *  pkt,
size_t  len 
)

Return the result of filtering a packet.

Parameters
[in]pcapnmsg_pcap_t object.
[in]pktPointer to start of network packet.
[in]lenLength of packet.
Returns
false if packet failed the filter
true if packet passed the filter