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