Group PJ_PCAP
- group PJ_PCAP
This module describes simple utility to read PCAP file. It is not intended to support all PCAP features (that’s what libpcap is for!), but it can be useful for example to playback or stream PCAP contents.
Typedefs
-
typedef struct pj_pcap_file pj_pcap_file
Opaque declaration for PCAP file
Enums
Functions
-
void pj_pcap_filter_default(pj_pcap_filter *filter)
Initialize filter with default values. The default value is to allow any packets.
- Parameters:
filter – Filter to be initialized.
-
pj_status_t pj_pcap_open(pj_pool_t *pool, const char *path, pj_pcap_file **p_file)
Open PCAP file.
- Parameters:
pool – Pool to allocate memory.
path – File/path name.
p_file – Pointer to receive PCAP file handle.
- Returns:
PJ_SUCCESS if file can be opened successfully.
-
pj_status_t pj_pcap_close(pj_pcap_file *file)
Close PCAP file.
- Parameters:
file – PCAP file handle.
- Returns:
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pj_pcap_set_filter(pj_pcap_file *file, const pj_pcap_filter *filter)
Configure filter for reading the file. When filter is configured, only packets matching all the filter settings will be returned.
- Parameters:
file – PCAP file handle.
filter – The filter.
- Returns:
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pj_pcap_read_udp(pj_pcap_file *file, pj_pcap_udp_hdr *udp_hdr, pj_uint8_t *udp_payload, pj_size_t *udp_payload_size)
Read UDP payload from the next packet in the PCAP file. Optionally it can return the UDP header, if caller supplies it.
- Parameters:
file – PCAP file handle.
udp_hdr – Optional buffer to receive UDP header.
udp_payload – Buffer to receive the UDP payload.
udp_payload_size – On input, specify the size of the buffer. On output, it will be filled with the actual size of the payload as read from the packet.
- Returns:
PJ_SUCCESS on success, or the appropriate error code.
-
struct pj_pcap_udp_hdr
- #include <pcap.h>
This describes UDP header, which may optionally be returned in pj_pcap_read_udp() function. All fields are in network byte order.
Public Members
-
pj_uint16_t src_port
Source port.
-
pj_uint16_t dst_port
Destination port
-
pj_uint16_t len
Length.
-
pj_uint16_t csum
Checksum.
-
pj_uint16_t src_port
-
struct pj_pcap_filter
- #include <pcap.h>
This structure describes the filter to be used when reading packets from a PCAP file. When a filter is configured, only packets matching all the filter specifications will be read from PCAP file.
Public Members
-
pj_pcap_link_type link
Select data link type, or zero to include any supported data links.
-
pj_pcap_proto_type proto
Select protocol, or zero to include all supported protocols.
-
pj_uint32_t ip_src
Specify source IP address of the packets, or zero to include packets from any IP addresses. Note that IP address here must be in network byte order.
-
pj_uint32_t ip_dst
Specify destination IP address of the packets, or zero to include packets destined to any IP addresses. Note that IP address here must be in network byte order.
-
pj_uint16_t src_port
Specify source port of the packets, or zero to include packets with any source port number. Note that the port number must be in network byte order.
-
pj_uint16_t dst_port
Specify destination port of the packets, or zero to include packets with any destination port number. Note that the port number must be in network byte order.
-
pj_pcap_link_type link
-
typedef struct pj_pcap_file pj_pcap_file