xref: /aosp_15_r20/external/libpcap/pcap/pcap.h (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard Worker /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2*8b26181fSAndroid Build Coastguard Worker /*
3*8b26181fSAndroid Build Coastguard Worker  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4*8b26181fSAndroid Build Coastguard Worker  *	The Regents of the University of California.  All rights reserved.
5*8b26181fSAndroid Build Coastguard Worker  *
6*8b26181fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*8b26181fSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
8*8b26181fSAndroid Build Coastguard Worker  * are met:
9*8b26181fSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
10*8b26181fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
11*8b26181fSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
12*8b26181fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
13*8b26181fSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
14*8b26181fSAndroid Build Coastguard Worker  * 3. All advertising materials mentioning features or use of this software
15*8b26181fSAndroid Build Coastguard Worker  *    must display the following acknowledgement:
16*8b26181fSAndroid Build Coastguard Worker  *	This product includes software developed by the Computer Systems
17*8b26181fSAndroid Build Coastguard Worker  *	Engineering Group at Lawrence Berkeley Laboratory.
18*8b26181fSAndroid Build Coastguard Worker  * 4. Neither the name of the University nor of the Laboratory may be used
19*8b26181fSAndroid Build Coastguard Worker  *    to endorse or promote products derived from this software without
20*8b26181fSAndroid Build Coastguard Worker  *    specific prior written permission.
21*8b26181fSAndroid Build Coastguard Worker  *
22*8b26181fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*8b26181fSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*8b26181fSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*8b26181fSAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*8b26181fSAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*8b26181fSAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*8b26181fSAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*8b26181fSAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*8b26181fSAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*8b26181fSAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*8b26181fSAndroid Build Coastguard Worker  * SUCH DAMAGE.
33*8b26181fSAndroid Build Coastguard Worker  */
34*8b26181fSAndroid Build Coastguard Worker 
35*8b26181fSAndroid Build Coastguard Worker /*
36*8b26181fSAndroid Build Coastguard Worker  * Remote packet capture mechanisms and extensions from WinPcap:
37*8b26181fSAndroid Build Coastguard Worker  *
38*8b26181fSAndroid Build Coastguard Worker  * Copyright (c) 2002 - 2003
39*8b26181fSAndroid Build Coastguard Worker  * NetGroup, Politecnico di Torino (Italy)
40*8b26181fSAndroid Build Coastguard Worker  * All rights reserved.
41*8b26181fSAndroid Build Coastguard Worker  *
42*8b26181fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
43*8b26181fSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
44*8b26181fSAndroid Build Coastguard Worker  * are met:
45*8b26181fSAndroid Build Coastguard Worker  *
46*8b26181fSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
47*8b26181fSAndroid Build Coastguard Worker  * notice, this list of conditions and the following disclaimer.
48*8b26181fSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
49*8b26181fSAndroid Build Coastguard Worker  * notice, this list of conditions and the following disclaimer in the
50*8b26181fSAndroid Build Coastguard Worker  * documentation and/or other materials provided with the distribution.
51*8b26181fSAndroid Build Coastguard Worker  * 3. Neither the name of the Politecnico di Torino nor the names of its
52*8b26181fSAndroid Build Coastguard Worker  * contributors may be used to endorse or promote products derived from
53*8b26181fSAndroid Build Coastguard Worker  * this software without specific prior written permission.
54*8b26181fSAndroid Build Coastguard Worker  *
55*8b26181fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
56*8b26181fSAndroid Build Coastguard Worker  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
57*8b26181fSAndroid Build Coastguard Worker  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
58*8b26181fSAndroid Build Coastguard Worker  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
59*8b26181fSAndroid Build Coastguard Worker  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60*8b26181fSAndroid Build Coastguard Worker  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
61*8b26181fSAndroid Build Coastguard Worker  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62*8b26181fSAndroid Build Coastguard Worker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63*8b26181fSAndroid Build Coastguard Worker  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64*8b26181fSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65*8b26181fSAndroid Build Coastguard Worker  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66*8b26181fSAndroid Build Coastguard Worker  *
67*8b26181fSAndroid Build Coastguard Worker  */
68*8b26181fSAndroid Build Coastguard Worker 
69*8b26181fSAndroid Build Coastguard Worker #ifndef lib_pcap_pcap_h
70*8b26181fSAndroid Build Coastguard Worker #define lib_pcap_pcap_h
71*8b26181fSAndroid Build Coastguard Worker 
72*8b26181fSAndroid Build Coastguard Worker /*
73*8b26181fSAndroid Build Coastguard Worker  * Some software that uses libpcap/WinPcap/Npcap defines _MSC_VER before
74*8b26181fSAndroid Build Coastguard Worker  * including pcap.h if it's not defined - and it defines it to 1500.
75*8b26181fSAndroid Build Coastguard Worker  * (I'm looking at *you*, lwIP!)
76*8b26181fSAndroid Build Coastguard Worker  *
77*8b26181fSAndroid Build Coastguard Worker  * Attempt to detect this, and undefine _MSC_VER so that we can *reliably*
78*8b26181fSAndroid Build Coastguard Worker  * use it to know what compiler is being used and, if it's Visual Studio,
79*8b26181fSAndroid Build Coastguard Worker  * what version is being used.
80*8b26181fSAndroid Build Coastguard Worker  */
81*8b26181fSAndroid Build Coastguard Worker #if defined(_MSC_VER)
82*8b26181fSAndroid Build Coastguard Worker   /*
83*8b26181fSAndroid Build Coastguard Worker    * We assume here that software such as that doesn't define _MSC_FULL_VER
84*8b26181fSAndroid Build Coastguard Worker    * as well and that it defines _MSC_VER with a value > 1200.
85*8b26181fSAndroid Build Coastguard Worker    *
86*8b26181fSAndroid Build Coastguard Worker    * DO NOT BREAK THESE ASSUMPTIONS.  IF YOU FEEL YOU MUST DEFINE _MSC_VER
87*8b26181fSAndroid Build Coastguard Worker    * WITH A COMPILER THAT'S NOT MICROSOFT'S C COMPILER, PLEASE CONTACT
88*8b26181fSAndroid Build Coastguard Worker    * US SO THAT WE CAN MAKE IT SO THAT YOU DON'T HAVE TO DO THAT.  THANK
89*8b26181fSAndroid Build Coastguard Worker    * YOU.
90*8b26181fSAndroid Build Coastguard Worker    *
91*8b26181fSAndroid Build Coastguard Worker    * OK, is _MSC_FULL_VER defined?
92*8b26181fSAndroid Build Coastguard Worker    */
93*8b26181fSAndroid Build Coastguard Worker   #if !defined(_MSC_FULL_VER)
94*8b26181fSAndroid Build Coastguard Worker     /*
95*8b26181fSAndroid Build Coastguard Worker      * According to
96*8b26181fSAndroid Build Coastguard Worker      *
97*8b26181fSAndroid Build Coastguard Worker      *    https://sourceforge.net/p/predef/wiki/Compilers/
98*8b26181fSAndroid Build Coastguard Worker      *
99*8b26181fSAndroid Build Coastguard Worker      * with "Visual C++ 6.0 Processor Pack"/Visual C++ 6.0 SP6 and
100*8b26181fSAndroid Build Coastguard Worker      * later, _MSC_FULL_VER is defined, so either this is an older
101*8b26181fSAndroid Build Coastguard Worker      * version of Visual C++ or it's not Visual C++ at all.
102*8b26181fSAndroid Build Coastguard Worker      *
103*8b26181fSAndroid Build Coastguard Worker      * For Visual C++ 6.0, _MSC_VER is defined as 1200.
104*8b26181fSAndroid Build Coastguard Worker      */
105*8b26181fSAndroid Build Coastguard Worker     #if _MSC_VER > 1200
106*8b26181fSAndroid Build Coastguard Worker       /*
107*8b26181fSAndroid Build Coastguard Worker        * If this is Visual C++, _MSC_FULL_VER should be defined, so we
108*8b26181fSAndroid Build Coastguard Worker        * assume this isn't Visual C++, and undo the lie that it is.
109*8b26181fSAndroid Build Coastguard Worker        */
110*8b26181fSAndroid Build Coastguard Worker       #undef _MSC_VER
111*8b26181fSAndroid Build Coastguard Worker     #endif
112*8b26181fSAndroid Build Coastguard Worker   #endif
113*8b26181fSAndroid Build Coastguard Worker #endif
114*8b26181fSAndroid Build Coastguard Worker 
115*8b26181fSAndroid Build Coastguard Worker #include <pcap/funcattrs.h>
116*8b26181fSAndroid Build Coastguard Worker 
117*8b26181fSAndroid Build Coastguard Worker #include <pcap/pcap-inttypes.h>
118*8b26181fSAndroid Build Coastguard Worker 
119*8b26181fSAndroid Build Coastguard Worker #if defined(_WIN32)
120*8b26181fSAndroid Build Coastguard Worker   #include <winsock2.h>		/* u_int, u_char etc. */
121*8b26181fSAndroid Build Coastguard Worker   #include <io.h>		/* _get_osfhandle() */
122*8b26181fSAndroid Build Coastguard Worker #elif defined(MSDOS)
123*8b26181fSAndroid Build Coastguard Worker   #include <sys/types.h>	/* u_int, u_char etc. */
124*8b26181fSAndroid Build Coastguard Worker   #include <sys/socket.h>
125*8b26181fSAndroid Build Coastguard Worker #else /* UN*X */
126*8b26181fSAndroid Build Coastguard Worker   #include <sys/types.h>	/* u_int, u_char etc. */
127*8b26181fSAndroid Build Coastguard Worker   #include <sys/time.h>
128*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32/MSDOS/UN*X */
129*8b26181fSAndroid Build Coastguard Worker 
130*8b26181fSAndroid Build Coastguard Worker #include <pcap/socket.h>	/* for SOCKET, as the active-mode rpcap APIs use it */
131*8b26181fSAndroid Build Coastguard Worker 
132*8b26181fSAndroid Build Coastguard Worker #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
133*8b26181fSAndroid Build Coastguard Worker #include <pcap/bpf.h>
134*8b26181fSAndroid Build Coastguard Worker #endif
135*8b26181fSAndroid Build Coastguard Worker 
136*8b26181fSAndroid Build Coastguard Worker #include <stdio.h>
137*8b26181fSAndroid Build Coastguard Worker 
138*8b26181fSAndroid Build Coastguard Worker #ifdef __cplusplus
139*8b26181fSAndroid Build Coastguard Worker extern "C" {
140*8b26181fSAndroid Build Coastguard Worker #endif
141*8b26181fSAndroid Build Coastguard Worker 
142*8b26181fSAndroid Build Coastguard Worker /*
143*8b26181fSAndroid Build Coastguard Worker  * Version number of the current version of the pcap file format.
144*8b26181fSAndroid Build Coastguard Worker  *
145*8b26181fSAndroid Build Coastguard Worker  * NOTE: this is *NOT* the version number of the libpcap library.
146*8b26181fSAndroid Build Coastguard Worker  * To fetch the version information for the version of libpcap
147*8b26181fSAndroid Build Coastguard Worker  * you're using, use pcap_lib_version().
148*8b26181fSAndroid Build Coastguard Worker  */
149*8b26181fSAndroid Build Coastguard Worker #define PCAP_VERSION_MAJOR 2
150*8b26181fSAndroid Build Coastguard Worker #define PCAP_VERSION_MINOR 4
151*8b26181fSAndroid Build Coastguard Worker 
152*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERRBUF_SIZE 256
153*8b26181fSAndroid Build Coastguard Worker 
154*8b26181fSAndroid Build Coastguard Worker /*
155*8b26181fSAndroid Build Coastguard Worker  * Compatibility for systems that have a bpf.h that
156*8b26181fSAndroid Build Coastguard Worker  * predates the bpf typedefs for 64-bit support.
157*8b26181fSAndroid Build Coastguard Worker  */
158*8b26181fSAndroid Build Coastguard Worker #if BPF_RELEASE - 0 < 199406
159*8b26181fSAndroid Build Coastguard Worker typedef	int bpf_int32;
160*8b26181fSAndroid Build Coastguard Worker typedef	u_int bpf_u_int32;
161*8b26181fSAndroid Build Coastguard Worker #endif
162*8b26181fSAndroid Build Coastguard Worker 
163*8b26181fSAndroid Build Coastguard Worker typedef struct pcap pcap_t;
164*8b26181fSAndroid Build Coastguard Worker typedef struct pcap_dumper pcap_dumper_t;
165*8b26181fSAndroid Build Coastguard Worker typedef struct pcap_if pcap_if_t;
166*8b26181fSAndroid Build Coastguard Worker typedef struct pcap_addr pcap_addr_t;
167*8b26181fSAndroid Build Coastguard Worker 
168*8b26181fSAndroid Build Coastguard Worker /*
169*8b26181fSAndroid Build Coastguard Worker  * The first record in the file contains saved values for some
170*8b26181fSAndroid Build Coastguard Worker  * of the flags used in the printout phases of tcpdump.
171*8b26181fSAndroid Build Coastguard Worker  * Many fields here are 32 bit ints so compilers won't insert unwanted
172*8b26181fSAndroid Build Coastguard Worker  * padding; these files need to be interchangeable across architectures.
173*8b26181fSAndroid Build Coastguard Worker  * Documentation: https://www.tcpdump.org/manpages/pcap-savefile.5.txt.
174*8b26181fSAndroid Build Coastguard Worker  *
175*8b26181fSAndroid Build Coastguard Worker  * Do not change the layout of this structure, in any way (this includes
176*8b26181fSAndroid Build Coastguard Worker  * changes that only affect the length of fields in this structure).
177*8b26181fSAndroid Build Coastguard Worker  *
178*8b26181fSAndroid Build Coastguard Worker  * Also, do not change the interpretation of any of the members of this
179*8b26181fSAndroid Build Coastguard Worker  * structure, in any way (this includes using values other than
180*8b26181fSAndroid Build Coastguard Worker  * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
181*8b26181fSAndroid Build Coastguard Worker  * field).
182*8b26181fSAndroid Build Coastguard Worker  *
183*8b26181fSAndroid Build Coastguard Worker  * Instead:
184*8b26181fSAndroid Build Coastguard Worker  *
185*8b26181fSAndroid Build Coastguard Worker  *	introduce a new structure for the new format, if the layout
186*8b26181fSAndroid Build Coastguard Worker  *	of the structure changed;
187*8b26181fSAndroid Build Coastguard Worker  *
188*8b26181fSAndroid Build Coastguard Worker  *	send mail to "[email protected]", requesting
189*8b26181fSAndroid Build Coastguard Worker  *	a new magic number for your new capture file format, and, when
190*8b26181fSAndroid Build Coastguard Worker  *	you get the new magic number, put it in "savefile.c";
191*8b26181fSAndroid Build Coastguard Worker  *
192*8b26181fSAndroid Build Coastguard Worker  *	use that magic number for save files with the changed file
193*8b26181fSAndroid Build Coastguard Worker  *	header;
194*8b26181fSAndroid Build Coastguard Worker  *
195*8b26181fSAndroid Build Coastguard Worker  *	make the code in "savefile.c" capable of reading files with
196*8b26181fSAndroid Build Coastguard Worker  *	the old file header as well as files with the new file header
197*8b26181fSAndroid Build Coastguard Worker  *	(using the magic number to determine the header format).
198*8b26181fSAndroid Build Coastguard Worker  *
199*8b26181fSAndroid Build Coastguard Worker  * Then supply the changes by forking the branch at
200*8b26181fSAndroid Build Coastguard Worker  *
201*8b26181fSAndroid Build Coastguard Worker  *	https://github.com/the-tcpdump-group/libpcap/tree/master
202*8b26181fSAndroid Build Coastguard Worker  *
203*8b26181fSAndroid Build Coastguard Worker  * and issuing a pull request, so that future versions of libpcap and
204*8b26181fSAndroid Build Coastguard Worker  * programs that use it (such as tcpdump) will be able to read your new
205*8b26181fSAndroid Build Coastguard Worker  * capture file format.
206*8b26181fSAndroid Build Coastguard Worker  */
207*8b26181fSAndroid Build Coastguard Worker struct pcap_file_header {
208*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 magic;
209*8b26181fSAndroid Build Coastguard Worker 	u_short version_major;
210*8b26181fSAndroid Build Coastguard Worker 	u_short version_minor;
211*8b26181fSAndroid Build Coastguard Worker 	bpf_int32 thiszone;	/* gmt to local correction; this is always 0 */
212*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 sigfigs;	/* accuracy of timestamps; this is always 0 */
213*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 snaplen;	/* max length saved portion of each pkt */
214*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 linktype;	/* data link type (LINKTYPE_*) */
215*8b26181fSAndroid Build Coastguard Worker };
216*8b26181fSAndroid Build Coastguard Worker 
217*8b26181fSAndroid Build Coastguard Worker /*
218*8b26181fSAndroid Build Coastguard Worker  * Macros for the value returned by pcap_datalink_ext().
219*8b26181fSAndroid Build Coastguard Worker  *
220*8b26181fSAndroid Build Coastguard Worker  * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
221*8b26181fSAndroid Build Coastguard Worker  * gives the FCS length of packets in the capture.
222*8b26181fSAndroid Build Coastguard Worker  */
223*8b26181fSAndroid Build Coastguard Worker #define LT_FCS_LENGTH_PRESENT(x)	((x) & 0x04000000)
224*8b26181fSAndroid Build Coastguard Worker #define LT_FCS_LENGTH(x)		(((x) & 0xF0000000) >> 28)
225*8b26181fSAndroid Build Coastguard Worker #define LT_FCS_DATALINK_EXT(x)		((((x) & 0xF) << 28) | 0x04000000)
226*8b26181fSAndroid Build Coastguard Worker 
227*8b26181fSAndroid Build Coastguard Worker typedef enum {
228*8b26181fSAndroid Build Coastguard Worker        PCAP_D_INOUT = 0,
229*8b26181fSAndroid Build Coastguard Worker        PCAP_D_IN,
230*8b26181fSAndroid Build Coastguard Worker        PCAP_D_OUT
231*8b26181fSAndroid Build Coastguard Worker } pcap_direction_t;
232*8b26181fSAndroid Build Coastguard Worker 
233*8b26181fSAndroid Build Coastguard Worker /*
234*8b26181fSAndroid Build Coastguard Worker  * Generic per-packet information, as supplied by libpcap.
235*8b26181fSAndroid Build Coastguard Worker  *
236*8b26181fSAndroid Build Coastguard Worker  * The time stamp can and should be a "struct timeval", regardless of
237*8b26181fSAndroid Build Coastguard Worker  * whether your system supports 32-bit tv_sec in "struct timeval",
238*8b26181fSAndroid Build Coastguard Worker  * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
239*8b26181fSAndroid Build Coastguard Worker  * and 64-bit applications.  The on-disk format of savefiles uses 32-bit
240*8b26181fSAndroid Build Coastguard Worker  * tv_sec (and tv_usec); this structure is irrelevant to that.  32-bit
241*8b26181fSAndroid Build Coastguard Worker  * and 64-bit versions of libpcap, even if they're on the same platform,
242*8b26181fSAndroid Build Coastguard Worker  * should supply the appropriate version of "struct timeval", even if
243*8b26181fSAndroid Build Coastguard Worker  * that's not what the underlying packet capture mechanism supplies.
244*8b26181fSAndroid Build Coastguard Worker  */
245*8b26181fSAndroid Build Coastguard Worker struct pcap_pkthdr {
246*8b26181fSAndroid Build Coastguard Worker 	struct timeval ts;	/* time stamp */
247*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 caplen;	/* length of portion present */
248*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 len;	/* length of this packet (off wire) */
249*8b26181fSAndroid Build Coastguard Worker };
250*8b26181fSAndroid Build Coastguard Worker 
251*8b26181fSAndroid Build Coastguard Worker /*
252*8b26181fSAndroid Build Coastguard Worker  * As returned by the pcap_stats()
253*8b26181fSAndroid Build Coastguard Worker  */
254*8b26181fSAndroid Build Coastguard Worker struct pcap_stat {
255*8b26181fSAndroid Build Coastguard Worker 	u_int ps_recv;		/* number of packets received */
256*8b26181fSAndroid Build Coastguard Worker 	u_int ps_drop;		/* number of packets dropped */
257*8b26181fSAndroid Build Coastguard Worker 	u_int ps_ifdrop;	/* drops by interface -- only supported on some platforms */
258*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
259*8b26181fSAndroid Build Coastguard Worker 	u_int ps_capt;		/* number of packets that reach the application */
260*8b26181fSAndroid Build Coastguard Worker 	u_int ps_sent;		/* number of packets sent by the server on the network */
261*8b26181fSAndroid Build Coastguard Worker 	u_int ps_netdrop;	/* number of packets lost on the network */
262*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32 */
263*8b26181fSAndroid Build Coastguard Worker };
264*8b26181fSAndroid Build Coastguard Worker 
265*8b26181fSAndroid Build Coastguard Worker #ifdef MSDOS
266*8b26181fSAndroid Build Coastguard Worker /*
267*8b26181fSAndroid Build Coastguard Worker  * As returned by the pcap_stats_ex()
268*8b26181fSAndroid Build Coastguard Worker  */
269*8b26181fSAndroid Build Coastguard Worker struct pcap_stat_ex {
270*8b26181fSAndroid Build Coastguard Worker        u_long  rx_packets;        /* total packets received       */
271*8b26181fSAndroid Build Coastguard Worker        u_long  tx_packets;        /* total packets transmitted    */
272*8b26181fSAndroid Build Coastguard Worker        u_long  rx_bytes;          /* total bytes received         */
273*8b26181fSAndroid Build Coastguard Worker        u_long  tx_bytes;          /* total bytes transmitted      */
274*8b26181fSAndroid Build Coastguard Worker        u_long  rx_errors;         /* bad packets received         */
275*8b26181fSAndroid Build Coastguard Worker        u_long  tx_errors;         /* packet transmit problems     */
276*8b26181fSAndroid Build Coastguard Worker        u_long  rx_dropped;        /* no space in Rx buffers       */
277*8b26181fSAndroid Build Coastguard Worker        u_long  tx_dropped;        /* no space available for Tx    */
278*8b26181fSAndroid Build Coastguard Worker        u_long  multicast;         /* multicast packets received   */
279*8b26181fSAndroid Build Coastguard Worker        u_long  collisions;
280*8b26181fSAndroid Build Coastguard Worker 
281*8b26181fSAndroid Build Coastguard Worker        /* detailed rx_errors: */
282*8b26181fSAndroid Build Coastguard Worker        u_long  rx_length_errors;
283*8b26181fSAndroid Build Coastguard Worker        u_long  rx_over_errors;    /* receiver ring buff overflow  */
284*8b26181fSAndroid Build Coastguard Worker        u_long  rx_crc_errors;     /* recv'd pkt with crc error    */
285*8b26181fSAndroid Build Coastguard Worker        u_long  rx_frame_errors;   /* recv'd frame alignment error */
286*8b26181fSAndroid Build Coastguard Worker        u_long  rx_fifo_errors;    /* recv'r fifo overrun          */
287*8b26181fSAndroid Build Coastguard Worker        u_long  rx_missed_errors;  /* recv'r missed packet         */
288*8b26181fSAndroid Build Coastguard Worker 
289*8b26181fSAndroid Build Coastguard Worker        /* detailed tx_errors */
290*8b26181fSAndroid Build Coastguard Worker        u_long  tx_aborted_errors;
291*8b26181fSAndroid Build Coastguard Worker        u_long  tx_carrier_errors;
292*8b26181fSAndroid Build Coastguard Worker        u_long  tx_fifo_errors;
293*8b26181fSAndroid Build Coastguard Worker        u_long  tx_heartbeat_errors;
294*8b26181fSAndroid Build Coastguard Worker        u_long  tx_window_errors;
295*8b26181fSAndroid Build Coastguard Worker      };
296*8b26181fSAndroid Build Coastguard Worker #endif
297*8b26181fSAndroid Build Coastguard Worker 
298*8b26181fSAndroid Build Coastguard Worker /*
299*8b26181fSAndroid Build Coastguard Worker  * Item in a list of interfaces.
300*8b26181fSAndroid Build Coastguard Worker  */
301*8b26181fSAndroid Build Coastguard Worker struct pcap_if {
302*8b26181fSAndroid Build Coastguard Worker 	struct pcap_if *next;
303*8b26181fSAndroid Build Coastguard Worker 	char *name;		/* name to hand to "pcap_open_live()" */
304*8b26181fSAndroid Build Coastguard Worker 	char *description;	/* textual description of interface, or NULL */
305*8b26181fSAndroid Build Coastguard Worker 	struct pcap_addr *addresses;
306*8b26181fSAndroid Build Coastguard Worker 	bpf_u_int32 flags;	/* PCAP_IF_ interface flags */
307*8b26181fSAndroid Build Coastguard Worker };
308*8b26181fSAndroid Build Coastguard Worker 
309*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_LOOPBACK				0x00000001	/* interface is loopback */
310*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_UP					0x00000002	/* interface is up */
311*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_RUNNING					0x00000004	/* interface is running */
312*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_WIRELESS				0x00000008	/* interface is wireless (*NOT* necessarily Wi-Fi!) */
313*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_CONNECTION_STATUS			0x00000030	/* connection status: */
314*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_CONNECTION_STATUS_UNKNOWN		0x00000000	/* unknown */
315*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_CONNECTION_STATUS_CONNECTED		0x00000010	/* connected */
316*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_CONNECTION_STATUS_DISCONNECTED		0x00000020	/* disconnected */
317*8b26181fSAndroid Build Coastguard Worker #define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE	0x00000030	/* not applicable */
318*8b26181fSAndroid Build Coastguard Worker 
319*8b26181fSAndroid Build Coastguard Worker /*
320*8b26181fSAndroid Build Coastguard Worker  * Representation of an interface address.
321*8b26181fSAndroid Build Coastguard Worker  */
322*8b26181fSAndroid Build Coastguard Worker struct pcap_addr {
323*8b26181fSAndroid Build Coastguard Worker 	struct pcap_addr *next;
324*8b26181fSAndroid Build Coastguard Worker 	struct sockaddr *addr;		/* address */
325*8b26181fSAndroid Build Coastguard Worker 	struct sockaddr *netmask;	/* netmask for that address */
326*8b26181fSAndroid Build Coastguard Worker 	struct sockaddr *broadaddr;	/* broadcast address for that address */
327*8b26181fSAndroid Build Coastguard Worker 	struct sockaddr *dstaddr;	/* P2P destination address for that address */
328*8b26181fSAndroid Build Coastguard Worker };
329*8b26181fSAndroid Build Coastguard Worker 
330*8b26181fSAndroid Build Coastguard Worker typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
331*8b26181fSAndroid Build Coastguard Worker 			     const u_char *);
332*8b26181fSAndroid Build Coastguard Worker 
333*8b26181fSAndroid Build Coastguard Worker /*
334*8b26181fSAndroid Build Coastguard Worker  * Error codes for the pcap API.
335*8b26181fSAndroid Build Coastguard Worker  * These will all be negative, so you can check for the success or
336*8b26181fSAndroid Build Coastguard Worker  * failure of a call that returns these codes by checking for a
337*8b26181fSAndroid Build Coastguard Worker  * negative value.
338*8b26181fSAndroid Build Coastguard Worker  */
339*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR			-1	/* generic error code */
340*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_BREAK		-2	/* loop terminated by pcap_breakloop */
341*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_NOT_ACTIVATED	-3	/* the capture needs to be activated */
342*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_ACTIVATED		-4	/* the operation can't be performed on already activated captures */
343*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_NO_SUCH_DEVICE	-5	/* no such device exists */
344*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_RFMON_NOTSUP		-6	/* this device doesn't support rfmon (monitor) mode */
345*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_NOT_RFMON		-7	/* operation supported only in monitor mode */
346*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_PERM_DENIED		-8	/* no permission to open the device */
347*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_IFACE_NOT_UP		-9	/* interface isn't up */
348*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_CANTSET_TSTAMP_TYPE	-10	/* this device doesn't support setting the time stamp type */
349*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_PROMISC_PERM_DENIED	-11	/* you don't have permission to capture in promiscuous mode */
350*8b26181fSAndroid Build Coastguard Worker #define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12  /* the requested time stamp precision is not supported */
351*8b26181fSAndroid Build Coastguard Worker 
352*8b26181fSAndroid Build Coastguard Worker /*
353*8b26181fSAndroid Build Coastguard Worker  * Warning codes for the pcap API.
354*8b26181fSAndroid Build Coastguard Worker  * These will all be positive and non-zero, so they won't look like
355*8b26181fSAndroid Build Coastguard Worker  * errors.
356*8b26181fSAndroid Build Coastguard Worker  */
357*8b26181fSAndroid Build Coastguard Worker #define PCAP_WARNING			1	/* generic warning code */
358*8b26181fSAndroid Build Coastguard Worker #define PCAP_WARNING_PROMISC_NOTSUP	2	/* this device doesn't support promiscuous mode */
359*8b26181fSAndroid Build Coastguard Worker #define PCAP_WARNING_TSTAMP_TYPE_NOTSUP	3	/* the requested time stamp type is not supported */
360*8b26181fSAndroid Build Coastguard Worker 
361*8b26181fSAndroid Build Coastguard Worker /*
362*8b26181fSAndroid Build Coastguard Worker  * Value to pass to pcap_compile() as the netmask if you don't know what
363*8b26181fSAndroid Build Coastguard Worker  * the netmask is.
364*8b26181fSAndroid Build Coastguard Worker  */
365*8b26181fSAndroid Build Coastguard Worker #define PCAP_NETMASK_UNKNOWN	0xffffffff
366*8b26181fSAndroid Build Coastguard Worker 
367*8b26181fSAndroid Build Coastguard Worker /*
368*8b26181fSAndroid Build Coastguard Worker  * Initialize pcap.  If this isn't called, pcap is initialized to
369*8b26181fSAndroid Build Coastguard Worker  * a mode source-compatible and binary-compatible with older versions
370*8b26181fSAndroid Build Coastguard Worker  * that lack this routine.
371*8b26181fSAndroid Build Coastguard Worker  */
372*8b26181fSAndroid Build Coastguard Worker 
373*8b26181fSAndroid Build Coastguard Worker /*
374*8b26181fSAndroid Build Coastguard Worker  * Initialization options.
375*8b26181fSAndroid Build Coastguard Worker  * All bits not listed here are reserved for expansion.
376*8b26181fSAndroid Build Coastguard Worker  *
377*8b26181fSAndroid Build Coastguard Worker  * On UNIX-like systems, the local character encoding is assumed to be
378*8b26181fSAndroid Build Coastguard Worker  * UTF-8, so no character encoding transformations are done.
379*8b26181fSAndroid Build Coastguard Worker  *
380*8b26181fSAndroid Build Coastguard Worker  * On Windows, the local character encoding is the local ANSI code page.
381*8b26181fSAndroid Build Coastguard Worker  */
382*8b26181fSAndroid Build Coastguard Worker #define PCAP_CHAR_ENC_LOCAL	0x00000000U	/* strings are in the local character encoding */
383*8b26181fSAndroid Build Coastguard Worker #define PCAP_CHAR_ENC_UTF_8	0x00000001U	/* strings are in UTF-8 */
384*8b26181fSAndroid Build Coastguard Worker 
385*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_10
386*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_init(unsigned int, char *);
387*8b26181fSAndroid Build Coastguard Worker 
388*8b26181fSAndroid Build Coastguard Worker /*
389*8b26181fSAndroid Build Coastguard Worker  * We're deprecating pcap_lookupdev() for various reasons (not
390*8b26181fSAndroid Build Coastguard Worker  * thread-safe, can behave weirdly with WinPcap).  Callers
391*8b26181fSAndroid Build Coastguard Worker  * should use pcap_findalldevs() and use the first device.
392*8b26181fSAndroid Build Coastguard Worker  */
393*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
394*8b26181fSAndroid Build Coastguard Worker PCAP_DEPRECATED("use 'pcap_findalldevs' and use the first device")
395*8b26181fSAndroid Build Coastguard Worker PCAP_API char	*pcap_lookupdev(char *);
396*8b26181fSAndroid Build Coastguard Worker 
397*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
398*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
399*8b26181fSAndroid Build Coastguard Worker 
400*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
401*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_create(const char *, char *);
402*8b26181fSAndroid Build Coastguard Worker 
403*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
404*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_snaplen(pcap_t *, int);
405*8b26181fSAndroid Build Coastguard Worker 
406*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
407*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_promisc(pcap_t *, int);
408*8b26181fSAndroid Build Coastguard Worker 
409*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
410*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_can_set_rfmon(pcap_t *);
411*8b26181fSAndroid Build Coastguard Worker 
412*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
413*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_rfmon(pcap_t *, int);
414*8b26181fSAndroid Build Coastguard Worker 
415*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
416*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_timeout(pcap_t *, int);
417*8b26181fSAndroid Build Coastguard Worker 
418*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
419*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_tstamp_type(pcap_t *, int);
420*8b26181fSAndroid Build Coastguard Worker 
421*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_5
422*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_immediate_mode(pcap_t *, int);
423*8b26181fSAndroid Build Coastguard Worker 
424*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
425*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_buffer_size(pcap_t *, int);
426*8b26181fSAndroid Build Coastguard Worker 
427*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_5
428*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_tstamp_precision(pcap_t *, int);
429*8b26181fSAndroid Build Coastguard Worker 
430*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_5
431*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_get_tstamp_precision(pcap_t *);
432*8b26181fSAndroid Build Coastguard Worker 
433*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
434*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_activate(pcap_t *);
435*8b26181fSAndroid Build Coastguard Worker 
436*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
437*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_list_tstamp_types(pcap_t *, int **);
438*8b26181fSAndroid Build Coastguard Worker 
439*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
440*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_free_tstamp_types(int *);
441*8b26181fSAndroid Build Coastguard Worker 
442*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
443*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_tstamp_type_name_to_val(const char *);
444*8b26181fSAndroid Build Coastguard Worker 
445*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
446*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_tstamp_type_val_to_name(int);
447*8b26181fSAndroid Build Coastguard Worker 
448*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_2
449*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_tstamp_type_val_to_description(int);
450*8b26181fSAndroid Build Coastguard Worker 
451*8b26181fSAndroid Build Coastguard Worker #ifdef __linux__
452*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
453*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_protocol_linux(pcap_t *, int);
454*8b26181fSAndroid Build Coastguard Worker #endif
455*8b26181fSAndroid Build Coastguard Worker 
456*8b26181fSAndroid Build Coastguard Worker /*
457*8b26181fSAndroid Build Coastguard Worker  * Time stamp types.
458*8b26181fSAndroid Build Coastguard Worker  * Not all systems and interfaces will necessarily support all of these.
459*8b26181fSAndroid Build Coastguard Worker  *
460*8b26181fSAndroid Build Coastguard Worker  * A system that supports PCAP_TSTAMP_HOST is offering time stamps
461*8b26181fSAndroid Build Coastguard Worker  * provided by the host machine, rather than by the capture device,
462*8b26181fSAndroid Build Coastguard Worker  * but not committing to any characteristics of the time stamp.
463*8b26181fSAndroid Build Coastguard Worker  *
464*8b26181fSAndroid Build Coastguard Worker  * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine,
465*8b26181fSAndroid Build Coastguard Worker  * that's low-precision but relatively cheap to fetch; it's normally done
466*8b26181fSAndroid Build Coastguard Worker  * using the system clock, so it's normally synchronized with times you'd
467*8b26181fSAndroid Build Coastguard Worker  * fetch from system calls.
468*8b26181fSAndroid Build Coastguard Worker  *
469*8b26181fSAndroid Build Coastguard Worker  * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine,
470*8b26181fSAndroid Build Coastguard Worker  * that's high-precision; it might be more expensive to fetch.  It is
471*8b26181fSAndroid Build Coastguard Worker  * synchronized with the system clock.
472*8b26181fSAndroid Build Coastguard Worker  *
473*8b26181fSAndroid Build Coastguard Worker  * PCAP_TSTAMP_HOST_HIPREC_UNSYNCED is a time stamp, provided by the host
474*8b26181fSAndroid Build Coastguard Worker  * machine, that's high-precision; it might be more expensive to fetch.
475*8b26181fSAndroid Build Coastguard Worker  * It is not synchronized with the system clock, and might have
476*8b26181fSAndroid Build Coastguard Worker  * problems with time stamps for packets received on different CPUs,
477*8b26181fSAndroid Build Coastguard Worker  * depending on the platform.  It might be more likely to be strictly
478*8b26181fSAndroid Build Coastguard Worker  * monotonic than PCAP_TSTAMP_HOST_HIPREC.
479*8b26181fSAndroid Build Coastguard Worker  *
480*8b26181fSAndroid Build Coastguard Worker  * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the
481*8b26181fSAndroid Build Coastguard Worker  * capture device; it's synchronized with the system clock.
482*8b26181fSAndroid Build Coastguard Worker  *
483*8b26181fSAndroid Build Coastguard Worker  * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by
484*8b26181fSAndroid Build Coastguard Worker  * the capture device; it's not synchronized with the system clock.
485*8b26181fSAndroid Build Coastguard Worker  *
486*8b26181fSAndroid Build Coastguard Worker  * Note that time stamps synchronized with the system clock can go
487*8b26181fSAndroid Build Coastguard Worker  * backwards, as the system clock can go backwards.  If a clock is
488*8b26181fSAndroid Build Coastguard Worker  * not in sync with the system clock, that could be because the
489*8b26181fSAndroid Build Coastguard Worker  * system clock isn't keeping accurate time, because the other
490*8b26181fSAndroid Build Coastguard Worker  * clock isn't keeping accurate time, or both.
491*8b26181fSAndroid Build Coastguard Worker  *
492*8b26181fSAndroid Build Coastguard Worker  * Note that host-provided time stamps generally correspond to the
493*8b26181fSAndroid Build Coastguard Worker  * time when the time-stamping code sees the packet; this could
494*8b26181fSAndroid Build Coastguard Worker  * be some unknown amount of time after the first or last bit of
495*8b26181fSAndroid Build Coastguard Worker  * the packet is received by the network adapter, due to batching
496*8b26181fSAndroid Build Coastguard Worker  * of interrupts for packet arrival, queueing delays, etc..
497*8b26181fSAndroid Build Coastguard Worker  */
498*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_HOST			0	/* host-provided, unknown characteristics */
499*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_HOST_LOWPREC		1	/* host-provided, low precision, synced with the system clock */
500*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_HOST_HIPREC			2	/* host-provided, high precision, synced with the system clock */
501*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_ADAPTER			3	/* device-provided, synced with the system clock */
502*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_ADAPTER_UNSYNCED		4	/* device-provided, not synced with the system clock */
503*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_HOST_HIPREC_UNSYNCED	5	/* host-provided, high precision, not synced with the system clock */
504*8b26181fSAndroid Build Coastguard Worker 
505*8b26181fSAndroid Build Coastguard Worker /*
506*8b26181fSAndroid Build Coastguard Worker  * Time stamp resolution types.
507*8b26181fSAndroid Build Coastguard Worker  * Not all systems and interfaces will necessarily support all of these
508*8b26181fSAndroid Build Coastguard Worker  * resolutions when doing live captures; all of them can be requested
509*8b26181fSAndroid Build Coastguard Worker  * when reading a savefile.
510*8b26181fSAndroid Build Coastguard Worker  */
511*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_PRECISION_MICRO	0	/* use timestamps with microsecond precision, default */
512*8b26181fSAndroid Build Coastguard Worker #define PCAP_TSTAMP_PRECISION_NANO	1	/* use timestamps with nanosecond precision */
513*8b26181fSAndroid Build Coastguard Worker 
514*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
515*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open_live(const char *, int, int, int, char *);
516*8b26181fSAndroid Build Coastguard Worker 
517*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_6
518*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open_dead(int, int);
519*8b26181fSAndroid Build Coastguard Worker 
520*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_5
521*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open_dead_with_tstamp_precision(int, int, u_int);
522*8b26181fSAndroid Build Coastguard Worker 
523*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_5
524*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
525*8b26181fSAndroid Build Coastguard Worker 
526*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
527*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open_offline(const char *, char *);
528*8b26181fSAndroid Build Coastguard Worker 
529*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
530*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_1_5
531*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_t  *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
532*8b26181fSAndroid Build Coastguard Worker 
533*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_t  *pcap_hopen_offline(intptr_t, char *);
534*8b26181fSAndroid Build Coastguard Worker   /*
535*8b26181fSAndroid Build Coastguard Worker    * If we're building libpcap, these are internal routines in savefile.c,
536*8b26181fSAndroid Build Coastguard Worker    * so we must not define them as macros.
537*8b26181fSAndroid Build Coastguard Worker    *
538*8b26181fSAndroid Build Coastguard Worker    * If we're not building libpcap, given that the version of the C runtime
539*8b26181fSAndroid Build Coastguard Worker    * with which libpcap was built might be different from the version
540*8b26181fSAndroid Build Coastguard Worker    * of the C runtime with which an application using libpcap was built,
541*8b26181fSAndroid Build Coastguard Worker    * and that a FILE structure may differ between the two versions of the
542*8b26181fSAndroid Build Coastguard Worker    * C runtime, calls to _fileno() must use the version of _fileno() in
543*8b26181fSAndroid Build Coastguard Worker    * the C runtime used to open the FILE *, not the version in the C
544*8b26181fSAndroid Build Coastguard Worker    * runtime with which libpcap was built.  (Maybe once the Universal CRT
545*8b26181fSAndroid Build Coastguard Worker    * rules the world, this will cease to be a problem.)
546*8b26181fSAndroid Build Coastguard Worker    */
547*8b26181fSAndroid Build Coastguard Worker   #ifndef BUILDING_PCAP
548*8b26181fSAndroid Build Coastguard Worker     #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
549*8b26181fSAndroid Build Coastguard Worker 	pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
550*8b26181fSAndroid Build Coastguard Worker     #define pcap_fopen_offline(f,b) \
551*8b26181fSAndroid Build Coastguard Worker 	pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
552*8b26181fSAndroid Build Coastguard Worker   #endif
553*8b26181fSAndroid Build Coastguard Worker #else /*_WIN32*/
554*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_1_5
555*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_t	*pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
556*8b26181fSAndroid Build Coastguard Worker 
557*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_0_9
558*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_t	*pcap_fopen_offline(FILE *, char *);
559*8b26181fSAndroid Build Coastguard Worker #endif /*_WIN32*/
560*8b26181fSAndroid Build Coastguard Worker 
561*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
562*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_close(pcap_t *);
563*8b26181fSAndroid Build Coastguard Worker 
564*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
565*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_loop(pcap_t *, int, pcap_handler, u_char *);
566*8b26181fSAndroid Build Coastguard Worker 
567*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
568*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
569*8b26181fSAndroid Build Coastguard Worker 
570*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
571*8b26181fSAndroid Build Coastguard Worker PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
572*8b26181fSAndroid Build Coastguard Worker 
573*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
574*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
575*8b26181fSAndroid Build Coastguard Worker 
576*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
577*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_breakloop(pcap_t *);
578*8b26181fSAndroid Build Coastguard Worker 
579*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
580*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_stats(pcap_t *, struct pcap_stat *);
581*8b26181fSAndroid Build Coastguard Worker 
582*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
583*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_setfilter(pcap_t *, struct bpf_program *);
584*8b26181fSAndroid Build Coastguard Worker 
585*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_9
586*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_setdirection(pcap_t *, pcap_direction_t);
587*8b26181fSAndroid Build Coastguard Worker 
588*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_7
589*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_getnonblock(pcap_t *, char *);
590*8b26181fSAndroid Build Coastguard Worker 
591*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_7
592*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_setnonblock(pcap_t *, int, char *);
593*8b26181fSAndroid Build Coastguard Worker 
594*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_9
595*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_inject(pcap_t *, const void *, size_t);
596*8b26181fSAndroid Build Coastguard Worker 
597*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
598*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_sendpacket(pcap_t *, const u_char *, int);
599*8b26181fSAndroid Build Coastguard Worker 
600*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
601*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_statustostr(int);
602*8b26181fSAndroid Build Coastguard Worker 
603*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
604*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_strerror(int);
605*8b26181fSAndroid Build Coastguard Worker 
606*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
607*8b26181fSAndroid Build Coastguard Worker PCAP_API char	*pcap_geterr(pcap_t *);
608*8b26181fSAndroid Build Coastguard Worker 
609*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
610*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_perror(pcap_t *, const char *);
611*8b26181fSAndroid Build Coastguard Worker 
612*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
613*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
614*8b26181fSAndroid Build Coastguard Worker 	    bpf_u_int32);
615*8b26181fSAndroid Build Coastguard Worker 
616*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_5
617*8b26181fSAndroid Build Coastguard Worker PCAP_DEPRECATED("use pcap_open_dead(), pcap_compile() and pcap_close()")
618*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_compile_nopcap(int, int, struct bpf_program *,
619*8b26181fSAndroid Build Coastguard Worker 	    const char *, int, bpf_u_int32);
620*8b26181fSAndroid Build Coastguard Worker 
621*8b26181fSAndroid Build Coastguard Worker /* XXX - this took two arguments in 0.4 and 0.5 */
622*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_6
623*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_freecode(struct bpf_program *);
624*8b26181fSAndroid Build Coastguard Worker 
625*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
626*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_offline_filter(const struct bpf_program *,
627*8b26181fSAndroid Build Coastguard Worker 	    const struct pcap_pkthdr *, const u_char *);
628*8b26181fSAndroid Build Coastguard Worker 
629*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
630*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_datalink(pcap_t *);
631*8b26181fSAndroid Build Coastguard Worker 
632*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_0
633*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_datalink_ext(pcap_t *);
634*8b26181fSAndroid Build Coastguard Worker 
635*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
636*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_list_datalinks(pcap_t *, int **);
637*8b26181fSAndroid Build Coastguard Worker 
638*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
639*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_set_datalink(pcap_t *, int);
640*8b26181fSAndroid Build Coastguard Worker 
641*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
642*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_free_datalinks(int *);
643*8b26181fSAndroid Build Coastguard Worker 
644*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
645*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_datalink_name_to_val(const char *);
646*8b26181fSAndroid Build Coastguard Worker 
647*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
648*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_datalink_val_to_name(int);
649*8b26181fSAndroid Build Coastguard Worker 
650*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
651*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_datalink_val_to_description(int);
652*8b26181fSAndroid Build Coastguard Worker 
653*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_10
654*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
655*8b26181fSAndroid Build Coastguard Worker 
656*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
657*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_snapshot(pcap_t *);
658*8b26181fSAndroid Build Coastguard Worker 
659*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
660*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_is_swapped(pcap_t *);
661*8b26181fSAndroid Build Coastguard Worker 
662*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
663*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_major_version(pcap_t *);
664*8b26181fSAndroid Build Coastguard Worker 
665*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
666*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_minor_version(pcap_t *);
667*8b26181fSAndroid Build Coastguard Worker 
668*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
669*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_bufsize(pcap_t *);
670*8b26181fSAndroid Build Coastguard Worker 
671*8b26181fSAndroid Build Coastguard Worker /* XXX */
672*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
673*8b26181fSAndroid Build Coastguard Worker PCAP_API FILE	*pcap_file(pcap_t *);
674*8b26181fSAndroid Build Coastguard Worker 
675*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
676*8b26181fSAndroid Build Coastguard Worker /*
677*8b26181fSAndroid Build Coastguard Worker  * This probably shouldn't have been kept in WinPcap; most if not all
678*8b26181fSAndroid Build Coastguard Worker  * UN*X code that used it won't work on Windows.  We deprecate it; if
679*8b26181fSAndroid Build Coastguard Worker  * anybody really needs access to whatever HANDLE may be associated
680*8b26181fSAndroid Build Coastguard Worker  * with a pcap_t (there's no guarantee that there is one), we can add
681*8b26181fSAndroid Build Coastguard Worker  * a Windows-only pcap_handle() API that returns the HANDLE.
682*8b26181fSAndroid Build Coastguard Worker  */
683*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
684*8b26181fSAndroid Build Coastguard Worker PCAP_DEPRECATED("request a 'pcap_handle' that returns a HANDLE if you need it")
685*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_fileno(pcap_t *);
686*8b26181fSAndroid Build Coastguard Worker #else /* _WIN32 */
687*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
688*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_fileno(pcap_t *);
689*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32 */
690*8b26181fSAndroid Build Coastguard Worker 
691*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
692*8b26181fSAndroid Build Coastguard Worker   PCAP_API int	pcap_wsockinit(void);
693*8b26181fSAndroid Build Coastguard Worker #endif
694*8b26181fSAndroid Build Coastguard Worker 
695*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
696*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
697*8b26181fSAndroid Build Coastguard Worker 
698*8b26181fSAndroid Build Coastguard Worker #ifdef _WIN32
699*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_0_9
700*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
701*8b26181fSAndroid Build Coastguard Worker 
702*8b26181fSAndroid Build Coastguard Worker   /*
703*8b26181fSAndroid Build Coastguard Worker    * If we're building libpcap, this is an internal routine in sf-pcap.c, so
704*8b26181fSAndroid Build Coastguard Worker    * we must not define it as a macro.
705*8b26181fSAndroid Build Coastguard Worker    *
706*8b26181fSAndroid Build Coastguard Worker    * If we're not building libpcap, given that the version of the C runtime
707*8b26181fSAndroid Build Coastguard Worker    * with which libpcap was built might be different from the version
708*8b26181fSAndroid Build Coastguard Worker    * of the C runtime with which an application using libpcap was built,
709*8b26181fSAndroid Build Coastguard Worker    * and that a FILE structure may differ between the two versions of the
710*8b26181fSAndroid Build Coastguard Worker    * C runtime, calls to _fileno() must use the version of _fileno() in
711*8b26181fSAndroid Build Coastguard Worker    * the C runtime used to open the FILE *, not the version in the C
712*8b26181fSAndroid Build Coastguard Worker    * runtime with which libpcap was built.  (Maybe once the Universal CRT
713*8b26181fSAndroid Build Coastguard Worker    * rules the world, this will cease to be a problem.)
714*8b26181fSAndroid Build Coastguard Worker    */
715*8b26181fSAndroid Build Coastguard Worker   #ifndef BUILDING_PCAP
716*8b26181fSAndroid Build Coastguard Worker     #define pcap_dump_fopen(p,f) \
717*8b26181fSAndroid Build Coastguard Worker 	pcap_dump_hopen(p, _get_osfhandle(_fileno(f)))
718*8b26181fSAndroid Build Coastguard Worker   #endif
719*8b26181fSAndroid Build Coastguard Worker #else /*_WIN32*/
720*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_0_9
721*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
722*8b26181fSAndroid Build Coastguard Worker #endif /*_WIN32*/
723*8b26181fSAndroid Build Coastguard Worker 
724*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_7
725*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
726*8b26181fSAndroid Build Coastguard Worker 
727*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
728*8b26181fSAndroid Build Coastguard Worker PCAP_API FILE	*pcap_dump_file(pcap_dumper_t *);
729*8b26181fSAndroid Build Coastguard Worker 
730*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_9
731*8b26181fSAndroid Build Coastguard Worker PCAP_API long	pcap_dump_ftell(pcap_dumper_t *);
732*8b26181fSAndroid Build Coastguard Worker 
733*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
734*8b26181fSAndroid Build Coastguard Worker PCAP_API int64_t	pcap_dump_ftell64(pcap_dumper_t *);
735*8b26181fSAndroid Build Coastguard Worker 
736*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
737*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_dump_flush(pcap_dumper_t *);
738*8b26181fSAndroid Build Coastguard Worker 
739*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
740*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_dump_close(pcap_dumper_t *);
741*8b26181fSAndroid Build Coastguard Worker 
742*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_4
743*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
744*8b26181fSAndroid Build Coastguard Worker 
745*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_7
746*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_findalldevs(pcap_if_t **, char *);
747*8b26181fSAndroid Build Coastguard Worker 
748*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_7
749*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_freealldevs(pcap_if_t *);
750*8b26181fSAndroid Build Coastguard Worker 
751*8b26181fSAndroid Build Coastguard Worker /*
752*8b26181fSAndroid Build Coastguard Worker  * We return a pointer to the version string, rather than exporting the
753*8b26181fSAndroid Build Coastguard Worker  * version string directly.
754*8b26181fSAndroid Build Coastguard Worker  *
755*8b26181fSAndroid Build Coastguard Worker  * On at least some UNIXes, if you import data from a shared library into
756*8b26181fSAndroid Build Coastguard Worker  * a program, the data is bound into the program binary, so if the string
757*8b26181fSAndroid Build Coastguard Worker  * in the version of the library with which the program was linked isn't
758*8b26181fSAndroid Build Coastguard Worker  * the same as the string in the version of the library with which the
759*8b26181fSAndroid Build Coastguard Worker  * program is being run, various undesirable things may happen (warnings,
760*8b26181fSAndroid Build Coastguard Worker  * the string being the one from the version of the library with which the
761*8b26181fSAndroid Build Coastguard Worker  * program was linked, or even weirder things, such as the string being the
762*8b26181fSAndroid Build Coastguard Worker  * one from the library but being truncated).
763*8b26181fSAndroid Build Coastguard Worker  *
764*8b26181fSAndroid Build Coastguard Worker  * On Windows, the string is constructed at run time.
765*8b26181fSAndroid Build Coastguard Worker  */
766*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_0_8
767*8b26181fSAndroid Build Coastguard Worker PCAP_API const char *pcap_lib_version(void);
768*8b26181fSAndroid Build Coastguard Worker 
769*8b26181fSAndroid Build Coastguard Worker #if defined(_WIN32)
770*8b26181fSAndroid Build Coastguard Worker 
771*8b26181fSAndroid Build Coastguard Worker   /*
772*8b26181fSAndroid Build Coastguard Worker    * Win32 definitions
773*8b26181fSAndroid Build Coastguard Worker    */
774*8b26181fSAndroid Build Coastguard Worker 
775*8b26181fSAndroid Build Coastguard Worker   /*!
776*8b26181fSAndroid Build Coastguard Worker     \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
777*8b26181fSAndroid Build Coastguard Worker   */
778*8b26181fSAndroid Build Coastguard Worker   struct pcap_send_queue
779*8b26181fSAndroid Build Coastguard Worker   {
780*8b26181fSAndroid Build Coastguard Worker 	u_int maxlen;	/* Maximum size of the queue, in bytes. This
781*8b26181fSAndroid Build Coastguard Worker 			   variable contains the size of the buffer field. */
782*8b26181fSAndroid Build Coastguard Worker 	u_int len;	/* Current size of the queue, in bytes. */
783*8b26181fSAndroid Build Coastguard Worker 	char *buffer;	/* Buffer containing the packets to be sent. */
784*8b26181fSAndroid Build Coastguard Worker   };
785*8b26181fSAndroid Build Coastguard Worker 
786*8b26181fSAndroid Build Coastguard Worker   typedef struct pcap_send_queue pcap_send_queue;
787*8b26181fSAndroid Build Coastguard Worker 
788*8b26181fSAndroid Build Coastguard Worker   /*!
789*8b26181fSAndroid Build Coastguard Worker     \brief This typedef is a support for the pcap_get_airpcap_handle() function
790*8b26181fSAndroid Build Coastguard Worker   */
791*8b26181fSAndroid Build Coastguard Worker   #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
792*8b26181fSAndroid Build Coastguard Worker     #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
793*8b26181fSAndroid Build Coastguard Worker     typedef struct _AirpcapHandle *PAirpcapHandle;
794*8b26181fSAndroid Build Coastguard Worker   #endif
795*8b26181fSAndroid Build Coastguard Worker 
796*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_setbuff(pcap_t *p, int dim);
797*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_setmode(pcap_t *p, int mode);
798*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_setmintocopy(pcap_t *p, int size);
799*8b26181fSAndroid Build Coastguard Worker 
800*8b26181fSAndroid Build Coastguard Worker   PCAP_API HANDLE pcap_getevent(pcap_t *p);
801*8b26181fSAndroid Build Coastguard Worker 
802*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_1_8
803*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
804*8b26181fSAndroid Build Coastguard Worker 
805*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_1_8
806*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
807*8b26181fSAndroid Build Coastguard Worker 
808*8b26181fSAndroid Build Coastguard Worker   PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
809*8b26181fSAndroid Build Coastguard Worker 
810*8b26181fSAndroid Build Coastguard Worker   PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
811*8b26181fSAndroid Build Coastguard Worker 
812*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
813*8b26181fSAndroid Build Coastguard Worker 
814*8b26181fSAndroid Build Coastguard Worker   PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
815*8b26181fSAndroid Build Coastguard Worker 
816*8b26181fSAndroid Build Coastguard Worker   PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
817*8b26181fSAndroid Build Coastguard Worker 
818*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_setuserbuffer(pcap_t *p, int size);
819*8b26181fSAndroid Build Coastguard Worker 
820*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
821*8b26181fSAndroid Build Coastguard Worker 
822*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync);
823*8b26181fSAndroid Build Coastguard Worker 
824*8b26181fSAndroid Build Coastguard Worker   PCAP_API int pcap_start_oem(char* err_str, int flags);
825*8b26181fSAndroid Build Coastguard Worker 
826*8b26181fSAndroid Build Coastguard Worker   PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
827*8b26181fSAndroid Build Coastguard Worker 
828*8b26181fSAndroid Build Coastguard Worker   #define MODE_CAPT 0
829*8b26181fSAndroid Build Coastguard Worker   #define MODE_STAT 1
830*8b26181fSAndroid Build Coastguard Worker   #define MODE_MON 2
831*8b26181fSAndroid Build Coastguard Worker 
832*8b26181fSAndroid Build Coastguard Worker #elif defined(MSDOS)
833*8b26181fSAndroid Build Coastguard Worker 
834*8b26181fSAndroid Build Coastguard Worker   /*
835*8b26181fSAndroid Build Coastguard Worker    * MS-DOS definitions
836*8b26181fSAndroid Build Coastguard Worker    */
837*8b26181fSAndroid Build Coastguard Worker 
838*8b26181fSAndroid Build Coastguard Worker   PCAP_API int  pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
839*8b26181fSAndroid Build Coastguard Worker   PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
840*8b26181fSAndroid Build Coastguard Worker   PCAP_API u_long pcap_mac_packets (void);
841*8b26181fSAndroid Build Coastguard Worker 
842*8b26181fSAndroid Build Coastguard Worker #else /* UN*X */
843*8b26181fSAndroid Build Coastguard Worker 
844*8b26181fSAndroid Build Coastguard Worker   /*
845*8b26181fSAndroid Build Coastguard Worker    * UN*X definitions
846*8b26181fSAndroid Build Coastguard Worker    */
847*8b26181fSAndroid Build Coastguard Worker 
848*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_0_8
849*8b26181fSAndroid Build Coastguard Worker   PCAP_API int	pcap_get_selectable_fd(pcap_t *);
850*8b26181fSAndroid Build Coastguard Worker 
851*8b26181fSAndroid Build Coastguard Worker   PCAP_AVAILABLE_1_9
852*8b26181fSAndroid Build Coastguard Worker   PCAP_API const struct timeval *pcap_get_required_select_timeout(pcap_t *);
853*8b26181fSAndroid Build Coastguard Worker 
854*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32/MSDOS/UN*X */
855*8b26181fSAndroid Build Coastguard Worker 
856*8b26181fSAndroid Build Coastguard Worker /*
857*8b26181fSAndroid Build Coastguard Worker  * Remote capture definitions.
858*8b26181fSAndroid Build Coastguard Worker  *
859*8b26181fSAndroid Build Coastguard Worker  * These routines are only present if libpcap has been configured to
860*8b26181fSAndroid Build Coastguard Worker  * include remote capture support.
861*8b26181fSAndroid Build Coastguard Worker  */
862*8b26181fSAndroid Build Coastguard Worker 
863*8b26181fSAndroid Build Coastguard Worker /*
864*8b26181fSAndroid Build Coastguard Worker  * The maximum buffer size in which address, port, interface names are kept.
865*8b26181fSAndroid Build Coastguard Worker  *
866*8b26181fSAndroid Build Coastguard Worker  * In case the adapter name or such is larger than this value, it is truncated.
867*8b26181fSAndroid Build Coastguard Worker  * This is not used by the user; however it must be aware that an hostname / interface
868*8b26181fSAndroid Build Coastguard Worker  * name longer than this value will be truncated.
869*8b26181fSAndroid Build Coastguard Worker  */
870*8b26181fSAndroid Build Coastguard Worker #define PCAP_BUF_SIZE 1024
871*8b26181fSAndroid Build Coastguard Worker 
872*8b26181fSAndroid Build Coastguard Worker /*
873*8b26181fSAndroid Build Coastguard Worker  * The type of input source, passed to pcap_open().
874*8b26181fSAndroid Build Coastguard Worker  */
875*8b26181fSAndroid Build Coastguard Worker #define PCAP_SRC_FILE		2	/* local savefile */
876*8b26181fSAndroid Build Coastguard Worker #define PCAP_SRC_IFLOCAL	3	/* local network interface */
877*8b26181fSAndroid Build Coastguard Worker #define PCAP_SRC_IFREMOTE	4	/* interface on a remote host, using RPCAP */
878*8b26181fSAndroid Build Coastguard Worker 
879*8b26181fSAndroid Build Coastguard Worker /*
880*8b26181fSAndroid Build Coastguard Worker  * The formats allowed by pcap_open() are the following:
881*8b26181fSAndroid Build Coastguard Worker  * - file://path_and_filename [opens a local file]
882*8b26181fSAndroid Build Coastguard Worker  * - rpcap://devicename [opens the selected device available on the local host, without using the RPCAP protocol]
883*8b26181fSAndroid Build Coastguard Worker  * - rpcap://host/devicename [opens the selected device available on a remote host]
884*8b26181fSAndroid Build Coastguard Worker  * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
885*8b26181fSAndroid Build Coastguard Worker  * - adaptername [to open a local adapter; kept for compatibility, but it is strongly discouraged]
886*8b26181fSAndroid Build Coastguard Worker  * - (NULL) [to open the first local adapter; kept for compatibility, but it is strongly discouraged]
887*8b26181fSAndroid Build Coastguard Worker  *
888*8b26181fSAndroid Build Coastguard Worker  * The formats allowed by the pcap_findalldevs_ex() are the following:
889*8b26181fSAndroid Build Coastguard Worker  * - file://folder/ [lists all the files in the given folder]
890*8b26181fSAndroid Build Coastguard Worker  * - rpcap:// [lists all local adapters]
891*8b26181fSAndroid Build Coastguard Worker  * - rpcap://host:port/ [lists the devices available on a remote host]
892*8b26181fSAndroid Build Coastguard Worker  *
893*8b26181fSAndroid Build Coastguard Worker  * In all the above, "rpcaps://" can be substituted for "rpcap://" to enable
894*8b26181fSAndroid Build Coastguard Worker  * SSL (if it has been compiled in).
895*8b26181fSAndroid Build Coastguard Worker  *
896*8b26181fSAndroid Build Coastguard Worker  * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since
897*8b26181fSAndroid Build Coastguard Worker  * IPv6 is fully supported, these are the allowed formats:
898*8b26181fSAndroid Build Coastguard Worker  *
899*8b26181fSAndroid Build Coastguard Worker  * - host (literal): e.g. host.foo.bar
900*8b26181fSAndroid Build Coastguard Worker  * - host (numeric IPv4): e.g. 10.11.12.13
901*8b26181fSAndroid Build Coastguard Worker  * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
902*8b26181fSAndroid Build Coastguard Worker  * - host (numeric IPv6): e.g. [1:2:3::4]
903*8b26181fSAndroid Build Coastguard Worker  * - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
904*8b26181fSAndroid Build Coastguard Worker  *
905*8b26181fSAndroid Build Coastguard Worker  * Here you find some allowed examples:
906*8b26181fSAndroid Build Coastguard Worker  * - rpcap://host.foo.bar/devicename [everything literal, no port number]
907*8b26181fSAndroid Build Coastguard Worker  * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
908*8b26181fSAndroid Build Coastguard Worker  * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
909*8b26181fSAndroid Build Coastguard Worker  * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
910*8b26181fSAndroid Build Coastguard Worker  * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
911*8b26181fSAndroid Build Coastguard Worker  * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
912*8b26181fSAndroid Build Coastguard Worker  * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
913*8b26181fSAndroid Build Coastguard Worker  * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
914*8b26181fSAndroid Build Coastguard Worker  */
915*8b26181fSAndroid Build Coastguard Worker 
916*8b26181fSAndroid Build Coastguard Worker /*
917*8b26181fSAndroid Build Coastguard Worker  * URL schemes for capture source.
918*8b26181fSAndroid Build Coastguard Worker  */
919*8b26181fSAndroid Build Coastguard Worker /*
920*8b26181fSAndroid Build Coastguard Worker  * This string indicates that the user wants to open a capture from a
921*8b26181fSAndroid Build Coastguard Worker  * local file.
922*8b26181fSAndroid Build Coastguard Worker  */
923*8b26181fSAndroid Build Coastguard Worker #define PCAP_SRC_FILE_STRING "file://"
924*8b26181fSAndroid Build Coastguard Worker /*
925*8b26181fSAndroid Build Coastguard Worker  * This string indicates that the user wants to open a capture from a
926*8b26181fSAndroid Build Coastguard Worker  * network interface.  This string does not necessarily involve the use
927*8b26181fSAndroid Build Coastguard Worker  * of the RPCAP protocol. If the interface required resides on the local
928*8b26181fSAndroid Build Coastguard Worker  * host, the RPCAP protocol is not involved and the local functions are used.
929*8b26181fSAndroid Build Coastguard Worker  */
930*8b26181fSAndroid Build Coastguard Worker #define PCAP_SRC_IF_STRING "rpcap://"
931*8b26181fSAndroid Build Coastguard Worker 
932*8b26181fSAndroid Build Coastguard Worker /*
933*8b26181fSAndroid Build Coastguard Worker  * Flags to pass to pcap_open().
934*8b26181fSAndroid Build Coastguard Worker  */
935*8b26181fSAndroid Build Coastguard Worker 
936*8b26181fSAndroid Build Coastguard Worker /*
937*8b26181fSAndroid Build Coastguard Worker  * Specifies whether promiscuous mode is to be used.
938*8b26181fSAndroid Build Coastguard Worker  */
939*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPENFLAG_PROMISCUOUS		0x00000001
940*8b26181fSAndroid Build Coastguard Worker 
941*8b26181fSAndroid Build Coastguard Worker /*
942*8b26181fSAndroid Build Coastguard Worker  * Specifies, for an RPCAP capture, whether the data transfer (in
943*8b26181fSAndroid Build Coastguard Worker  * case of a remote capture) has to be done with UDP protocol.
944*8b26181fSAndroid Build Coastguard Worker  *
945*8b26181fSAndroid Build Coastguard Worker  * If it is '1' if you want a UDP data connection, '0' if you want
946*8b26181fSAndroid Build Coastguard Worker  * a TCP data connection; control connection is always TCP-based.
947*8b26181fSAndroid Build Coastguard Worker  * A UDP connection is much lighter, but it does not guarantee that all
948*8b26181fSAndroid Build Coastguard Worker  * the captured packets arrive to the client workstation. Moreover,
949*8b26181fSAndroid Build Coastguard Worker  * it could be harmful in case of network congestion.
950*8b26181fSAndroid Build Coastguard Worker  * This flag is meaningless if the source is not a remote interface.
951*8b26181fSAndroid Build Coastguard Worker  * In that case, it is simply ignored.
952*8b26181fSAndroid Build Coastguard Worker  */
953*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPENFLAG_DATATX_UDP		0x00000002
954*8b26181fSAndroid Build Coastguard Worker 
955*8b26181fSAndroid Build Coastguard Worker /*
956*8b26181fSAndroid Build Coastguard Worker  * Specifies whether the remote probe will capture its own generated
957*8b26181fSAndroid Build Coastguard Worker  * traffic.
958*8b26181fSAndroid Build Coastguard Worker  *
959*8b26181fSAndroid Build Coastguard Worker  * In case the remote probe uses the same interface to capture traffic
960*8b26181fSAndroid Build Coastguard Worker  * and to send data back to the caller, the captured traffic includes
961*8b26181fSAndroid Build Coastguard Worker  * the RPCAP traffic as well.  If this flag is turned on, the RPCAP
962*8b26181fSAndroid Build Coastguard Worker  * traffic is excluded from the capture, so that the trace returned
963*8b26181fSAndroid Build Coastguard Worker  * back to the collector is does not include this traffic.
964*8b26181fSAndroid Build Coastguard Worker  *
965*8b26181fSAndroid Build Coastguard Worker  * Has no effect on local interfaces or savefiles.
966*8b26181fSAndroid Build Coastguard Worker  */
967*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPENFLAG_NOCAPTURE_RPCAP		0x00000004
968*8b26181fSAndroid Build Coastguard Worker 
969*8b26181fSAndroid Build Coastguard Worker /*
970*8b26181fSAndroid Build Coastguard Worker  * Specifies whether the local adapter will capture its own generated traffic.
971*8b26181fSAndroid Build Coastguard Worker  *
972*8b26181fSAndroid Build Coastguard Worker  * This flag tells the underlying capture driver to drop the packets
973*8b26181fSAndroid Build Coastguard Worker  * that were sent by itself.  This is useful when building applications
974*8b26181fSAndroid Build Coastguard Worker  * such as bridges that should ignore the traffic they just sent.
975*8b26181fSAndroid Build Coastguard Worker  *
976*8b26181fSAndroid Build Coastguard Worker  * Supported only on Windows.
977*8b26181fSAndroid Build Coastguard Worker  */
978*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPENFLAG_NOCAPTURE_LOCAL		0x00000008
979*8b26181fSAndroid Build Coastguard Worker 
980*8b26181fSAndroid Build Coastguard Worker /*
981*8b26181fSAndroid Build Coastguard Worker  * This flag configures the adapter for maximum responsiveness.
982*8b26181fSAndroid Build Coastguard Worker  *
983*8b26181fSAndroid Build Coastguard Worker  * In presence of a large value for nbytes, WinPcap waits for the arrival
984*8b26181fSAndroid Build Coastguard Worker  * of several packets before copying the data to the user. This guarantees
985*8b26181fSAndroid Build Coastguard Worker  * a low number of system calls, i.e. lower processor usage, i.e. better
986*8b26181fSAndroid Build Coastguard Worker  * performance, which is good for applications like sniffers. If the user
987*8b26181fSAndroid Build Coastguard Worker  * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will
988*8b26181fSAndroid Build Coastguard Worker  * copy the packets as soon as the application is ready to receive them.
989*8b26181fSAndroid Build Coastguard Worker  * This is suggested for real time applications (such as, for example,
990*8b26181fSAndroid Build Coastguard Worker  * a bridge) that need the best responsiveness.
991*8b26181fSAndroid Build Coastguard Worker  *
992*8b26181fSAndroid Build Coastguard Worker  * The equivalent with pcap_create()/pcap_activate() is "immediate mode".
993*8b26181fSAndroid Build Coastguard Worker  */
994*8b26181fSAndroid Build Coastguard Worker #define PCAP_OPENFLAG_MAX_RESPONSIVENESS	0x00000010
995*8b26181fSAndroid Build Coastguard Worker 
996*8b26181fSAndroid Build Coastguard Worker /*
997*8b26181fSAndroid Build Coastguard Worker  * Remote authentication methods.
998*8b26181fSAndroid Build Coastguard Worker  * These are used in the 'type' member of the pcap_rmtauth structure.
999*8b26181fSAndroid Build Coastguard Worker  */
1000*8b26181fSAndroid Build Coastguard Worker 
1001*8b26181fSAndroid Build Coastguard Worker /*
1002*8b26181fSAndroid Build Coastguard Worker  * NULL authentication.
1003*8b26181fSAndroid Build Coastguard Worker  *
1004*8b26181fSAndroid Build Coastguard Worker  * The 'NULL' authentication has to be equal to 'zero', so that old
1005*8b26181fSAndroid Build Coastguard Worker  * applications can just put every field of struct pcap_rmtauth to zero,
1006*8b26181fSAndroid Build Coastguard Worker  * and it does work.
1007*8b26181fSAndroid Build Coastguard Worker  */
1008*8b26181fSAndroid Build Coastguard Worker #define RPCAP_RMTAUTH_NULL 0
1009*8b26181fSAndroid Build Coastguard Worker /*
1010*8b26181fSAndroid Build Coastguard Worker  * Username/password authentication.
1011*8b26181fSAndroid Build Coastguard Worker  *
1012*8b26181fSAndroid Build Coastguard Worker  * With this type of authentication, the RPCAP protocol will use the username/
1013*8b26181fSAndroid Build Coastguard Worker  * password provided to authenticate the user on the remote machine. If the
1014*8b26181fSAndroid Build Coastguard Worker  * authentication is successful (and the user has the right to open network
1015*8b26181fSAndroid Build Coastguard Worker  * devices) the RPCAP connection will continue; otherwise it will be dropped.
1016*8b26181fSAndroid Build Coastguard Worker  *
1017*8b26181fSAndroid Build Coastguard Worker  * *******NOTE********: unless TLS is being used, the username and password
1018*8b26181fSAndroid Build Coastguard Worker  * are sent over the network to the capture server *IN CLEAR TEXT*.  Don't
1019*8b26181fSAndroid Build Coastguard Worker  * use this, without TLS (i.e., with rpcap:// rather than rpcaps://) on
1020*8b26181fSAndroid Build Coastguard Worker  * a network that you don't completely control!  (And be *really* careful
1021*8b26181fSAndroid Build Coastguard Worker  * in your definition of "completely"!)
1022*8b26181fSAndroid Build Coastguard Worker  */
1023*8b26181fSAndroid Build Coastguard Worker #define RPCAP_RMTAUTH_PWD 1
1024*8b26181fSAndroid Build Coastguard Worker 
1025*8b26181fSAndroid Build Coastguard Worker /*
1026*8b26181fSAndroid Build Coastguard Worker  * This structure keeps the information needed to authenticate the user
1027*8b26181fSAndroid Build Coastguard Worker  * on a remote machine.
1028*8b26181fSAndroid Build Coastguard Worker  *
1029*8b26181fSAndroid Build Coastguard Worker  * The remote machine can either grant or refuse the access according
1030*8b26181fSAndroid Build Coastguard Worker  * to the information provided.
1031*8b26181fSAndroid Build Coastguard Worker  * In case the NULL authentication is required, both 'username' and
1032*8b26181fSAndroid Build Coastguard Worker  * 'password' can be NULL pointers.
1033*8b26181fSAndroid Build Coastguard Worker  *
1034*8b26181fSAndroid Build Coastguard Worker  * This structure is meaningless if the source is not a remote interface;
1035*8b26181fSAndroid Build Coastguard Worker  * in that case, the functions which requires such a structure can accept
1036*8b26181fSAndroid Build Coastguard Worker  * a NULL pointer as well.
1037*8b26181fSAndroid Build Coastguard Worker  */
1038*8b26181fSAndroid Build Coastguard Worker struct pcap_rmtauth
1039*8b26181fSAndroid Build Coastguard Worker {
1040*8b26181fSAndroid Build Coastguard Worker 	/*
1041*8b26181fSAndroid Build Coastguard Worker 	 * \brief Type of the authentication required.
1042*8b26181fSAndroid Build Coastguard Worker 	 *
1043*8b26181fSAndroid Build Coastguard Worker 	 * In order to provide maximum flexibility, we can support different types
1044*8b26181fSAndroid Build Coastguard Worker 	 * of authentication based on the value of this 'type' variable. The currently
1045*8b26181fSAndroid Build Coastguard Worker 	 * supported authentication methods are defined into the
1046*8b26181fSAndroid Build Coastguard Worker 	 * \link remote_auth_methods Remote Authentication Methods Section\endlink.
1047*8b26181fSAndroid Build Coastguard Worker 	 */
1048*8b26181fSAndroid Build Coastguard Worker 	int type;
1049*8b26181fSAndroid Build Coastguard Worker 	/*
1050*8b26181fSAndroid Build Coastguard Worker 	 * \brief Zero-terminated string containing the username that has to be
1051*8b26181fSAndroid Build Coastguard Worker 	 * used on the remote machine for authentication.
1052*8b26181fSAndroid Build Coastguard Worker 	 *
1053*8b26181fSAndroid Build Coastguard Worker 	 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
1054*8b26181fSAndroid Build Coastguard Worker 	 * and it can be NULL.
1055*8b26181fSAndroid Build Coastguard Worker 	 */
1056*8b26181fSAndroid Build Coastguard Worker 	char *username;
1057*8b26181fSAndroid Build Coastguard Worker 	/*
1058*8b26181fSAndroid Build Coastguard Worker 	 * \brief Zero-terminated string containing the password that has to be
1059*8b26181fSAndroid Build Coastguard Worker 	 * used on the remote machine for authentication.
1060*8b26181fSAndroid Build Coastguard Worker 	 *
1061*8b26181fSAndroid Build Coastguard Worker 	 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
1062*8b26181fSAndroid Build Coastguard Worker 	 * and it can be NULL.
1063*8b26181fSAndroid Build Coastguard Worker 	 */
1064*8b26181fSAndroid Build Coastguard Worker 	char *password;
1065*8b26181fSAndroid Build Coastguard Worker };
1066*8b26181fSAndroid Build Coastguard Worker 
1067*8b26181fSAndroid Build Coastguard Worker /*
1068*8b26181fSAndroid Build Coastguard Worker  * This routine can open a savefile, a local device, or a device on
1069*8b26181fSAndroid Build Coastguard Worker  * a remote machine running an RPCAP server.
1070*8b26181fSAndroid Build Coastguard Worker  *
1071*8b26181fSAndroid Build Coastguard Worker  * For opening a savefile, the pcap_open_offline routines can be used,
1072*8b26181fSAndroid Build Coastguard Worker  * and will work just as well; code using them will work on more
1073*8b26181fSAndroid Build Coastguard Worker  * platforms than code using pcap_open() to open savefiles.
1074*8b26181fSAndroid Build Coastguard Worker  *
1075*8b26181fSAndroid Build Coastguard Worker  * For opening a local device, pcap_open_live() can be used; it supports
1076*8b26181fSAndroid Build Coastguard Worker  * most of the capabilities that pcap_open() supports, and code using it
1077*8b26181fSAndroid Build Coastguard Worker  * will work on more platforms than code using pcap_open().  pcap_create()
1078*8b26181fSAndroid Build Coastguard Worker  * and pcap_activate() can also be used; they support all capabilities
1079*8b26181fSAndroid Build Coastguard Worker  * that pcap_open() supports, except for the Windows-only
1080*8b26181fSAndroid Build Coastguard Worker  * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities.
1081*8b26181fSAndroid Build Coastguard Worker  *
1082*8b26181fSAndroid Build Coastguard Worker  * For opening a remote capture, pcap_open() is currently the only
1083*8b26181fSAndroid Build Coastguard Worker  * API available.
1084*8b26181fSAndroid Build Coastguard Worker  */
1085*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1086*8b26181fSAndroid Build Coastguard Worker PCAP_API pcap_t	*pcap_open(const char *source, int snaplen, int flags,
1087*8b26181fSAndroid Build Coastguard Worker 	    int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
1088*8b26181fSAndroid Build Coastguard Worker 
1089*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1090*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_createsrcstr(char *source, int type, const char *host,
1091*8b26181fSAndroid Build Coastguard Worker 	    const char *port, const char *name, char *errbuf);
1092*8b26181fSAndroid Build Coastguard Worker 
1093*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1094*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_parsesrcstr(const char *source, int *type, char *host,
1095*8b26181fSAndroid Build Coastguard Worker 	    char *port, char *name, char *errbuf);
1096*8b26181fSAndroid Build Coastguard Worker 
1097*8b26181fSAndroid Build Coastguard Worker /*
1098*8b26181fSAndroid Build Coastguard Worker  * This routine can scan a directory for savefiles, list local capture
1099*8b26181fSAndroid Build Coastguard Worker  * devices, or list capture devices on a remote machine running an RPCAP
1100*8b26181fSAndroid Build Coastguard Worker  * server.
1101*8b26181fSAndroid Build Coastguard Worker  *
1102*8b26181fSAndroid Build Coastguard Worker  * For scanning for savefiles, it can be used on both UN*X systems and
1103*8b26181fSAndroid Build Coastguard Worker  * Windows systems; for each directory entry it sees, it tries to open
1104*8b26181fSAndroid Build Coastguard Worker  * the file as a savefile using pcap_open_offline(), and only includes
1105*8b26181fSAndroid Build Coastguard Worker  * it in the list of files if the open succeeds, so it filters out
1106*8b26181fSAndroid Build Coastguard Worker  * files for which the user doesn't have read permission, as well as
1107*8b26181fSAndroid Build Coastguard Worker  * files that aren't valid savefiles readable by libpcap.
1108*8b26181fSAndroid Build Coastguard Worker  *
1109*8b26181fSAndroid Build Coastguard Worker  * For listing local capture devices, it's just a wrapper around
1110*8b26181fSAndroid Build Coastguard Worker  * pcap_findalldevs(); code using pcap_findalldevs() will work on more
1111*8b26181fSAndroid Build Coastguard Worker  * platforms than code using pcap_findalldevs_ex().
1112*8b26181fSAndroid Build Coastguard Worker  *
1113*8b26181fSAndroid Build Coastguard Worker  * For listing remote capture devices, pcap_findalldevs_ex() is currently
1114*8b26181fSAndroid Build Coastguard Worker  * the only API available.
1115*8b26181fSAndroid Build Coastguard Worker  */
1116*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1117*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_findalldevs_ex(const char *source,
1118*8b26181fSAndroid Build Coastguard Worker 	    struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
1119*8b26181fSAndroid Build Coastguard Worker 
1120*8b26181fSAndroid Build Coastguard Worker /*
1121*8b26181fSAndroid Build Coastguard Worker  * Sampling methods.
1122*8b26181fSAndroid Build Coastguard Worker  *
1123*8b26181fSAndroid Build Coastguard Worker  * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex()
1124*8b26181fSAndroid Build Coastguard Worker  * to see only a sample of packets, rather than all packets.
1125*8b26181fSAndroid Build Coastguard Worker  *
1126*8b26181fSAndroid Build Coastguard Worker  * Currently, they work only on Windows local captures.
1127*8b26181fSAndroid Build Coastguard Worker  */
1128*8b26181fSAndroid Build Coastguard Worker 
1129*8b26181fSAndroid Build Coastguard Worker /*
1130*8b26181fSAndroid Build Coastguard Worker  * Specifies that no sampling is to be done on the current capture.
1131*8b26181fSAndroid Build Coastguard Worker  *
1132*8b26181fSAndroid Build Coastguard Worker  * In this case, no sampling algorithms are applied to the current capture.
1133*8b26181fSAndroid Build Coastguard Worker  */
1134*8b26181fSAndroid Build Coastguard Worker #define PCAP_SAMP_NOSAMP	0
1135*8b26181fSAndroid Build Coastguard Worker 
1136*8b26181fSAndroid Build Coastguard Worker /*
1137*8b26181fSAndroid Build Coastguard Worker  * Specifies that only 1 out of N packets must be returned to the user.
1138*8b26181fSAndroid Build Coastguard Worker  *
1139*8b26181fSAndroid Build Coastguard Worker  * In this case, the 'value' field of the 'pcap_samp' structure indicates the
1140*8b26181fSAndroid Build Coastguard Worker  * number of packets (minus 1) that must be discarded before one packet got
1141*8b26181fSAndroid Build Coastguard Worker  * accepted.
1142*8b26181fSAndroid Build Coastguard Worker  * In other words, if 'value = 10', the first packet is returned to the
1143*8b26181fSAndroid Build Coastguard Worker  * caller, while the following 9 are discarded.
1144*8b26181fSAndroid Build Coastguard Worker  */
1145*8b26181fSAndroid Build Coastguard Worker #define PCAP_SAMP_1_EVERY_N	1
1146*8b26181fSAndroid Build Coastguard Worker 
1147*8b26181fSAndroid Build Coastguard Worker /*
1148*8b26181fSAndroid Build Coastguard Worker  * Specifies that we have to return 1 packet every N milliseconds.
1149*8b26181fSAndroid Build Coastguard Worker  *
1150*8b26181fSAndroid Build Coastguard Worker  * In this case, the 'value' field of the 'pcap_samp' structure indicates
1151*8b26181fSAndroid Build Coastguard Worker  * the 'waiting time' in milliseconds before one packet got accepted.
1152*8b26181fSAndroid Build Coastguard Worker  * In other words, if 'value = 10', the first packet is returned to the
1153*8b26181fSAndroid Build Coastguard Worker  * caller; the next returned one will be the first packet that arrives
1154*8b26181fSAndroid Build Coastguard Worker  * when 10ms have elapsed.
1155*8b26181fSAndroid Build Coastguard Worker  */
1156*8b26181fSAndroid Build Coastguard Worker #define PCAP_SAMP_FIRST_AFTER_N_MS 2
1157*8b26181fSAndroid Build Coastguard Worker 
1158*8b26181fSAndroid Build Coastguard Worker /*
1159*8b26181fSAndroid Build Coastguard Worker  * This structure defines the information related to sampling.
1160*8b26181fSAndroid Build Coastguard Worker  *
1161*8b26181fSAndroid Build Coastguard Worker  * In case the sampling is requested, the capturing device should read
1162*8b26181fSAndroid Build Coastguard Worker  * only a subset of the packets coming from the source. The returned packets
1163*8b26181fSAndroid Build Coastguard Worker  * depend on the sampling parameters.
1164*8b26181fSAndroid Build Coastguard Worker  *
1165*8b26181fSAndroid Build Coastguard Worker  * WARNING: The sampling process is applied *after* the filtering process.
1166*8b26181fSAndroid Build Coastguard Worker  * In other words, packets are filtered first, then the sampling process
1167*8b26181fSAndroid Build Coastguard Worker  * selects a subset of the 'filtered' packets and it returns them to the
1168*8b26181fSAndroid Build Coastguard Worker  * caller.
1169*8b26181fSAndroid Build Coastguard Worker  */
1170*8b26181fSAndroid Build Coastguard Worker struct pcap_samp
1171*8b26181fSAndroid Build Coastguard Worker {
1172*8b26181fSAndroid Build Coastguard Worker 	/*
1173*8b26181fSAndroid Build Coastguard Worker 	 * Method used for sampling; see above.
1174*8b26181fSAndroid Build Coastguard Worker 	 */
1175*8b26181fSAndroid Build Coastguard Worker 	int method;
1176*8b26181fSAndroid Build Coastguard Worker 
1177*8b26181fSAndroid Build Coastguard Worker 	/*
1178*8b26181fSAndroid Build Coastguard Worker 	 * This value depends on the sampling method defined.
1179*8b26181fSAndroid Build Coastguard Worker 	 * For its meaning, see above.
1180*8b26181fSAndroid Build Coastguard Worker 	 */
1181*8b26181fSAndroid Build Coastguard Worker 	int value;
1182*8b26181fSAndroid Build Coastguard Worker };
1183*8b26181fSAndroid Build Coastguard Worker 
1184*8b26181fSAndroid Build Coastguard Worker /*
1185*8b26181fSAndroid Build Coastguard Worker  * New functions.
1186*8b26181fSAndroid Build Coastguard Worker  */
1187*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1188*8b26181fSAndroid Build Coastguard Worker PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
1189*8b26181fSAndroid Build Coastguard Worker 
1190*8b26181fSAndroid Build Coastguard Worker /*
1191*8b26181fSAndroid Build Coastguard Worker  * RPCAP active mode.
1192*8b26181fSAndroid Build Coastguard Worker  */
1193*8b26181fSAndroid Build Coastguard Worker 
1194*8b26181fSAndroid Build Coastguard Worker /* Maximum length of an host name (needed for the RPCAP active mode) */
1195*8b26181fSAndroid Build Coastguard Worker #define RPCAP_HOSTLIST_SIZE 1024
1196*8b26181fSAndroid Build Coastguard Worker 
1197*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1198*8b26181fSAndroid Build Coastguard Worker PCAP_API SOCKET	pcap_remoteact_accept(const char *address, const char *port,
1199*8b26181fSAndroid Build Coastguard Worker 	    const char *hostlist, char *connectinghost,
1200*8b26181fSAndroid Build Coastguard Worker 	    struct pcap_rmtauth *auth, char *errbuf);
1201*8b26181fSAndroid Build Coastguard Worker 
1202*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_10
1203*8b26181fSAndroid Build Coastguard Worker PCAP_API SOCKET	pcap_remoteact_accept_ex(const char *address, const char *port,
1204*8b26181fSAndroid Build Coastguard Worker 	    const char *hostlist, char *connectinghost,
1205*8b26181fSAndroid Build Coastguard Worker 	    struct pcap_rmtauth *auth, int uses_ssl, char *errbuf);
1206*8b26181fSAndroid Build Coastguard Worker 
1207*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1208*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_remoteact_list(char *hostlist, char sep, int size,
1209*8b26181fSAndroid Build Coastguard Worker 	    char *errbuf);
1210*8b26181fSAndroid Build Coastguard Worker 
1211*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1212*8b26181fSAndroid Build Coastguard Worker PCAP_API int	pcap_remoteact_close(const char *host, char *errbuf);
1213*8b26181fSAndroid Build Coastguard Worker 
1214*8b26181fSAndroid Build Coastguard Worker PCAP_AVAILABLE_1_9
1215*8b26181fSAndroid Build Coastguard Worker PCAP_API void	pcap_remoteact_cleanup(void);
1216*8b26181fSAndroid Build Coastguard Worker 
1217*8b26181fSAndroid Build Coastguard Worker #ifdef __cplusplus
1218*8b26181fSAndroid Build Coastguard Worker }
1219*8b26181fSAndroid Build Coastguard Worker #endif
1220*8b26181fSAndroid Build Coastguard Worker 
1221*8b26181fSAndroid Build Coastguard Worker #endif /* lib_pcap_pcap_h */
1222