xref: /aosp_15_r20/external/libpcap/pcap-int.h (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard Worker /*
2*8b26181fSAndroid Build Coastguard Worker  * Copyright (c) 1994, 1995, 1996
3*8b26181fSAndroid Build Coastguard Worker  *	The Regents of the University of California.  All rights reserved.
4*8b26181fSAndroid Build Coastguard Worker  *
5*8b26181fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
6*8b26181fSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
7*8b26181fSAndroid Build Coastguard Worker  * are met:
8*8b26181fSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
9*8b26181fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
10*8b26181fSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
11*8b26181fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
12*8b26181fSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
13*8b26181fSAndroid Build Coastguard Worker  * 3. All advertising materials mentioning features or use of this software
14*8b26181fSAndroid Build Coastguard Worker  *    must display the following acknowledgement:
15*8b26181fSAndroid Build Coastguard Worker  *	This product includes software developed by the Computer Systems
16*8b26181fSAndroid Build Coastguard Worker  *	Engineering Group at Lawrence Berkeley Laboratory.
17*8b26181fSAndroid Build Coastguard Worker  * 4. Neither the name of the University nor of the Laboratory may be used
18*8b26181fSAndroid Build Coastguard Worker  *    to endorse or promote products derived from this software without
19*8b26181fSAndroid Build Coastguard Worker  *    specific prior written permission.
20*8b26181fSAndroid Build Coastguard Worker  *
21*8b26181fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*8b26181fSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*8b26181fSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*8b26181fSAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*8b26181fSAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*8b26181fSAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*8b26181fSAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*8b26181fSAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*8b26181fSAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*8b26181fSAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*8b26181fSAndroid Build Coastguard Worker  * SUCH DAMAGE.
32*8b26181fSAndroid Build Coastguard Worker  */
33*8b26181fSAndroid Build Coastguard Worker 
34*8b26181fSAndroid Build Coastguard Worker #ifndef pcap_int_h
35*8b26181fSAndroid Build Coastguard Worker #define	pcap_int_h
36*8b26181fSAndroid Build Coastguard Worker 
37*8b26181fSAndroid Build Coastguard Worker #include <stddef.h>
38*8b26181fSAndroid Build Coastguard Worker 
39*8b26181fSAndroid Build Coastguard Worker #include <signal.h>
40*8b26181fSAndroid Build Coastguard Worker 
41*8b26181fSAndroid Build Coastguard Worker #include <pcap/pcap.h>
42*8b26181fSAndroid Build Coastguard Worker 
43*8b26181fSAndroid Build Coastguard Worker #ifdef MSDOS
44*8b26181fSAndroid Build Coastguard Worker   #include <fcntl.h>
45*8b26181fSAndroid Build Coastguard Worker   #include <io.h>
46*8b26181fSAndroid Build Coastguard Worker #endif
47*8b26181fSAndroid Build Coastguard Worker 
48*8b26181fSAndroid Build Coastguard Worker #include "varattrs.h"
49*8b26181fSAndroid Build Coastguard Worker #include "fmtutils.h"
50*8b26181fSAndroid Build Coastguard Worker 
51*8b26181fSAndroid Build Coastguard Worker #include <stdarg.h>
52*8b26181fSAndroid Build Coastguard Worker 
53*8b26181fSAndroid Build Coastguard Worker #include "portability.h"
54*8b26181fSAndroid Build Coastguard Worker 
55*8b26181fSAndroid Build Coastguard Worker /*
56*8b26181fSAndroid Build Coastguard Worker  * If we're compiling with Visual Studio, make sure we have at least
57*8b26181fSAndroid Build Coastguard Worker  * VS 2015 or later, so we have sufficient C99 support.
58*8b26181fSAndroid Build Coastguard Worker  *
59*8b26181fSAndroid Build Coastguard Worker  * XXX - verify that we have at least C99 support on UN*Xes?
60*8b26181fSAndroid Build Coastguard Worker  *
61*8b26181fSAndroid Build Coastguard Worker  * What about MinGW or various DOS toolchains?  We're currently assuming
62*8b26181fSAndroid Build Coastguard Worker  * sufficient C99 support there.
63*8b26181fSAndroid Build Coastguard Worker  */
64*8b26181fSAndroid Build Coastguard Worker #if defined(_MSC_VER)
65*8b26181fSAndroid Build Coastguard Worker   /*
66*8b26181fSAndroid Build Coastguard Worker    * Compiler is MSVC.  Make sure we have VS 2015 or later.
67*8b26181fSAndroid Build Coastguard Worker    */
68*8b26181fSAndroid Build Coastguard Worker   #if _MSC_VER < 1900
69*8b26181fSAndroid Build Coastguard Worker     #error "Building libpcap requires VS 2015 or later"
70*8b26181fSAndroid Build Coastguard Worker   #endif
71*8b26181fSAndroid Build Coastguard Worker #endif
72*8b26181fSAndroid Build Coastguard Worker 
73*8b26181fSAndroid Build Coastguard Worker /*
74*8b26181fSAndroid Build Coastguard Worker  * Version string.
75*8b26181fSAndroid Build Coastguard Worker  * Uses PACKAGE_VERSION from config.h.
76*8b26181fSAndroid Build Coastguard Worker  */
77*8b26181fSAndroid Build Coastguard Worker #define PCAP_VERSION_STRING "libpcap version " PACKAGE_VERSION
78*8b26181fSAndroid Build Coastguard Worker 
79*8b26181fSAndroid Build Coastguard Worker #ifdef __cplusplus
80*8b26181fSAndroid Build Coastguard Worker extern "C" {
81*8b26181fSAndroid Build Coastguard Worker #endif
82*8b26181fSAndroid Build Coastguard Worker 
83*8b26181fSAndroid Build Coastguard Worker /*
84*8b26181fSAndroid Build Coastguard Worker  * If pcap_new_api is set, we disable pcap_lookupdev(), because:
85*8b26181fSAndroid Build Coastguard Worker  *
86*8b26181fSAndroid Build Coastguard Worker  *    it's not thread-safe, and is marked as deprecated, on all
87*8b26181fSAndroid Build Coastguard Worker  *    platforms;
88*8b26181fSAndroid Build Coastguard Worker  *
89*8b26181fSAndroid Build Coastguard Worker  *    on Windows, it may return UTF-16LE strings, which the program
90*8b26181fSAndroid Build Coastguard Worker  *    might then pass to pcap_create() (or to pcap_open_live(), which
91*8b26181fSAndroid Build Coastguard Worker  *    then passes them to pcap_create()), requiring pcap_create() to
92*8b26181fSAndroid Build Coastguard Worker  *    check for UTF-16LE strings using a hack, and that hack 1)
93*8b26181fSAndroid Build Coastguard Worker  *    *cannot* be 100% reliable and 2) runs the risk of going past the
94*8b26181fSAndroid Build Coastguard Worker  *    end of the string.
95*8b26181fSAndroid Build Coastguard Worker  *
96*8b26181fSAndroid Build Coastguard Worker  * We keep it around in legacy mode for compatibility.
97*8b26181fSAndroid Build Coastguard Worker  *
98*8b26181fSAndroid Build Coastguard Worker  * We also disable the aforementioned hack in pcap_create().
99*8b26181fSAndroid Build Coastguard Worker  */
100*8b26181fSAndroid Build Coastguard Worker extern int pcap_new_api;
101*8b26181fSAndroid Build Coastguard Worker 
102*8b26181fSAndroid Build Coastguard Worker /*
103*8b26181fSAndroid Build Coastguard Worker  * If pcap_utf_8_mode is set, on Windows we treat strings as UTF-8.
104*8b26181fSAndroid Build Coastguard Worker  *
105*8b26181fSAndroid Build Coastguard Worker  * On UN*Xes, we assume all strings are and should be in UTF-8, regardless
106*8b26181fSAndroid Build Coastguard Worker  * of the setting of this flag.
107*8b26181fSAndroid Build Coastguard Worker  */
108*8b26181fSAndroid Build Coastguard Worker extern int pcap_utf_8_mode;
109*8b26181fSAndroid Build Coastguard Worker 
110*8b26181fSAndroid Build Coastguard Worker /*
111*8b26181fSAndroid Build Coastguard Worker  * Swap byte ordering of unsigned long long timestamp on a big endian
112*8b26181fSAndroid Build Coastguard Worker  * machine.
113*8b26181fSAndroid Build Coastguard Worker  */
114*8b26181fSAndroid Build Coastguard Worker #define SWAPLL(ull)  ((ull & 0xff00000000000000ULL) >> 56) | \
115*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x00ff000000000000ULL) >> 40) | \
116*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x0000ff0000000000ULL) >> 24) | \
117*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x000000ff00000000ULL) >> 8)  | \
118*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x00000000ff000000ULL) << 8)  | \
119*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x0000000000ff0000ULL) << 24) | \
120*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x000000000000ff00ULL) << 40) | \
121*8b26181fSAndroid Build Coastguard Worker                       ((ull & 0x00000000000000ffULL) << 56)
122*8b26181fSAndroid Build Coastguard Worker 
123*8b26181fSAndroid Build Coastguard Worker /*
124*8b26181fSAndroid Build Coastguard Worker  * Maximum snapshot length.
125*8b26181fSAndroid Build Coastguard Worker  *
126*8b26181fSAndroid Build Coastguard Worker  * Somewhat arbitrary, but chosen to be:
127*8b26181fSAndroid Build Coastguard Worker  *
128*8b26181fSAndroid Build Coastguard Worker  *    1) big enough for maximum-size Linux loopback packets (65549)
129*8b26181fSAndroid Build Coastguard Worker  *       and some USB packets captured with USBPcap:
130*8b26181fSAndroid Build Coastguard Worker  *
131*8b26181fSAndroid Build Coastguard Worker  *           https://desowin.org/usbpcap/
132*8b26181fSAndroid Build Coastguard Worker  *
133*8b26181fSAndroid Build Coastguard Worker  *       (> 131072, < 262144)
134*8b26181fSAndroid Build Coastguard Worker  *
135*8b26181fSAndroid Build Coastguard Worker  * and
136*8b26181fSAndroid Build Coastguard Worker  *
137*8b26181fSAndroid Build Coastguard Worker  *    2) small enough not to cause attempts to allocate huge amounts of
138*8b26181fSAndroid Build Coastguard Worker  *       memory; some applications might use the snapshot length in a
139*8b26181fSAndroid Build Coastguard Worker  *       savefile header to control the size of the buffer they allocate,
140*8b26181fSAndroid Build Coastguard Worker  *       so a size of, say, 2^31-1 might not work well.  (libpcap uses it
141*8b26181fSAndroid Build Coastguard Worker  *       as a hint, but doesn't start out allocating a buffer bigger than
142*8b26181fSAndroid Build Coastguard Worker  *       2 KiB, and grows the buffer as necessary, but not beyond the
143*8b26181fSAndroid Build Coastguard Worker  *       per-linktype maximum snapshot length.  Other code might naively
144*8b26181fSAndroid Build Coastguard Worker  *       use it; we want to avoid writing a too-large snapshot length,
145*8b26181fSAndroid Build Coastguard Worker  *       in order not to cause that code problems.)
146*8b26181fSAndroid Build Coastguard Worker  *
147*8b26181fSAndroid Build Coastguard Worker  * We don't enforce this in pcap_set_snaplen(), but we use it internally.
148*8b26181fSAndroid Build Coastguard Worker  */
149*8b26181fSAndroid Build Coastguard Worker #define MAXIMUM_SNAPLEN		262144
150*8b26181fSAndroid Build Coastguard Worker 
151*8b26181fSAndroid Build Coastguard Worker /*
152*8b26181fSAndroid Build Coastguard Worker  * Locale-independent macros for testing character types.
153*8b26181fSAndroid Build Coastguard Worker  * These can be passed any integral value, without worrying about, for
154*8b26181fSAndroid Build Coastguard Worker  * example, sign-extending char values, unlike the C macros.
155*8b26181fSAndroid Build Coastguard Worker  */
156*8b26181fSAndroid Build Coastguard Worker #define PCAP_ISDIGIT(c) \
157*8b26181fSAndroid Build Coastguard Worker 	((c) >= '0' && (c) <= '9')
158*8b26181fSAndroid Build Coastguard Worker #define PCAP_ISXDIGIT(c) \
159*8b26181fSAndroid Build Coastguard Worker 	(((c) >= '0' && (c) <= '9') || \
160*8b26181fSAndroid Build Coastguard Worker 	 ((c) >= 'A' && (c) <= 'F') || \
161*8b26181fSAndroid Build Coastguard Worker 	 ((c) >= 'a' && (c) <= 'f'))
162*8b26181fSAndroid Build Coastguard Worker 
163*8b26181fSAndroid Build Coastguard Worker struct pcap_opt {
164*8b26181fSAndroid Build Coastguard Worker 	char	*device;
165*8b26181fSAndroid Build Coastguard Worker 	int	timeout;	/* timeout for buffering */
166*8b26181fSAndroid Build Coastguard Worker 	u_int	buffer_size;
167*8b26181fSAndroid Build Coastguard Worker 	int	promisc;
168*8b26181fSAndroid Build Coastguard Worker 	int	rfmon;		/* monitor mode */
169*8b26181fSAndroid Build Coastguard Worker 	int	immediate;	/* immediate mode - deliver packets as soon as they arrive */
170*8b26181fSAndroid Build Coastguard Worker 	int	nonblock;	/* non-blocking mode - don't wait for packets to be delivered, return "no packets available" */
171*8b26181fSAndroid Build Coastguard Worker 	int	tstamp_type;
172*8b26181fSAndroid Build Coastguard Worker 	int	tstamp_precision;
173*8b26181fSAndroid Build Coastguard Worker 
174*8b26181fSAndroid Build Coastguard Worker 	/*
175*8b26181fSAndroid Build Coastguard Worker 	 * Platform-dependent options.
176*8b26181fSAndroid Build Coastguard Worker 	 */
177*8b26181fSAndroid Build Coastguard Worker #ifdef __linux__
178*8b26181fSAndroid Build Coastguard Worker 	int	protocol;	/* protocol to use when creating PF_PACKET socket */
179*8b26181fSAndroid Build Coastguard Worker #endif
180*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
181*8b26181fSAndroid Build Coastguard Worker 	int	nocapture_local;/* disable NPF loopback */
182*8b26181fSAndroid Build Coastguard Worker #endif
183*8b26181fSAndroid Build Coastguard Worker };
184*8b26181fSAndroid Build Coastguard Worker 
185*8b26181fSAndroid Build Coastguard Worker typedef int	(*activate_op_t)(pcap_t *);
186*8b26181fSAndroid Build Coastguard Worker typedef int	(*can_set_rfmon_op_t)(pcap_t *);
187*8b26181fSAndroid Build Coastguard Worker typedef int	(*read_op_t)(pcap_t *, int cnt, pcap_handler, u_char *);
188*8b26181fSAndroid Build Coastguard Worker typedef int	(*next_packet_op_t)(pcap_t *, struct pcap_pkthdr *, u_char **);
189*8b26181fSAndroid Build Coastguard Worker typedef int	(*inject_op_t)(pcap_t *, const void *, int);
190*8b26181fSAndroid Build Coastguard Worker typedef void	(*save_current_filter_op_t)(pcap_t *, const char *);
191*8b26181fSAndroid Build Coastguard Worker typedef int	(*setfilter_op_t)(pcap_t *, struct bpf_program *);
192*8b26181fSAndroid Build Coastguard Worker typedef int	(*setdirection_op_t)(pcap_t *, pcap_direction_t);
193*8b26181fSAndroid Build Coastguard Worker typedef int	(*set_datalink_op_t)(pcap_t *, int);
194*8b26181fSAndroid Build Coastguard Worker typedef int	(*getnonblock_op_t)(pcap_t *);
195*8b26181fSAndroid Build Coastguard Worker typedef int	(*setnonblock_op_t)(pcap_t *, int);
196*8b26181fSAndroid Build Coastguard Worker typedef int	(*stats_op_t)(pcap_t *, struct pcap_stat *);
197*8b26181fSAndroid Build Coastguard Worker typedef void	(*breakloop_op_t)(pcap_t *);
198*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
199*8b26181fSAndroid Build Coastguard Worker typedef struct pcap_stat *(*stats_ex_op_t)(pcap_t *, int *);
200*8b26181fSAndroid Build Coastguard Worker typedef int	(*setbuff_op_t)(pcap_t *, int);
201*8b26181fSAndroid Build Coastguard Worker typedef int	(*setmode_op_t)(pcap_t *, int);
202*8b26181fSAndroid Build Coastguard Worker typedef int	(*setmintocopy_op_t)(pcap_t *, int);
203*8b26181fSAndroid Build Coastguard Worker typedef HANDLE	(*getevent_op_t)(pcap_t *);
204*8b26181fSAndroid Build Coastguard Worker typedef int	(*oid_get_request_op_t)(pcap_t *, bpf_u_int32, void *, size_t *);
205*8b26181fSAndroid Build Coastguard Worker typedef int	(*oid_set_request_op_t)(pcap_t *, bpf_u_int32, const void *, size_t *);
206*8b26181fSAndroid Build Coastguard Worker typedef u_int	(*sendqueue_transmit_op_t)(pcap_t *, pcap_send_queue *, int);
207*8b26181fSAndroid Build Coastguard Worker typedef int	(*setuserbuffer_op_t)(pcap_t *, int);
208*8b26181fSAndroid Build Coastguard Worker typedef int	(*live_dump_op_t)(pcap_t *, char *, int, int);
209*8b26181fSAndroid Build Coastguard Worker typedef int	(*live_dump_ended_op_t)(pcap_t *, int);
210*8b26181fSAndroid Build Coastguard Worker typedef PAirpcapHandle	(*get_airpcap_handle_op_t)(pcap_t *);
211*8b26181fSAndroid Build Coastguard Worker #endif
212*8b26181fSAndroid Build Coastguard Worker typedef void	(*cleanup_op_t)(pcap_t *);
213*8b26181fSAndroid Build Coastguard Worker 
214*8b26181fSAndroid Build Coastguard Worker /*
215*8b26181fSAndroid Build Coastguard Worker  * We put all the stuff used in the read code path at the beginning,
216*8b26181fSAndroid Build Coastguard Worker  * to try to keep it together in the same cache line or lines.
217*8b26181fSAndroid Build Coastguard Worker  */
218*8b26181fSAndroid Build Coastguard Worker struct pcap {
219*8b26181fSAndroid Build Coastguard Worker 	/*
220*8b26181fSAndroid Build Coastguard Worker 	 * Method to call to read packets on a live capture.
221*8b26181fSAndroid Build Coastguard Worker 	 */
222*8b26181fSAndroid Build Coastguard Worker 	read_op_t read_op;
223*8b26181fSAndroid Build Coastguard Worker 
224*8b26181fSAndroid Build Coastguard Worker 	/*
225*8b26181fSAndroid Build Coastguard Worker 	 * Method to call to read the next packet from a savefile.
226*8b26181fSAndroid Build Coastguard Worker 	 */
227*8b26181fSAndroid Build Coastguard Worker 	next_packet_op_t next_packet_op;
228*8b26181fSAndroid Build Coastguard Worker 
229*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
230*8b26181fSAndroid Build Coastguard Worker 	HANDLE handle;
231*8b26181fSAndroid Build Coastguard Worker #else
232*8b26181fSAndroid Build Coastguard Worker 	int fd;
233*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32 */
234*8b26181fSAndroid Build Coastguard Worker 
235*8b26181fSAndroid Build Coastguard Worker 	/*
236*8b26181fSAndroid Build Coastguard Worker 	 * Read buffer.
237*8b26181fSAndroid Build Coastguard Worker 	 */
238*8b26181fSAndroid Build Coastguard Worker 	u_int bufsize;
239*8b26181fSAndroid Build Coastguard Worker 	void *buffer;
240*8b26181fSAndroid Build Coastguard Worker 	u_char *bp;
241*8b26181fSAndroid Build Coastguard Worker 	int cc;
242*8b26181fSAndroid Build Coastguard Worker 
243*8b26181fSAndroid Build Coastguard Worker 	sig_atomic_t break_loop; /* flag set to force break from packet-reading loop */
244*8b26181fSAndroid Build Coastguard Worker 
245*8b26181fSAndroid Build Coastguard Worker 	void *priv;		/* private data for methods */
246*8b26181fSAndroid Build Coastguard Worker 
247*8b26181fSAndroid Build Coastguard Worker #ifdef ENABLE_REMOTE
248*8b26181fSAndroid Build Coastguard Worker 	struct pcap_samp rmt_samp;	/* parameters related to the sampling process. */
249*8b26181fSAndroid Build Coastguard Worker #endif
250*8b26181fSAndroid Build Coastguard Worker 
251*8b26181fSAndroid Build Coastguard Worker 	int swapped;
252*8b26181fSAndroid Build Coastguard Worker 	FILE *rfile;		/* null if live capture, non-null if savefile */
253*8b26181fSAndroid Build Coastguard Worker 	u_int fddipad;
254*8b26181fSAndroid Build Coastguard Worker 	struct pcap *next;	/* list of open pcaps that need stuff cleared on close */
255*8b26181fSAndroid Build Coastguard Worker 
256*8b26181fSAndroid Build Coastguard Worker 	/*
257*8b26181fSAndroid Build Coastguard Worker 	 * File version number; meaningful only for a savefile, but we
258*8b26181fSAndroid Build Coastguard Worker 	 * keep it here so that apps that (mistakenly) ask for the
259*8b26181fSAndroid Build Coastguard Worker 	 * version numbers will get the same zero values that they
260*8b26181fSAndroid Build Coastguard Worker 	 * always did.
261*8b26181fSAndroid Build Coastguard Worker 	 */
262*8b26181fSAndroid Build Coastguard Worker 	int version_major;
263*8b26181fSAndroid Build Coastguard Worker 	int version_minor;
264*8b26181fSAndroid Build Coastguard Worker 
265*8b26181fSAndroid Build Coastguard Worker 	int snapshot;
266*8b26181fSAndroid Build Coastguard Worker 	int linktype;		/* Network linktype */
267*8b26181fSAndroid Build Coastguard Worker 	int linktype_ext;	/* Extended information stored in the linktype field of a file */
268*8b26181fSAndroid Build Coastguard Worker 	int offset;		/* offset for proper alignment */
269*8b26181fSAndroid Build Coastguard Worker 	int activated;		/* true if the capture is really started */
270*8b26181fSAndroid Build Coastguard Worker 	int oldstyle;		/* if we're opening with pcap_open_live() */
271*8b26181fSAndroid Build Coastguard Worker 
272*8b26181fSAndroid Build Coastguard Worker 	struct pcap_opt opt;
273*8b26181fSAndroid Build Coastguard Worker 
274*8b26181fSAndroid Build Coastguard Worker 	/*
275*8b26181fSAndroid Build Coastguard Worker 	 * Place holder for pcap_next().
276*8b26181fSAndroid Build Coastguard Worker 	 */
277*8b26181fSAndroid Build Coastguard Worker 	u_char *pkt;
278*8b26181fSAndroid Build Coastguard Worker 
279*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
280*8b26181fSAndroid Build Coastguard Worker 	struct pcap_stat stat;	/* used for pcap_stats_ex() */
281*8b26181fSAndroid Build Coastguard Worker #endif
282*8b26181fSAndroid Build Coastguard Worker 
283*8b26181fSAndroid Build Coastguard Worker 	/* We're accepting only packets in this direction/these directions. */
284*8b26181fSAndroid Build Coastguard Worker 	pcap_direction_t direction;
285*8b26181fSAndroid Build Coastguard Worker 
286*8b26181fSAndroid Build Coastguard Worker 	/*
287*8b26181fSAndroid Build Coastguard Worker 	 * Flags to affect BPF code generation.
288*8b26181fSAndroid Build Coastguard Worker 	 */
289*8b26181fSAndroid Build Coastguard Worker 	int bpf_codegen_flags;
290*8b26181fSAndroid Build Coastguard Worker 
291*8b26181fSAndroid Build Coastguard Worker #if !defined(_WIN32) && !defined(MSDOS)
292*8b26181fSAndroid Build Coastguard Worker 	int selectable_fd;	/* FD on which select()/poll()/epoll_wait()/kevent()/etc. can be done */
293*8b26181fSAndroid Build Coastguard Worker 
294*8b26181fSAndroid Build Coastguard Worker 	/*
295*8b26181fSAndroid Build Coastguard Worker 	 * In case there either is no selectable FD, or there is but
296*8b26181fSAndroid Build Coastguard Worker 	 * it doesn't necessarily work (e.g., if it doesn't get notified
297*8b26181fSAndroid Build Coastguard Worker 	 * if the packet capture timeout expires before the buffer
298*8b26181fSAndroid Build Coastguard Worker 	 * fills up), this points to a timeout that should be used
299*8b26181fSAndroid Build Coastguard Worker 	 * in select()/poll()/epoll_wait()/kevent() call.  The pcap_t should
300*8b26181fSAndroid Build Coastguard Worker 	 * be put into non-blocking mode, and, if the timeout expires on
301*8b26181fSAndroid Build Coastguard Worker 	 * the call, an attempt should be made to read packets from all
302*8b26181fSAndroid Build Coastguard Worker 	 * pcap_t's with a required timeout, and the code must be
303*8b26181fSAndroid Build Coastguard Worker 	 * prepared not to see any packets from the attempt.
304*8b26181fSAndroid Build Coastguard Worker 	 */
305*8b26181fSAndroid Build Coastguard Worker 	const struct timeval *required_select_timeout;
306*8b26181fSAndroid Build Coastguard Worker #endif
307*8b26181fSAndroid Build Coastguard Worker 
308*8b26181fSAndroid Build Coastguard Worker 	/*
309*8b26181fSAndroid Build Coastguard Worker 	 * Placeholder for filter code if bpf not in kernel.
310*8b26181fSAndroid Build Coastguard Worker 	 */
311*8b26181fSAndroid Build Coastguard Worker 	struct bpf_program fcode;
312*8b26181fSAndroid Build Coastguard Worker 
313*8b26181fSAndroid Build Coastguard Worker 	char errbuf[PCAP_ERRBUF_SIZE + 1];
314*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
315*8b26181fSAndroid Build Coastguard Worker 	char acp_errbuf[PCAP_ERRBUF_SIZE + 1];	/* buffer for local code page error strings */
316*8b26181fSAndroid Build Coastguard Worker #endif
317*8b26181fSAndroid Build Coastguard Worker 	int dlt_count;
318*8b26181fSAndroid Build Coastguard Worker 	u_int *dlt_list;
319*8b26181fSAndroid Build Coastguard Worker 	int tstamp_type_count;
320*8b26181fSAndroid Build Coastguard Worker 	u_int *tstamp_type_list;
321*8b26181fSAndroid Build Coastguard Worker 	int tstamp_precision_count;
322*8b26181fSAndroid Build Coastguard Worker 	u_int *tstamp_precision_list;
323*8b26181fSAndroid Build Coastguard Worker 
324*8b26181fSAndroid Build Coastguard Worker 	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
325*8b26181fSAndroid Build Coastguard Worker 
326*8b26181fSAndroid Build Coastguard Worker 	/*
327*8b26181fSAndroid Build Coastguard Worker 	 * More methods.
328*8b26181fSAndroid Build Coastguard Worker 	 */
329*8b26181fSAndroid Build Coastguard Worker 	activate_op_t activate_op;
330*8b26181fSAndroid Build Coastguard Worker 	can_set_rfmon_op_t can_set_rfmon_op;
331*8b26181fSAndroid Build Coastguard Worker 	inject_op_t inject_op;
332*8b26181fSAndroid Build Coastguard Worker 	save_current_filter_op_t save_current_filter_op;
333*8b26181fSAndroid Build Coastguard Worker 	setfilter_op_t setfilter_op;
334*8b26181fSAndroid Build Coastguard Worker 	setdirection_op_t setdirection_op;
335*8b26181fSAndroid Build Coastguard Worker 	set_datalink_op_t set_datalink_op;
336*8b26181fSAndroid Build Coastguard Worker 	getnonblock_op_t getnonblock_op;
337*8b26181fSAndroid Build Coastguard Worker 	setnonblock_op_t setnonblock_op;
338*8b26181fSAndroid Build Coastguard Worker 	stats_op_t stats_op;
339*8b26181fSAndroid Build Coastguard Worker 	breakloop_op_t breakloop_op;
340*8b26181fSAndroid Build Coastguard Worker 
341*8b26181fSAndroid Build Coastguard Worker 	/*
342*8b26181fSAndroid Build Coastguard Worker 	 * Routine to use as callback for pcap_next()/pcap_next_ex().
343*8b26181fSAndroid Build Coastguard Worker 	 */
344*8b26181fSAndroid Build Coastguard Worker 	pcap_handler oneshot_callback;
345*8b26181fSAndroid Build Coastguard Worker 
346*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
347*8b26181fSAndroid Build Coastguard Worker 	/*
348*8b26181fSAndroid Build Coastguard Worker 	 * These are, at least currently, specific to the Win32 NPF
349*8b26181fSAndroid Build Coastguard Worker 	 * driver.
350*8b26181fSAndroid Build Coastguard Worker 	 */
351*8b26181fSAndroid Build Coastguard Worker 	stats_ex_op_t stats_ex_op;
352*8b26181fSAndroid Build Coastguard Worker 	setbuff_op_t setbuff_op;
353*8b26181fSAndroid Build Coastguard Worker 	setmode_op_t setmode_op;
354*8b26181fSAndroid Build Coastguard Worker 	setmintocopy_op_t setmintocopy_op;
355*8b26181fSAndroid Build Coastguard Worker 	getevent_op_t getevent_op;
356*8b26181fSAndroid Build Coastguard Worker 	oid_get_request_op_t oid_get_request_op;
357*8b26181fSAndroid Build Coastguard Worker 	oid_set_request_op_t oid_set_request_op;
358*8b26181fSAndroid Build Coastguard Worker 	sendqueue_transmit_op_t sendqueue_transmit_op;
359*8b26181fSAndroid Build Coastguard Worker 	setuserbuffer_op_t setuserbuffer_op;
360*8b26181fSAndroid Build Coastguard Worker 	live_dump_op_t live_dump_op;
361*8b26181fSAndroid Build Coastguard Worker 	live_dump_ended_op_t live_dump_ended_op;
362*8b26181fSAndroid Build Coastguard Worker 	get_airpcap_handle_op_t get_airpcap_handle_op;
363*8b26181fSAndroid Build Coastguard Worker #endif
364*8b26181fSAndroid Build Coastguard Worker 	cleanup_op_t cleanup_op;
365*8b26181fSAndroid Build Coastguard Worker };
366*8b26181fSAndroid Build Coastguard Worker 
367*8b26181fSAndroid Build Coastguard Worker /*
368*8b26181fSAndroid Build Coastguard Worker  * BPF code generation flags.
369*8b26181fSAndroid Build Coastguard Worker  */
370*8b26181fSAndroid Build Coastguard Worker #define BPF_SPECIAL_VLAN_HANDLING	0x00000001	/* special VLAN handling for Linux */
371*8b26181fSAndroid Build Coastguard Worker 
372*8b26181fSAndroid Build Coastguard Worker /*
373*8b26181fSAndroid Build Coastguard Worker  * This is a timeval as stored in a savefile.
374*8b26181fSAndroid Build Coastguard Worker  * It has to use the same types everywhere, independent of the actual
375*8b26181fSAndroid Build Coastguard Worker  * `struct timeval'; `struct timeval' has 32-bit tv_sec values on some
376*8b26181fSAndroid Build Coastguard Worker  * platforms and 64-bit tv_sec values on other platforms, and writing
377*8b26181fSAndroid Build Coastguard Worker  * out native `struct timeval' values would mean files could only be
378*8b26181fSAndroid Build Coastguard Worker  * read on systems with the same tv_sec size as the system on which
379*8b26181fSAndroid Build Coastguard Worker  * the file was written.
380*8b26181fSAndroid Build Coastguard Worker  */
381*8b26181fSAndroid Build Coastguard Worker 
382*8b26181fSAndroid Build Coastguard Worker struct pcap_timeval {
383*8b26181fSAndroid Build Coastguard Worker     bpf_int32 tv_sec;		/* seconds */
384*8b26181fSAndroid Build Coastguard Worker     bpf_int32 tv_usec;		/* microseconds */
385*8b26181fSAndroid Build Coastguard Worker };
386*8b26181fSAndroid Build Coastguard Worker 
387*8b26181fSAndroid Build Coastguard Worker /*
388*8b26181fSAndroid Build Coastguard Worker  * This is a `pcap_pkthdr' as actually stored in a savefile.
389*8b26181fSAndroid Build Coastguard Worker  *
390*8b26181fSAndroid Build Coastguard Worker  * Do not change the format of this structure, in any way (this includes
391*8b26181fSAndroid Build Coastguard Worker  * changes that only affect the length of fields in this structure),
392*8b26181fSAndroid Build Coastguard Worker  * and do not make the time stamp anything other than seconds and
393*8b26181fSAndroid Build Coastguard Worker  * microseconds (e.g., seconds and nanoseconds).  Instead:
394*8b26181fSAndroid Build Coastguard Worker  *
395*8b26181fSAndroid Build Coastguard Worker  *	introduce a new structure for the new format;
396*8b26181fSAndroid Build Coastguard Worker  *
397*8b26181fSAndroid Build Coastguard Worker  *	send mail to "[email protected]", requesting
398*8b26181fSAndroid Build Coastguard Worker  *	a new magic number for your new capture file format, and, when
399*8b26181fSAndroid Build Coastguard Worker  *	you get the new magic number, put it in "savefile.c";
400*8b26181fSAndroid Build Coastguard Worker  *
401*8b26181fSAndroid Build Coastguard Worker  *	use that magic number for save files with the changed record
402*8b26181fSAndroid Build Coastguard Worker  *	header;
403*8b26181fSAndroid Build Coastguard Worker  *
404*8b26181fSAndroid Build Coastguard Worker  *	make the code in "savefile.c" capable of reading files with
405*8b26181fSAndroid Build Coastguard Worker  *	the old record header as well as files with the new record header
406*8b26181fSAndroid Build Coastguard Worker  *	(using the magic number to determine the header format).
407*8b26181fSAndroid Build Coastguard Worker  *
408*8b26181fSAndroid Build Coastguard Worker  * Then supply the changes by forking the branch at
409*8b26181fSAndroid Build Coastguard Worker  *
410*8b26181fSAndroid Build Coastguard Worker  *	https://github.com/the-tcpdump-group/libpcap/tree/master
411*8b26181fSAndroid Build Coastguard Worker  *
412*8b26181fSAndroid Build Coastguard Worker  * and issuing a pull request, so that future versions of libpcap and
413*8b26181fSAndroid Build Coastguard Worker  * programs that use it (such as tcpdump) will be able to read your new
414*8b26181fSAndroid Build Coastguard Worker  * capture file format.
415*8b26181fSAndroid Build Coastguard Worker  */
416*8b26181fSAndroid Build Coastguard Worker 
417*8b26181fSAndroid Build Coastguard Worker struct pcap_sf_pkthdr {
418*8b26181fSAndroid Build Coastguard Worker     struct pcap_timeval ts;	/* time stamp */
419*8b26181fSAndroid Build Coastguard Worker     bpf_u_int32 caplen;		/* length of portion present */
420*8b26181fSAndroid Build Coastguard Worker     bpf_u_int32 len;		/* length of this packet (off wire) */
421*8b26181fSAndroid Build Coastguard Worker };
422*8b26181fSAndroid Build Coastguard Worker 
423*8b26181fSAndroid Build Coastguard Worker /*
424*8b26181fSAndroid Build Coastguard Worker  * How a `pcap_pkthdr' is actually stored in savefiles written
425*8b26181fSAndroid Build Coastguard Worker  * by some patched versions of libpcap (e.g. the ones in Red
426*8b26181fSAndroid Build Coastguard Worker  * Hat Linux 6.1 and 6.2).
427*8b26181fSAndroid Build Coastguard Worker  *
428*8b26181fSAndroid Build Coastguard Worker  * Do not change the format of this structure, in any way (this includes
429*8b26181fSAndroid Build Coastguard Worker  * changes that only affect the length of fields in this structure).
430*8b26181fSAndroid Build Coastguard Worker  * Instead, introduce a new structure, as per the above.
431*8b26181fSAndroid Build Coastguard Worker  */
432*8b26181fSAndroid Build Coastguard Worker 
433*8b26181fSAndroid Build Coastguard Worker struct pcap_sf_patched_pkthdr {
434*8b26181fSAndroid Build Coastguard Worker     struct pcap_timeval ts;	/* time stamp */
435*8b26181fSAndroid Build Coastguard Worker     bpf_u_int32 caplen;		/* length of portion present */
436*8b26181fSAndroid Build Coastguard Worker     bpf_u_int32 len;		/* length of this packet (off wire) */
437*8b26181fSAndroid Build Coastguard Worker     int		index;
438*8b26181fSAndroid Build Coastguard Worker     unsigned short protocol;
439*8b26181fSAndroid Build Coastguard Worker     unsigned char pkt_type;
440*8b26181fSAndroid Build Coastguard Worker };
441*8b26181fSAndroid Build Coastguard Worker 
442*8b26181fSAndroid Build Coastguard Worker /*
443*8b26181fSAndroid Build Coastguard Worker  * User data structure for the one-shot callback used for pcap_next()
444*8b26181fSAndroid Build Coastguard Worker  * and pcap_next_ex().
445*8b26181fSAndroid Build Coastguard Worker  */
446*8b26181fSAndroid Build Coastguard Worker struct oneshot_userdata {
447*8b26181fSAndroid Build Coastguard Worker 	struct pcap_pkthdr *hdr;
448*8b26181fSAndroid Build Coastguard Worker 	const u_char **pkt;
449*8b26181fSAndroid Build Coastguard Worker 	pcap_t *pd;
450*8b26181fSAndroid Build Coastguard Worker };
451*8b26181fSAndroid Build Coastguard Worker 
452*8b26181fSAndroid Build Coastguard Worker #ifndef min
453*8b26181fSAndroid Build Coastguard Worker #define min(a, b) ((a) > (b) ? (b) : (a))
454*8b26181fSAndroid Build Coastguard Worker #endif
455*8b26181fSAndroid Build Coastguard Worker 
456*8b26181fSAndroid Build Coastguard Worker int	pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
457*8b26181fSAndroid Build Coastguard Worker 
458*8b26181fSAndroid Build Coastguard Worker /*
459*8b26181fSAndroid Build Coastguard Worker  * Does the packet count argument to a module's read routine say
460*8b26181fSAndroid Build Coastguard Worker  * "supply packets until you run out of packets"?
461*8b26181fSAndroid Build Coastguard Worker  */
462*8b26181fSAndroid Build Coastguard Worker #define PACKET_COUNT_IS_UNLIMITED(count)	((count) <= 0)
463*8b26181fSAndroid Build Coastguard Worker 
464*8b26181fSAndroid Build Coastguard Worker /*
465*8b26181fSAndroid Build Coastguard Worker  * Routines that most pcap implementations can use for non-blocking mode.
466*8b26181fSAndroid Build Coastguard Worker  */
467*8b26181fSAndroid Build Coastguard Worker #if !defined(_WIN32) && !defined(MSDOS)
468*8b26181fSAndroid Build Coastguard Worker int	pcap_getnonblock_fd(pcap_t *);
469*8b26181fSAndroid Build Coastguard Worker int	pcap_setnonblock_fd(pcap_t *p, int);
470*8b26181fSAndroid Build Coastguard Worker #endif
471*8b26181fSAndroid Build Coastguard Worker 
472*8b26181fSAndroid Build Coastguard Worker /*
473*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for "pcap_create()".
474*8b26181fSAndroid Build Coastguard Worker  *
475*8b26181fSAndroid Build Coastguard Worker  * "pcap_create_interface()" is the routine to do a pcap_create on
476*8b26181fSAndroid Build Coastguard Worker  * a regular network interface.  There are multiple implementations
477*8b26181fSAndroid Build Coastguard Worker  * of this, one for each platform type (Linux, BPF, DLPI, etc.),
478*8b26181fSAndroid Build Coastguard Worker  * with the one used chosen by the configure script.
479*8b26181fSAndroid Build Coastguard Worker  *
480*8b26181fSAndroid Build Coastguard Worker  * "pcap_create_common()" allocates and fills in a pcap_t, for use
481*8b26181fSAndroid Build Coastguard Worker  * by pcap_create routines.
482*8b26181fSAndroid Build Coastguard Worker  */
483*8b26181fSAndroid Build Coastguard Worker pcap_t	*pcap_create_interface(const char *, char *);
484*8b26181fSAndroid Build Coastguard Worker 
485*8b26181fSAndroid Build Coastguard Worker /*
486*8b26181fSAndroid Build Coastguard Worker  * This wrapper takes an error buffer pointer and a type to use for the
487*8b26181fSAndroid Build Coastguard Worker  * private data, and calls pcap_create_common(), passing it the error
488*8b26181fSAndroid Build Coastguard Worker  * buffer pointer, the size for the private data type, in bytes, and the
489*8b26181fSAndroid Build Coastguard Worker  * offset of the private data from the beginning of the structure, in
490*8b26181fSAndroid Build Coastguard Worker  * bytes.
491*8b26181fSAndroid Build Coastguard Worker  */
492*8b26181fSAndroid Build Coastguard Worker #define PCAP_CREATE_COMMON(ebuf, type) \
493*8b26181fSAndroid Build Coastguard Worker 	pcap_create_common(ebuf, \
494*8b26181fSAndroid Build Coastguard Worker 	    sizeof (struct { pcap_t __common; type __private; }), \
495*8b26181fSAndroid Build Coastguard Worker 	    offsetof (struct { pcap_t __common; type __private; }, __private))
496*8b26181fSAndroid Build Coastguard Worker pcap_t	*pcap_create_common(char *, size_t, size_t);
497*8b26181fSAndroid Build Coastguard Worker int	pcap_do_addexit(pcap_t *);
498*8b26181fSAndroid Build Coastguard Worker void	pcap_add_to_pcaps_to_close(pcap_t *);
499*8b26181fSAndroid Build Coastguard Worker void	pcap_remove_from_pcaps_to_close(pcap_t *);
500*8b26181fSAndroid Build Coastguard Worker void	pcap_cleanup_live_common(pcap_t *);
501*8b26181fSAndroid Build Coastguard Worker int	pcap_check_activated(pcap_t *);
502*8b26181fSAndroid Build Coastguard Worker void	pcap_breakloop_common(pcap_t *);
503*8b26181fSAndroid Build Coastguard Worker 
504*8b26181fSAndroid Build Coastguard Worker /*
505*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for "pcap_findalldevs()".
506*8b26181fSAndroid Build Coastguard Worker  *
507*8b26181fSAndroid Build Coastguard Worker  * A pcap_if_list_t * is a reference to a list of devices.
508*8b26181fSAndroid Build Coastguard Worker  *
509*8b26181fSAndroid Build Coastguard Worker  * A get_if_flags_func is a platform-dependent function called to get
510*8b26181fSAndroid Build Coastguard Worker  * additional interface flags.
511*8b26181fSAndroid Build Coastguard Worker  *
512*8b26181fSAndroid Build Coastguard Worker  * "pcap_platform_finddevs()" is the platform-dependent routine to
513*8b26181fSAndroid Build Coastguard Worker  * find local network interfaces.
514*8b26181fSAndroid Build Coastguard Worker  *
515*8b26181fSAndroid Build Coastguard Worker  * "pcap_findalldevs_interfaces()" is a helper to find those interfaces
516*8b26181fSAndroid Build Coastguard Worker  * using the "standard" mechanisms (SIOCGIFCONF, "getifaddrs()", etc.).
517*8b26181fSAndroid Build Coastguard Worker  *
518*8b26181fSAndroid Build Coastguard Worker  * "add_dev()" adds an entry to a pcap_if_list_t.
519*8b26181fSAndroid Build Coastguard Worker  *
520*8b26181fSAndroid Build Coastguard Worker  * "find_dev()" tries to find a device, by name, in a pcap_if_list_t.
521*8b26181fSAndroid Build Coastguard Worker  *
522*8b26181fSAndroid Build Coastguard Worker  * "find_or_add_dev()" checks whether a device is already in a pcap_if_list_t
523*8b26181fSAndroid Build Coastguard Worker  * and, if not, adds an entry for it.
524*8b26181fSAndroid Build Coastguard Worker  */
525*8b26181fSAndroid Build Coastguard Worker struct pcap_if_list;
526*8b26181fSAndroid Build Coastguard Worker typedef struct pcap_if_list pcap_if_list_t;
527*8b26181fSAndroid Build Coastguard Worker typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *);
528*8b26181fSAndroid Build Coastguard Worker int	pcap_platform_finddevs(pcap_if_list_t *, char *);
529*8b26181fSAndroid Build Coastguard Worker #if !defined(_WIN32) && !defined(MSDOS)
530*8b26181fSAndroid Build Coastguard Worker int	pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
531*8b26181fSAndroid Build Coastguard Worker 	    int (*)(const char *), get_if_flags_func);
532*8b26181fSAndroid Build Coastguard Worker #endif
533*8b26181fSAndroid Build Coastguard Worker pcap_if_t *find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
534*8b26181fSAndroid Build Coastguard Worker 	    get_if_flags_func, const char *, char *);
535*8b26181fSAndroid Build Coastguard Worker pcap_if_t *find_dev(pcap_if_list_t *, const char *);
536*8b26181fSAndroid Build Coastguard Worker pcap_if_t *add_dev(pcap_if_list_t *, const char *, bpf_u_int32, const char *,
537*8b26181fSAndroid Build Coastguard Worker 	    char *);
538*8b26181fSAndroid Build Coastguard Worker int	add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
539*8b26181fSAndroid Build Coastguard Worker 	    struct sockaddr *, size_t, struct sockaddr *, size_t,
540*8b26181fSAndroid Build Coastguard Worker 	    struct sockaddr *dstaddr, size_t, char *errbuf);
541*8b26181fSAndroid Build Coastguard Worker #ifndef _WIN32
542*8b26181fSAndroid Build Coastguard Worker pcap_if_t *find_or_add_if(pcap_if_list_t *, const char *, bpf_u_int32,
543*8b26181fSAndroid Build Coastguard Worker 	    get_if_flags_func, char *);
544*8b26181fSAndroid Build Coastguard Worker int	add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
545*8b26181fSAndroid Build Coastguard Worker 	    get_if_flags_func,
546*8b26181fSAndroid Build Coastguard Worker 	    struct sockaddr *, size_t, struct sockaddr *, size_t,
547*8b26181fSAndroid Build Coastguard Worker 	    struct sockaddr *, size_t, struct sockaddr *, size_t, char *);
548*8b26181fSAndroid Build Coastguard Worker #endif
549*8b26181fSAndroid Build Coastguard Worker 
550*8b26181fSAndroid Build Coastguard Worker /*
551*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for "pcap_open_offline()" and other savefile
552*8b26181fSAndroid Build Coastguard Worker  * I/O routines.
553*8b26181fSAndroid Build Coastguard Worker  *
554*8b26181fSAndroid Build Coastguard Worker  * "pcap_open_offline_common()" allocates and fills in a pcap_t, for use
555*8b26181fSAndroid Build Coastguard Worker  * by pcap_open_offline routines.
556*8b26181fSAndroid Build Coastguard Worker  *
557*8b26181fSAndroid Build Coastguard Worker  * "pcap_adjust_snapshot()" adjusts the snapshot to be non-zero and
558*8b26181fSAndroid Build Coastguard Worker  * fit within an int.
559*8b26181fSAndroid Build Coastguard Worker  *
560*8b26181fSAndroid Build Coastguard Worker  * "sf_cleanup()" closes the file handle associated with a pcap_t, if
561*8b26181fSAndroid Build Coastguard Worker  * appropriate, and frees all data common to all modules for handling
562*8b26181fSAndroid Build Coastguard Worker  * savefile types.
563*8b26181fSAndroid Build Coastguard Worker  *
564*8b26181fSAndroid Build Coastguard Worker  * "charset_fopen()", in UTF-8 mode on Windows, does an fopen() that
565*8b26181fSAndroid Build Coastguard Worker  * treats the pathname as being in UTF-8, rather than the local
566*8b26181fSAndroid Build Coastguard Worker  * code page, on Windows.
567*8b26181fSAndroid Build Coastguard Worker  */
568*8b26181fSAndroid Build Coastguard Worker 
569*8b26181fSAndroid Build Coastguard Worker /*
570*8b26181fSAndroid Build Coastguard Worker  * This wrapper takes an error buffer pointer and a type to use for the
571*8b26181fSAndroid Build Coastguard Worker  * private data, and calls pcap_create_common(), passing it the error
572*8b26181fSAndroid Build Coastguard Worker  * buffer pointer, the size for the private data type, in bytes, and the
573*8b26181fSAndroid Build Coastguard Worker  * offset of the private data from the beginning of the structure, in
574*8b26181fSAndroid Build Coastguard Worker  * bytes.
575*8b26181fSAndroid Build Coastguard Worker  */
576*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPEN_OFFLINE_COMMON(ebuf, type) \
577*8b26181fSAndroid Build Coastguard Worker 	pcap_open_offline_common(ebuf, \
578*8b26181fSAndroid Build Coastguard Worker 	    sizeof (struct { pcap_t __common; type __private; }), \
579*8b26181fSAndroid Build Coastguard Worker 	    offsetof (struct { pcap_t __common; type __private; }, __private))
580*8b26181fSAndroid Build Coastguard Worker pcap_t	*pcap_open_offline_common(char *ebuf, size_t total_size,
581*8b26181fSAndroid Build Coastguard Worker     size_t private_data);
582*8b26181fSAndroid Build Coastguard Worker bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
583*8b26181fSAndroid Build Coastguard Worker void	sf_cleanup(pcap_t *p);
584*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
585*8b26181fSAndroid Build Coastguard Worker FILE	*charset_fopen(const char *path, const char *mode);
586*8b26181fSAndroid Build Coastguard Worker #else
587*8b26181fSAndroid Build Coastguard Worker /*
588*8b26181fSAndroid Build Coastguard Worker  * On other OSes, just use Boring Old fopen().
589*8b26181fSAndroid Build Coastguard Worker  */
590*8b26181fSAndroid Build Coastguard Worker #define charset_fopen(path, mode)	fopen((path), (mode))
591*8b26181fSAndroid Build Coastguard Worker #endif
592*8b26181fSAndroid Build Coastguard Worker 
593*8b26181fSAndroid Build Coastguard Worker /*
594*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for loading code at run time.
595*8b26181fSAndroid Build Coastguard Worker  */
596*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
597*8b26181fSAndroid Build Coastguard Worker #define pcap_code_handle_t	HMODULE
598*8b26181fSAndroid Build Coastguard Worker #define pcap_funcptr_t		FARPROC
599*8b26181fSAndroid Build Coastguard Worker 
600*8b26181fSAndroid Build Coastguard Worker pcap_code_handle_t	pcap_load_code(const char *);
601*8b26181fSAndroid Build Coastguard Worker pcap_funcptr_t		pcap_find_function(pcap_code_handle_t, const char *);
602*8b26181fSAndroid Build Coastguard Worker #endif
603*8b26181fSAndroid Build Coastguard Worker 
604*8b26181fSAndroid Build Coastguard Worker /*
605*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for doing user-mode filtering of packets and
606*8b26181fSAndroid Build Coastguard Worker  * validating filter programs.
607*8b26181fSAndroid Build Coastguard Worker  */
608*8b26181fSAndroid Build Coastguard Worker /*
609*8b26181fSAndroid Build Coastguard Worker  * Auxiliary data, for use when interpreting a filter intended for the
610*8b26181fSAndroid Build Coastguard Worker  * Linux kernel when the kernel rejects the filter (requiring us to
611*8b26181fSAndroid Build Coastguard Worker  * run it in userland).  It contains VLAN tag information.
612*8b26181fSAndroid Build Coastguard Worker  */
613*8b26181fSAndroid Build Coastguard Worker struct pcap_bpf_aux_data {
614*8b26181fSAndroid Build Coastguard Worker 	u_short vlan_tag_present;
615*8b26181fSAndroid Build Coastguard Worker 	u_short vlan_tag;
616*8b26181fSAndroid Build Coastguard Worker };
617*8b26181fSAndroid Build Coastguard Worker 
618*8b26181fSAndroid Build Coastguard Worker /*
619*8b26181fSAndroid Build Coastguard Worker  * Filtering routine that takes the auxiliary data as an additional
620*8b26181fSAndroid Build Coastguard Worker  * argument.
621*8b26181fSAndroid Build Coastguard Worker  */
622*8b26181fSAndroid Build Coastguard Worker u_int	pcap_filter_with_aux_data(const struct bpf_insn *,
623*8b26181fSAndroid Build Coastguard Worker     const u_char *, u_int, u_int, const struct pcap_bpf_aux_data *);
624*8b26181fSAndroid Build Coastguard Worker 
625*8b26181fSAndroid Build Coastguard Worker /*
626*8b26181fSAndroid Build Coastguard Worker  * Filtering routine that doesn't.
627*8b26181fSAndroid Build Coastguard Worker  */
628*8b26181fSAndroid Build Coastguard Worker u_int	pcap_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
629*8b26181fSAndroid Build Coastguard Worker 
630*8b26181fSAndroid Build Coastguard Worker /*
631*8b26181fSAndroid Build Coastguard Worker  * Routine to validate a BPF program.
632*8b26181fSAndroid Build Coastguard Worker  */
633*8b26181fSAndroid Build Coastguard Worker int	pcap_validate_filter(const struct bpf_insn *, int);
634*8b26181fSAndroid Build Coastguard Worker 
635*8b26181fSAndroid Build Coastguard Worker /*
636*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for both "pcap_create()" and routines that
637*8b26181fSAndroid Build Coastguard Worker  * open savefiles.
638*8b26181fSAndroid Build Coastguard Worker  *
639*8b26181fSAndroid Build Coastguard Worker  * "pcap_oneshot()" is the standard one-shot callback for "pcap_next()"
640*8b26181fSAndroid Build Coastguard Worker  * and "pcap_next_ex()".
641*8b26181fSAndroid Build Coastguard Worker  */
642*8b26181fSAndroid Build Coastguard Worker void	pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);
643*8b26181fSAndroid Build Coastguard Worker 
644*8b26181fSAndroid Build Coastguard Worker int	install_bpf_program(pcap_t *, struct bpf_program *);
645*8b26181fSAndroid Build Coastguard Worker 
646*8b26181fSAndroid Build Coastguard Worker int	pcap_strcasecmp(const char *, const char *);
647*8b26181fSAndroid Build Coastguard Worker 
648*8b26181fSAndroid Build Coastguard Worker /*
649*8b26181fSAndroid Build Coastguard Worker  * Internal interfaces for pcap_createsrcstr and pcap_parsesrcstr with
650*8b26181fSAndroid Build Coastguard Worker  * the additional bit of information regarding SSL support (rpcap:// vs.
651*8b26181fSAndroid Build Coastguard Worker  * rpcaps://).
652*8b26181fSAndroid Build Coastguard Worker  */
653*8b26181fSAndroid Build Coastguard Worker int	pcap_createsrcstr_ex(char *, int, const char *, const char *,
654*8b26181fSAndroid Build Coastguard Worker     const char *, unsigned char, char *);
655*8b26181fSAndroid Build Coastguard Worker int	pcap_parsesrcstr_ex(const char *, int *, char *, char *,
656*8b26181fSAndroid Build Coastguard Worker     char *, unsigned char *, char *);
657*8b26181fSAndroid Build Coastguard Worker 
658*8b26181fSAndroid Build Coastguard Worker #ifdef YYDEBUG
659*8b26181fSAndroid Build Coastguard Worker extern int pcap_debug;
660*8b26181fSAndroid Build Coastguard Worker #endif
661*8b26181fSAndroid Build Coastguard Worker 
662*8b26181fSAndroid Build Coastguard Worker #ifdef __cplusplus
663*8b26181fSAndroid Build Coastguard Worker }
664*8b26181fSAndroid Build Coastguard Worker #endif
665*8b26181fSAndroid Build Coastguard Worker 
666*8b26181fSAndroid Build Coastguard Worker #endif
667