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