1
/* $Id: pcap.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJLIB_UTIL_PCAP_H__
21
#define __PJLIB_UTIL_PCAP_H__
25
* @brief Simple PCAP file reader
33
* @defgroup PJ_PCAP Simple PCAP file reader
34
* @ingroup PJ_FILE_FMT
36
* This module describes simple utility to read PCAP file. It is not intended
37
* to support all PCAP features (that's what libpcap is for!), but it can
38
* be useful for example to playback or stream PCAP contents.
42
* Enumeration to describe supported data link types.
44
typedef enum pj_pcap_link_type
46
/** Ethernet data link */
47
PJ_PCAP_LINK_TYPE_ETH = 1
53
* Enumeration to describe supported protocol types.
55
typedef enum pj_pcap_proto_type
58
PJ_PCAP_PROTO_TYPE_UDP = 17
64
* This describes UDP header, which may optionally be returned in
65
* #pj_pcap_read_udp() function. All fields are in network byte order.
67
typedef struct pj_pcap_udp_hdr
69
pj_uint16_t src_port; /**< Source port. */
70
pj_uint16_t dst_port; /**< Destination port */
71
pj_uint16_t len; /**< Length. */
72
pj_uint16_t csum; /**< Checksum. */
77
* This structure describes the filter to be used when reading packets from
78
* a PCAP file. When a filter is configured, only packets matching all the
79
* filter specifications will be read from PCAP file.
81
typedef struct pj_pcap_filter
84
* Select data link type, or zero to include any supported data links.
86
pj_pcap_link_type link;
89
* Select protocol, or zero to include all supported protocols.
91
pj_pcap_proto_type proto;
94
* Specify source IP address of the packets, or zero to include packets
95
* from any IP addresses. Note that IP address here must be in
101
* Specify destination IP address of the packets, or zero to include packets
102
* destined to any IP addresses. Note that IP address here must be in
103
* network byte order.
108
* Specify source port of the packets, or zero to include packets with
109
* any source port number. Note that the port number must be in network
112
pj_uint16_t src_port;
115
* Specify destination port of the packets, or zero to include packets with
116
* any destination port number. Note that the port number must be in network
119
pj_uint16_t dst_port;
124
/** Opaque declaration for PCAP file */
125
typedef struct pj_pcap_file pj_pcap_file;
129
* Initialize filter with default values. The default value is to allow
132
* @param filter Filter to be initialized.
134
PJ_DECL(void) pj_pcap_filter_default(pj_pcap_filter *filter);
139
* @param pool Pool to allocate memory.
140
* @param path File/path name.
141
* @param p_file Pointer to receive PCAP file handle.
143
* @return PJ_SUCCESS if file can be opened successfully.
145
PJ_DECL(pj_status_t) pj_pcap_open(pj_pool_t *pool,
147
pj_pcap_file **p_file);
152
* @param file PCAP file handle.
154
* @return PJ_SUCCESS on success, or the appropriate error code.
156
PJ_DECL(pj_status_t) pj_pcap_close(pj_pcap_file *file);
159
* Configure filter for reading the file. When filter is configured,
160
* only packets matching all the filter settings will be returned.
162
* @param file PCAP file handle.
163
* @param filter The filter.
165
* @return PJ_SUCCESS on success, or the appropriate error code.
167
PJ_DECL(pj_status_t) pj_pcap_set_filter(pj_pcap_file *file,
168
const pj_pcap_filter *filter);
171
* Read UDP payload from the next packet in the PCAP file. Optionally it
172
* can return the UDP header, if caller supplies it.
174
* @param file PCAP file handle.
175
* @param udp_hdr Optional buffer to receive UDP header.
176
* @param udp_payload Buffer to receive the UDP payload.
177
* @param udp_payload_size On input, specify the size of the buffer.
178
* On output, it will be filled with the actual size
179
* of the payload as read from the packet.
181
* @return PJ_SUCCESS on success, or the appropriate error code.
183
PJ_DECL(pj_status_t) pj_pcap_read_udp(pj_pcap_file *file,
184
pj_pcap_udp_hdr *udp_hdr,
185
pj_uint8_t *udp_payload,
186
pj_size_t *udp_payload_size);
195
#endif /* __PJLIB_UTIL_PCAP_H__ */