]> The Tcpdump Group git mirrors - libpcap/blob - pcap/pcap.h
CI: Call print_so_deps() on rpcapd in remote enabled build
[libpcap] / pcap / pcap.h
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 * including 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 #else /* UN*X */
123 #include <sys/types.h> /* u_int, u_char etc. */
124 #include <sys/time.h>
125 #endif /* _WIN32/UN*X */
126
127 #include <pcap/socket.h> /* for PCAP_SOCKET, as the active-mode rpcap APIs use it */
128
129 #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
130 #include <pcap/bpf.h>
131 #endif
132
133 #include <stdio.h>
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138
139 /*
140 * Version number of the current version of the pcap file format.
141 *
142 * NOTE: this is *NOT* the version number of the libpcap library.
143 * To fetch the version information for the version of libpcap
144 * you're using, use pcap_lib_version().
145 */
146 #define PCAP_VERSION_MAJOR 2
147 #define PCAP_VERSION_MINOR 4
148
149 #define PCAP_ERRBUF_SIZE 256
150
151 /*
152 * Compatibility for systems that have a bpf.h that
153 * predates the bpf typedefs for 64-bit support.
154 */
155 #if ! defined(BPF_RELEASE) || BPF_RELEASE < 199406
156 typedef int bpf_int32;
157 typedef u_int bpf_u_int32;
158 #endif
159
160 typedef struct pcap pcap_t;
161 typedef struct pcap_dumper pcap_dumper_t;
162 typedef struct pcap_if pcap_if_t;
163 typedef struct pcap_addr pcap_addr_t;
164
165 /*
166 * The first record in the file contains saved values for some
167 * of the flags used in the printout phases of tcpdump.
168 * Many fields here are 32 bit ints so compilers won't insert unwanted
169 * padding; these files need to be interchangeable across architectures.
170 * Documentation: https://www.tcpdump.org/manpages/pcap-savefile.5.txt.
171 *
172 * Do not change the layout of this structure, in any way (this includes
173 * changes that only affect the length of fields in this structure).
174 *
175 * Also, do not change the interpretation of any of the members of this
176 * structure, in any way (this includes using values other than
177 * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
178 * field).
179 *
180 * Instead:
181 *
182 * introduce a new structure for the new format, if the layout
183 * of the structure changed;
184 *
185 * send mail to "tcpdump-workers@lists.tcpdump.org", requesting
186 * a new magic number for your new capture file format, and, when
187 * you get the new magic number, put it in "savefile.c";
188 *
189 * use that magic number for save files with the changed file
190 * header;
191 *
192 * make the code in "savefile.c" capable of reading files with
193 * the old file header as well as files with the new file header
194 * (using the magic number to determine the header format).
195 *
196 * Then supply the changes by forking the branch at
197 *
198 * https://github.com/the-tcpdump-group/libpcap/tree/master
199 *
200 * and issuing a pull request, so that future versions of libpcap and
201 * programs that use it (such as tcpdump) will be able to read your new
202 * capture file format.
203 */
204 struct pcap_file_header {
205 bpf_u_int32 magic;
206 u_short version_major;
207 u_short version_minor;
208 bpf_int32 thiszone; /* not used - SHOULD be filled with 0 */
209 bpf_u_int32 sigfigs; /* not used - SHOULD be filled with 0 */
210 bpf_u_int32 snaplen; /* max length saved portion of each pkt */
211 bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
212 };
213
214 /*
215 * Subfields of the field containing the link-layer header type.
216 *
217 * Link-layer header types are assigned for both pcap and
218 * pcapng, and the same value must work with both. In pcapng,
219 * the link-layer header type field in an Interface Description
220 * Block is 16 bits, so only the bottommost 16 bits of the
221 * link-layer header type in a pcap file can be used for the
222 * header type value.
223 *
224 * In libpcap, the upper 16 bits, from the top down, are divided into:
225 *
226 * A 4-bit "FCS length" field, to allow the FCS length to
227 * be specified, just as it can be specified in the if_fcslen
228 * field of the pcapng IDB. The field is in units of 16 bits,
229 * i.e. 1 means 16 bits of FCS, 2 means 32 bits of FCS, etc..
230 *
231 * A reserved bit, which must be zero.
232 *
233 * An "FCS length present" flag; if 0, the "FCS length" field
234 * should be ignored, and if 1, the "FCS length" field should
235 * be used.
236 *
237 * 10 reserved bits, which must be zero. They were originally
238 * intended to be used as a "class" field, allowing additional
239 * classes of link-layer types to be defined, with a class value
240 * of 0 indicating that the link-layer type is a LINKTYPE_ value.
241 * A value of 0x224 was, at one point, used by NetBSD to define
242 * "raw" packet types, with the lower 16 bits containing a
243 * NetBSD AF_ value; see
244 *
245 * https://marc.info/?l=tcpdump-workers&m=98296750229149&w=2
246 *
247 * It's unknown whether those were ever used in capture files,
248 * or if the intent was just to use it as a link-layer type
249 * for BPF programs; NetBSD's libpcap used to support them in
250 * the BPF code generator, but it no longer does so. If it
251 * was ever used in capture files, or if classes other than
252 * "LINKTYPE_ value" are ever useful in capture files, we could
253 * re-enable this, and use the reserved 16 bits following the
254 * link-layer type in pcapng files to hold the class information
255 * there. (Note, BTW, that LINKTYPE_RAW/DLT_RAW is now being
256 * interpreted by libpcap, tcpdump, and Wireshark as "raw IP",
257 * including both IPv4 and IPv6, with the version number in the
258 * header being checked to see which it is, not just "raw IPv4";
259 * there are LINKTYPE_IPV4/DLT_IPV4 and LINKTYPE_IPV6/DLT_IPV6
260 * values if "these are IPv{4,6} and only IPv{4,6} packets"
261 * types are needed.)
262 *
263 * Or we might be able to use it for other purposes.
264 */
265 #define LT_LINKTYPE(x) ((x) & 0x0000FFFF)
266 #define LT_LINKTYPE_EXT(x) ((x) & 0xFFFF0000)
267 #define LT_RESERVED1(x) ((x) & 0x03FF0000)
268 #define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000)
269 #define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28)
270 #define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000)
271
272 typedef enum {
273 PCAP_D_INOUT = 0,
274 PCAP_D_IN,
275 PCAP_D_OUT
276 } pcap_direction_t;
277
278 /*
279 * Generic per-packet information, as supplied by libpcap.
280 *
281 * The time stamp can and should be a "struct timeval", regardless of
282 * whether your system supports 32-bit tv_sec in "struct timeval",
283 * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
284 * and 64-bit applications. The on-disk format of savefiles uses 32-bit
285 * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit
286 * and 64-bit versions of libpcap, even if they're on the same platform,
287 * should supply the appropriate version of "struct timeval", even if
288 * that's not what the underlying packet capture mechanism supplies.
289 *
290 * caplen is the number of packet bytes available in the packet.
291 *
292 * len is the number of bytes that would have been available if
293 * the capture process had not discarded data at the end of the
294 * packet, either because a snapshot length less than the packet
295 * size was provided or because the mechanism used to capture
296 * the packet imposed a limit on the amount of packet data
297 * that is provided.
298 */
299 struct pcap_pkthdr {
300 struct timeval ts; /* time stamp */
301 bpf_u_int32 caplen; /* length of portion present in data */
302 bpf_u_int32 len; /* length of this packet prior to any slicing */
303 };
304
305 /*
306 * As returned by the pcap_stats()
307 */
308 struct pcap_stat {
309 u_int ps_recv; /* number of packets received */
310 u_int ps_drop; /* number of packets dropped */
311 u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */
312 #ifdef _WIN32
313 u_int ps_capt; /* number of packets that reach the application */
314 u_int ps_sent; /* number of packets sent by the server on the network */
315 u_int ps_netdrop; /* number of packets lost on the network */
316 #endif /* _WIN32 */
317 };
318
319 /*
320 * Item in a list of interfaces.
321 */
322 struct pcap_if {
323 struct pcap_if *next;
324 char *name; /* name to hand to "pcap_open_live()" */
325 char *description; /* textual description of interface, or NULL */
326 struct pcap_addr *addresses;
327 bpf_u_int32 flags; /* PCAP_IF_ interface flags */
328 };
329
330 #define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
331 #define PCAP_IF_UP 0x00000002 /* interface is up */
332 #define PCAP_IF_RUNNING 0x00000004 /* interface is running */
333 #define PCAP_IF_WIRELESS 0x00000008 /* interface is wireless (*NOT* necessarily Wi-Fi!) */
334 #define PCAP_IF_CONNECTION_STATUS 0x00000030 /* connection status: */
335 #define PCAP_IF_CONNECTION_STATUS_UNKNOWN 0x00000000 /* unknown */
336 #define PCAP_IF_CONNECTION_STATUS_CONNECTED 0x00000010 /* connected */
337 #define PCAP_IF_CONNECTION_STATUS_DISCONNECTED 0x00000020 /* disconnected */
338 #define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE 0x00000030 /* not applicable */
339
340 /*
341 * Representation of an interface address.
342 */
343 struct pcap_addr {
344 struct pcap_addr *next;
345 struct sockaddr *addr; /* address */
346 struct sockaddr *netmask; /* netmask for that address */
347 struct sockaddr *broadaddr; /* broadcast address for that address */
348 struct sockaddr *dstaddr; /* P2P destination address for that address */
349 };
350
351 typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
352 const u_char *);
353
354 /*
355 * Error codes for the pcap API.
356 * These will all be negative, so you can check for the success or
357 * failure of a call that returns these codes by checking for a
358 * negative value.
359 */
360 #define PCAP_ERROR -1 /* generic error code */
361 #define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */
362 #define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */
363 #define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */
364 #define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */
365 #define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */
366 #define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */
367 #define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */
368 #define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
369 #define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */
370 #define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */
371 #define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */
372 #define PCAP_ERROR_CAPTURE_NOTSUP -13 /* capture mechanism not available */
373
374 /*
375 * Warning codes for the pcap API.
376 * These will all be positive and non-zero, so they won't look like
377 * errors.
378 */
379 #define PCAP_WARNING 1 /* generic warning code */
380 #define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */
381 #define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */
382
383 /*
384 * Value to pass to pcap_compile() as the netmask if you don't know what
385 * the netmask is.
386 */
387 #define PCAP_NETMASK_UNKNOWN 0xffffffff
388
389 /*
390 * Initialize pcap. If this isn't called, pcap is initialized to
391 * a mode source-compatible and binary-compatible with older versions
392 * that lack this routine.
393 */
394
395 /*
396 * Initialization options.
397 * All bits not listed here are reserved for expansion.
398 *
399 * On UNIX-like systems, the local character encoding is assumed to be
400 * UTF-8, so no character encoding transformations are done.
401 *
402 * On Windows, the local character encoding is the local ANSI code page.
403 */
404 #define PCAP_CHAR_ENC_LOCAL 0x00000000U /* strings are in the local character encoding */
405 #define PCAP_CHAR_ENC_UTF_8 0x00000001U /* strings are in UTF-8 */
406 #define PCAP_MMAP_32BIT 0x00000002U /* map packet buffers with 32-bit addresses */
407
408 PCAP_AVAILABLE_1_10
409 PCAP_API int pcap_init(unsigned int, char *)
410 PCAP_NONNULL(2) PCAP_WARN_UNUSED_RESULT;
411
412 /*
413 * We're deprecating pcap_lookupdev() for various reasons (not
414 * thread-safe, can behave weirdly with WinPcap). Callers
415 * should use pcap_findalldevs() and use the first device.
416 */
417 PCAP_AVAILABLE_0_4
418 PCAP_DEPRECATED("use 'pcap_findalldevs' and use the first device")
419 PCAP_API char *pcap_lookupdev(char *);
420
421 PCAP_AVAILABLE_0_4
422 PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *,
423 char *) PCAP_NONNULL(4) PCAP_WARN_UNUSED_RESULT;
424
425 PCAP_AVAILABLE_1_0
426 PCAP_API pcap_t *pcap_create(const char *, char *) PCAP_NONNULL(2);
427
428 PCAP_AVAILABLE_1_0
429 PCAP_API int pcap_set_snaplen(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
430
431 PCAP_AVAILABLE_1_0
432 PCAP_API int pcap_set_promisc(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
433
434 PCAP_AVAILABLE_1_0
435 PCAP_API int pcap_can_set_rfmon(pcap_t *);
436
437 PCAP_AVAILABLE_1_0
438 PCAP_API int pcap_set_rfmon(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
439
440 PCAP_AVAILABLE_1_0
441 PCAP_API int pcap_set_timeout(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
442
443 PCAP_AVAILABLE_1_2
444 PCAP_API int pcap_set_tstamp_type(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
445
446 PCAP_AVAILABLE_1_5
447 PCAP_API int pcap_set_immediate_mode(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
448
449 PCAP_AVAILABLE_1_0
450 PCAP_API int pcap_set_buffer_size(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
451
452 PCAP_AVAILABLE_1_5
453 PCAP_API int pcap_set_tstamp_precision(pcap_t *, int)
454 PCAP_WARN_UNUSED_RESULT;
455
456 PCAP_AVAILABLE_1_5
457 PCAP_API int pcap_get_tstamp_precision(pcap_t *) PCAP_WARN_UNUSED_RESULT;
458
459 PCAP_AVAILABLE_1_0
460 PCAP_API int pcap_activate(pcap_t *) PCAP_WARN_UNUSED_RESULT;
461
462 PCAP_AVAILABLE_1_2
463 PCAP_API int pcap_list_tstamp_types(pcap_t *, int **);
464
465 PCAP_AVAILABLE_1_2
466 PCAP_API void pcap_free_tstamp_types(int *);
467
468 PCAP_AVAILABLE_1_2
469 PCAP_API int pcap_tstamp_type_name_to_val(const char *);
470
471 PCAP_AVAILABLE_1_2
472 PCAP_API const char *pcap_tstamp_type_val_to_name(int);
473
474 PCAP_AVAILABLE_1_2
475 PCAP_API const char *pcap_tstamp_type_val_to_description(int);
476
477 #ifdef __linux__
478 PCAP_AVAILABLE_1_9
479 PCAP_API int pcap_set_protocol_linux(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
480 #endif
481
482 /*
483 * Time stamp types.
484 * Not all systems and interfaces will necessarily support all of these.
485 *
486 * A system that supports PCAP_TSTAMP_HOST is offering time stamps
487 * provided by the host machine, rather than by the capture device,
488 * but not committing to any characteristics of the time stamp.
489 *
490 * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine,
491 * that's low-precision but relatively cheap to fetch; it's normally done
492 * using the system clock, so it's normally synchronized with times you'd
493 * fetch from system calls.
494 *
495 * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine,
496 * that's high-precision; it might be more expensive to fetch. It is
497 * synchronized with the system clock.
498 *
499 * PCAP_TSTAMP_HOST_HIPREC_UNSYNCED is a time stamp, provided by the host
500 * machine, that's high-precision; it might be more expensive to fetch.
501 * It is not synchronized with the system clock, and might have
502 * problems with time stamps for packets received on different CPUs,
503 * depending on the platform. It might be more likely to be strictly
504 * monotonic than PCAP_TSTAMP_HOST_HIPREC.
505 *
506 * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the
507 * capture device; it's synchronized with the system clock.
508 *
509 * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by
510 * the capture device; it's not synchronized with the system clock.
511 *
512 * Note that time stamps synchronized with the system clock can go
513 * backwards, as the system clock can go backwards. If a clock is
514 * not in sync with the system clock, that could be because the
515 * system clock isn't keeping accurate time, because the other
516 * clock isn't keeping accurate time, or both.
517 *
518 * Note that host-provided time stamps generally correspond to the
519 * time when the time-stamping code sees the packet; this could
520 * be some unknown amount of time after the first or last bit of
521 * the packet is received by the network adapter, due to batching
522 * of interrupts for packet arrival, queueing delays, etc..
523 */
524 #define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */
525 #define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision, synced with the system clock */
526 #define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision, synced with the system clock */
527 #define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */
528 #define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */
529 #define PCAP_TSTAMP_HOST_HIPREC_UNSYNCED 5 /* host-provided, high precision, not synced with the system clock */
530
531 /*
532 * Time stamp resolution types.
533 * Not all systems and interfaces will necessarily support all of these
534 * resolutions when doing live captures; all of them can be requested
535 * when reading a savefile.
536 */
537 #define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */
538 #define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */
539
540 PCAP_AVAILABLE_0_4
541 PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *)
542 PCAP_NONNULL(5);
543
544 PCAP_AVAILABLE_0_6
545 PCAP_API pcap_t *pcap_open_dead(int, int);
546
547 PCAP_AVAILABLE_1_5
548 PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
549
550 PCAP_AVAILABLE_1_5
551 PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int,
552 char *) PCAP_NONNULL(3);
553
554 PCAP_AVAILABLE_0_4
555 PCAP_API pcap_t *pcap_open_offline(const char *, char *) PCAP_NONNULL(2);
556
557 #ifdef _WIN32
558 PCAP_AVAILABLE_1_5
559 PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int,
560 char *) PCAP_NONNULL(3);
561
562 PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *) PCAP_NONNULL(2);
563 /*
564 * If we're building libpcap, these are internal routines in savefile.c,
565 * so we must not define them as macros.
566 *
567 * If we're not building libpcap, given that the version of the C runtime
568 * with which libpcap was built might be different from the version
569 * of the C runtime with which an application using libpcap was built,
570 * and that a FILE structure may differ between the two versions of the
571 * C runtime, calls to _fileno() must use the version of _fileno() in
572 * the C runtime used to open the FILE *, not the version in the C
573 * runtime with which libpcap was built. (Maybe once the Universal CRT
574 * rules the world, this will cease to be a problem.)
575 */
576 #ifndef BUILDING_PCAP
577 #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
578 pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
579 #define pcap_fopen_offline(f,b) \
580 pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
581 #endif
582 #else /*_WIN32*/
583 PCAP_AVAILABLE_1_5
584 PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *,
585 u_int, char *) PCAP_NONNULL(3);
586
587 PCAP_AVAILABLE_0_9
588 PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *) PCAP_NONNULL(2);
589 #endif /*_WIN32*/
590
591 PCAP_AVAILABLE_0_4
592 PCAP_API void pcap_close(pcap_t *);
593
594 PCAP_AVAILABLE_0_4
595 PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *)
596 PCAP_WARN_UNUSED_RESULT;
597
598 PCAP_AVAILABLE_0_4
599 PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *)
600 PCAP_WARN_UNUSED_RESULT;
601
602 PCAP_AVAILABLE_0_4
603 PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
604
605 PCAP_AVAILABLE_0_8
606 PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
607
608 PCAP_AVAILABLE_0_8
609 PCAP_API void pcap_breakloop(pcap_t *);
610
611 PCAP_AVAILABLE_0_4
612 PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *)
613 PCAP_WARN_UNUSED_RESULT;
614
615 PCAP_AVAILABLE_0_4
616 PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *)
617 PCAP_WARN_UNUSED_RESULT;
618
619 PCAP_AVAILABLE_0_9
620 PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t)
621 PCAP_WARN_UNUSED_RESULT;
622
623 PCAP_AVAILABLE_0_7
624 PCAP_API int pcap_getnonblock(pcap_t *, char *);
625
626 PCAP_AVAILABLE_0_7
627 PCAP_API int pcap_setnonblock(pcap_t *, int, char *)
628 PCAP_WARN_UNUSED_RESULT;
629
630 PCAP_AVAILABLE_0_9
631 PCAP_API int pcap_inject(pcap_t *, const void *, size_t)
632 PCAP_WARN_UNUSED_RESULT;
633
634 PCAP_AVAILABLE_0_8
635 PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int)
636 PCAP_WARN_UNUSED_RESULT;
637
638 PCAP_AVAILABLE_1_0
639 PCAP_API const char *pcap_statustostr(int);
640
641 PCAP_AVAILABLE_0_4
642 PCAP_API const char *pcap_strerror(int);
643
644 PCAP_AVAILABLE_0_4
645 PCAP_API char *pcap_geterr(pcap_t *);
646
647 PCAP_AVAILABLE_0_4
648 PCAP_API void pcap_perror(pcap_t *, const char *);
649
650 PCAP_AVAILABLE_0_4
651 PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
652 bpf_u_int32) PCAP_WARN_UNUSED_RESULT;
653
654 PCAP_AVAILABLE_0_5
655 PCAP_DEPRECATED("use pcap_open_dead(), pcap_compile() and pcap_close()")
656 PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *,
657 const char *, int, bpf_u_int32) PCAP_WARN_UNUSED_RESULT;
658
659 /* XXX - this took two arguments in 0.4 and 0.5 */
660 PCAP_AVAILABLE_0_6
661 PCAP_API void pcap_freecode(struct bpf_program *);
662
663 PCAP_AVAILABLE_1_0
664 PCAP_API int pcap_offline_filter(const struct bpf_program *,
665 const struct pcap_pkthdr *, const u_char *);
666
667 PCAP_AVAILABLE_0_4
668 PCAP_API int pcap_datalink(pcap_t *);
669
670 PCAP_AVAILABLE_1_0
671 PCAP_API int pcap_datalink_ext(pcap_t *);
672
673 PCAP_AVAILABLE_0_8
674 PCAP_API int pcap_list_datalinks(pcap_t *, int **);
675
676 PCAP_AVAILABLE_0_8
677 PCAP_API int pcap_set_datalink(pcap_t *, int) PCAP_WARN_UNUSED_RESULT;
678
679 PCAP_AVAILABLE_0_8
680 PCAP_API void pcap_free_datalinks(int *);
681
682 PCAP_AVAILABLE_0_8
683 PCAP_API int pcap_datalink_name_to_val(const char *);
684
685 PCAP_AVAILABLE_0_8
686 PCAP_API const char *pcap_datalink_val_to_name(int);
687
688 PCAP_AVAILABLE_0_8
689 PCAP_API const char *pcap_datalink_val_to_description(int);
690
691 PCAP_AVAILABLE_1_9
692 PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
693
694 PCAP_AVAILABLE_0_4
695 PCAP_API int pcap_snapshot(pcap_t *);
696
697 PCAP_AVAILABLE_0_4
698 PCAP_API int pcap_is_swapped(pcap_t *);
699
700 PCAP_AVAILABLE_0_4
701 PCAP_API int pcap_major_version(pcap_t *);
702
703 PCAP_AVAILABLE_0_4
704 PCAP_API int pcap_minor_version(pcap_t *);
705
706 PCAP_AVAILABLE_1_9
707 PCAP_API int pcap_bufsize(pcap_t *);
708
709 /* XXX */
710 PCAP_AVAILABLE_0_4
711 PCAP_API FILE *pcap_file(pcap_t *);
712
713 #ifdef _WIN32
714 /*
715 * This probably shouldn't have been kept in WinPcap; most if not all
716 * UN*X code that used it won't work on Windows. We deprecate it; if
717 * anybody really needs access to whatever HANDLE may be associated
718 * with a pcap_t (there's no guarantee that there is one), we can add
719 * a Windows-only pcap_handle() API that returns the HANDLE.
720 */
721 PCAP_AVAILABLE_0_4
722 PCAP_DEPRECATED("request a 'pcap_handle' that returns a HANDLE if you need it")
723 PCAP_API int pcap_fileno(pcap_t *);
724 #else /* _WIN32 */
725 PCAP_AVAILABLE_0_4
726 PCAP_API int pcap_fileno(pcap_t *);
727 #endif /* _WIN32 */
728
729 #ifdef _WIN32
730 PCAP_API int pcap_wsockinit(void);
731 #endif
732
733 PCAP_AVAILABLE_0_4
734 PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
735
736 #ifdef _WIN32
737 PCAP_AVAILABLE_0_9
738 PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
739
740 /*
741 * If we're building libpcap, this is an internal routine in sf-pcap.c, so
742 * we must not define it as a macro.
743 *
744 * If we're not building libpcap, given that the version of the C runtime
745 * with which libpcap was built might be different from the version
746 * of the C runtime with which an application using libpcap was built,
747 * and that a FILE structure may differ between the two versions of the
748 * C runtime, calls to _fileno() must use the version of _fileno() in
749 * the C runtime used to open the FILE *, not the version in the C
750 * runtime with which libpcap was built. (Maybe once the Universal CRT
751 * rules the world, this will cease to be a problem.)
752 */
753 #ifndef BUILDING_PCAP
754 #define pcap_dump_fopen(p,f) \
755 pcap_dump_hopen(p, _get_osfhandle(_fileno(f)))
756 #endif
757 #else /*_WIN32*/
758 PCAP_AVAILABLE_0_9
759 PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
760 #endif /*_WIN32*/
761
762 PCAP_AVAILABLE_1_7
763 PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
764
765 PCAP_AVAILABLE_0_8
766 PCAP_API FILE *pcap_dump_file(pcap_dumper_t *);
767
768 PCAP_AVAILABLE_0_9
769 PCAP_API long pcap_dump_ftell(pcap_dumper_t *);
770
771 PCAP_AVAILABLE_1_9
772 PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *);
773
774 PCAP_AVAILABLE_0_8
775 PCAP_API int pcap_dump_flush(pcap_dumper_t *);
776
777 PCAP_AVAILABLE_0_4
778 PCAP_API void pcap_dump_close(pcap_dumper_t *);
779
780 PCAP_AVAILABLE_0_4
781 PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
782
783 PCAP_AVAILABLE_0_7
784 PCAP_API int pcap_findalldevs(pcap_if_t **, char *)
785 PCAP_NONNULL(2) PCAP_WARN_UNUSED_RESULT;
786
787 PCAP_AVAILABLE_0_7
788 PCAP_API void pcap_freealldevs(pcap_if_t *);
789
790 /*
791 * We return a pointer to the version string, rather than exporting the
792 * version string directly.
793 *
794 * On at least some UNIXes, if you import data from a shared library into
795 * a program, the data is bound into the program binary, so if the string
796 * in the version of the library with which the program was linked isn't
797 * the same as the string in the version of the library with which the
798 * program is being run, various undesirable things may happen (warnings,
799 * the string being the one from the version of the library with which the
800 * program was linked, or even weirder things, such as the string being the
801 * one from the library but being truncated).
802 *
803 * On Windows, the string is constructed at run time.
804 */
805 PCAP_AVAILABLE_0_8
806 PCAP_API const char *pcap_lib_version(void);
807
808 #if defined(_WIN32)
809
810 /*
811 * Win32 definitions
812 */
813
814 /*!
815 \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
816 */
817 struct pcap_send_queue
818 {
819 u_int maxlen; /* Maximum size of the queue, in bytes. This
820 variable contains the size of the buffer field. */
821 u_int len; /* Current size of the queue, in bytes. */
822 char *buffer; /* Buffer containing the packets to be sent. */
823 };
824
825 typedef struct pcap_send_queue pcap_send_queue;
826
827 /*!
828 \brief This typedef is a support for the pcap_get_airpcap_handle() function
829 */
830 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
831 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
832 typedef struct _AirpcapHandle* PAirpcapHandle;
833 #endif
834
835 PCAP_API int pcap_setbuff(pcap_t *p, int dim) PCAP_WARN_UNUSED_RESULT;
836 PCAP_API int pcap_setmode(pcap_t *p, int mode) PCAP_WARN_UNUSED_RESULT;
837 PCAP_API int pcap_setmintocopy(pcap_t *p, int size) PCAP_WARN_UNUSED_RESULT;
838
839 PCAP_API HANDLE pcap_getevent(pcap_t *p);
840
841 PCAP_AVAILABLE_1_8
842 PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *)
843 PCAP_WARN_UNUSED_RESULT;
844
845 PCAP_AVAILABLE_1_8
846 PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *,
847 size_t *) PCAP_WARN_UNUSED_RESULT;
848
849 PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
850
851 PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
852
853 PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
854
855 PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
856
857 PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
858
859 PCAP_API int pcap_setuserbuffer(pcap_t *p, int size) PCAP_WARN_UNUSED_RESULT;
860
861 PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize,
862 int maxpacks) PCAP_WARN_UNUSED_RESULT;
863
864 PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync)
865 PCAP_WARN_UNUSED_RESULT;
866
867 PCAP_API int pcap_start_oem(char* err_str, int flags);
868
869 PCAP_DEPRECATED("AirPcap support has been removed")
870 PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t* p);
871
872 #define MODE_CAPT 0
873 #define MODE_STAT 1
874 #define MODE_MON 2
875
876 #else /* UN*X */
877
878 /*
879 * UN*X definitions
880 */
881
882 PCAP_AVAILABLE_0_8
883 PCAP_API int pcap_get_selectable_fd(pcap_t *);
884
885 PCAP_AVAILABLE_1_9
886 PCAP_API const struct timeval *pcap_get_required_select_timeout(pcap_t *);
887
888 #endif /* _WIN32/UN*X */
889
890 /*
891 * APIs added in WinPcap for remote capture.
892 *
893 * They are present even if remote capture isn't enabled, as they
894 * also support local capture, and as their absence may complicate
895 * code build on macOS 14 with Xcode 15, as that platform supports
896 * "weakly linked symbols":
897 *
898 * https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
899 *
900 * which are symbols in dynamically-linked shared libraries, declared in
901 * such a fashion that if a program linked against a newer software
902 * development kit (SDK), and using a symbol present in the OS version
903 * for which that SDK is provided, is run on an older OS version that
904 * lacks that symbol, that symbol's value is a NULL pointer. This
905 * allows those programs to test for the presence of that symbol
906 * by checking whether it's non-null and, if it is, using the symbol,
907 * otherwise not using it.
908 *
909 * (This is a slightly more convenient alternative to the usual
910 * technique used on Windows - and also available, and sometimes
911 * used, on UN*Xes - of loading the library containing the symbol
912 * at run time with dlopen() on UN*Xes and LoadLibrary() on Windows,
913 * looking up the symbol with dlsym() on UN*Xes and GetProcAddress()
914 * on Windows, and using the symbol with the returned pointer if it's
915 * not null.)
916 */
917
918 /*
919 * The maximum buffer size in which address, port, interface names are kept.
920 *
921 * In case the adapter name or such is larger than this value, it is truncated.
922 * This is not used by the user; however it must be aware that an hostname / interface
923 * name longer than this value will be truncated.
924 */
925 #define PCAP_BUF_SIZE 1024
926
927 /*
928 * The type of input source, passed to pcap_open().
929 */
930 #define PCAP_SRC_FILE 2 /* local savefile */
931 #define PCAP_SRC_IFLOCAL 3 /* local network interface */
932 #define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */
933
934 /*
935 * The formats allowed by pcap_open() are the following (optional parts in []):
936 * - file://path_and_filename [opens a local file]
937 * - rpcap://devicename [opens the selected device available on the local host, without using the RPCAP protocol]
938 * - rpcap://[username:password@]host[:port]/devicename [opens the selected device available on a remote host]
939 * - username and password, if present, will be used to authenticate to the remote host
940 * - port, if present, will specify a port for RPCAP rather than using the default
941 * - adaptername [to open a local adapter; kept for compatibility, but it is strongly discouraged]
942 * - (NULL) [to open the first local adapter; kept for compatibility, but it is strongly discouraged]
943 *
944 * The formats allowed by the pcap_findalldevs_ex() are the following (optional parts in []):
945 * - file://folder/ [lists all the files in the given folder]
946 * - rpcap:// [lists all local adapters]
947 * - rpcap://[username:password@]host[:port]/ [lists the devices available on a remote host]
948 * - username and password, if present, will be used to authenticate to the remote host
949 * - port, if present, will specify a port for RPCAP rather than using the default
950 *
951 * In all the above, "rpcaps://" can be substituted for "rpcap://" to enable
952 * SSL (if it has been compiled in).
953 *
954 * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since
955 * IPv6 is fully supported, these are the allowed formats:
956 *
957 * - host (literal): e.g. host.foo.bar
958 * - host (numeric IPv4): e.g. 10.11.12.13
959 * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
960 * - host (numeric IPv6): e.g. [1:2:3::4]
961 * - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
962 *
963 * Here you find some allowed examples:
964 * - rpcap://host.foo.bar/devicename [everything literal, no port number]
965 * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
966 * - rpcap://root:hunter2@host.foo.bar/devicename [everything literal, with username/password]
967 * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
968 * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
969 * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
970 * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
971 * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
972 * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
973 */
974
975 /*
976 * URL schemes for capture source.
977 */
978 /*
979 * This string indicates that the user wants to open a capture from a
980 * local file.
981 */
982 #define PCAP_SRC_FILE_STRING "file://"
983 /*
984 * This string indicates that the user wants to open a capture from a
985 * network interface. This string does not necessarily involve the use
986 * of the RPCAP protocol. If the interface required resides on the local
987 * host, the RPCAP protocol is not involved and the local functions are used.
988 */
989 #define PCAP_SRC_IF_STRING "rpcap://"
990
991 /*
992 * Flags to pass to pcap_open().
993 */
994
995 /*
996 * Specifies whether promiscuous mode is to be used.
997 */
998 #define PCAP_OPENFLAG_PROMISCUOUS 0x00000001
999
1000 /*
1001 * Specifies, for an RPCAP capture, whether the data transfer (in
1002 * case of a remote capture) has to be done with UDP protocol.
1003 *
1004 * If it is '1' if you want a UDP data connection, '0' if you want
1005 * a TCP data connection; control connection is always TCP-based.
1006 * A UDP connection is much lighter, but it does not guarantee that all
1007 * the captured packets arrive to the client workstation. Moreover,
1008 * it could be harmful in case of network congestion.
1009 * This flag is meaningless if the source is not a remote interface.
1010 * In that case, it is simply ignored.
1011 */
1012 #define PCAP_OPENFLAG_DATATX_UDP 0x00000002
1013
1014 /*
1015 * Specifies whether the remote probe will capture its own generated
1016 * traffic.
1017 *
1018 * In case the remote probe uses the same interface to capture traffic
1019 * and to send data back to the caller, the captured traffic includes
1020 * the RPCAP traffic as well. If this flag is turned on, the RPCAP
1021 * traffic is excluded from the capture, so that the trace returned
1022 * back to the collector is does not include this traffic.
1023 *
1024 * Has no effect on local interfaces or savefiles.
1025 */
1026 #define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004
1027
1028 /*
1029 * Specifies whether the local adapter will capture its own generated traffic.
1030 *
1031 * This flag tells the underlying capture driver to drop the packets
1032 * that were sent by itself. This is useful when building applications
1033 * such as bridges that should ignore the traffic they just sent.
1034 *
1035 * Supported only on Windows.
1036 */
1037 #define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008
1038
1039 /*
1040 * This flag configures the adapter for maximum responsiveness.
1041 *
1042 * In presence of a large value for nbytes, WinPcap waits for the arrival
1043 * of several packets before copying the data to the user. This guarantees
1044 * a low number of system calls, i.e. lower processor usage, i.e. better
1045 * performance, which is good for applications like sniffers. If the user
1046 * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will
1047 * copy the packets as soon as the application is ready to receive them.
1048 * This is suggested for real time applications (such as, for example,
1049 * a bridge) that need the best responsiveness.
1050 *
1051 * The equivalent with pcap_create()/pcap_activate() is "immediate mode".
1052 */
1053 #define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010
1054
1055 /*
1056 * Remote authentication methods.
1057 * These are used in the 'type' member of the pcap_rmtauth structure.
1058 */
1059
1060 /*
1061 * NULL authentication.
1062 *
1063 * The 'NULL' authentication has to be equal to 'zero', so that old
1064 * applications can just put every field of struct pcap_rmtauth to zero,
1065 * and it does work.
1066 */
1067 #define RPCAP_RMTAUTH_NULL 0
1068 /*
1069 * Username/password authentication.
1070 *
1071 * With this type of authentication, the RPCAP protocol will use the username/
1072 * password provided to authenticate the user on the remote machine. If the
1073 * authentication is successful (and the user has the right to open network
1074 * devices) the RPCAP connection will continue; otherwise it will be dropped.
1075 *
1076 * *******NOTE********: unless TLS is being used, the username and password
1077 * are sent over the network to the capture server *IN CLEAR TEXT*. Don't
1078 * use this, without TLS (i.e., with rpcap:// rather than rpcaps://) on
1079 * a network that you don't completely control! (And be *really* careful
1080 * in your definition of "completely"!)
1081 */
1082 #define RPCAP_RMTAUTH_PWD 1
1083
1084 /*
1085 * This structure keeps the information needed to authenticate the user
1086 * on a remote machine.
1087 *
1088 * The remote machine can either grant or refuse the access according
1089 * to the information provided.
1090 * In case the NULL authentication is required, both 'username' and
1091 * 'password' can be NULL pointers.
1092 *
1093 * This structure is meaningless if the source is not a remote interface;
1094 * in that case, the functions which requires such a structure can accept
1095 * a NULL pointer as well.
1096 */
1097 struct pcap_rmtauth
1098 {
1099 /*
1100 * \brief Type of the authentication required.
1101 *
1102 * In order to provide maximum flexibility, we can support different types
1103 * of authentication based on the value of this 'type' variable. The currently
1104 * supported authentication methods are defined into the
1105 * \link remote_auth_methods Remote Authentication Methods Section\endlink.
1106 */
1107 int type;
1108 /*
1109 * \brief Zero-terminated string containing the username that has to be
1110 * used on the remote machine for authentication.
1111 *
1112 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
1113 * and it can be NULL.
1114 */
1115 char *username;
1116 /*
1117 * \brief Zero-terminated string containing the password that has to be
1118 * used on the remote machine for authentication.
1119 *
1120 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
1121 * and it can be NULL.
1122 */
1123 char *password;
1124 };
1125
1126 /*
1127 * This routine can open a savefile, a local device, or a device on
1128 * a remote machine running an RPCAP server.
1129 *
1130 * For opening a savefile, the pcap_open_offline routines can be used,
1131 * and will work just as well; code using them will work on more
1132 * platforms than code using pcap_open() to open savefiles.
1133 *
1134 * For opening a local device, pcap_open_live() can be used; it supports
1135 * most of the capabilities that pcap_open() supports, and code using it
1136 * will work on more platforms than code using pcap_open(). pcap_create()
1137 * and pcap_activate() can also be used; they support all capabilities
1138 * that pcap_open() supports, except for the Windows-only
1139 * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities.
1140 *
1141 * For opening a remote capture, pcap_open() is currently the only
1142 * API available.
1143 */
1144 PCAP_AVAILABLE_1_9_REMOTE
1145 PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
1146 int read_timeout, struct pcap_rmtauth *auth, char *errbuf)
1147 PCAP_NONNULL(6);
1148
1149 PCAP_AVAILABLE_1_9_REMOTE
1150 PCAP_API int pcap_createsrcstr(char *source, int type, const char *host,
1151 const char *port, const char *name, char *errbuf)
1152 PCAP_NONNULL(6) PCAP_WARN_UNUSED_RESULT;
1153
1154 PCAP_AVAILABLE_1_9_REMOTE
1155 PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host,
1156 char *port, char *name, char *errbuf)
1157 PCAP_NONNULL(6) PCAP_WARN_UNUSED_RESULT;
1158
1159 /*
1160 * This routine can scan a directory for savefiles, list local capture
1161 * devices, or list capture devices on a remote machine running an RPCAP
1162 * server.
1163 *
1164 * For scanning for savefiles, it can be used on both UN*X systems and
1165 * Windows systems; for each directory entry it sees, it tries to open
1166 * the file as a savefile using pcap_open_offline(), and only includes
1167 * it in the list of files if the open succeeds, so it filters out
1168 * files for which the user doesn't have read permission, as well as
1169 * files that aren't valid savefiles readable by libpcap.
1170 *
1171 * For listing local capture devices, it's just a wrapper around
1172 * pcap_findalldevs(); code using pcap_findalldevs() will work on more
1173 * platforms than code using pcap_findalldevs_ex().
1174 *
1175 * For listing remote capture devices, pcap_findalldevs_ex() is currently
1176 * the only API available.
1177 */
1178 PCAP_AVAILABLE_1_9_REMOTE
1179 PCAP_API int pcap_findalldevs_ex(const char *source,
1180 struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf)
1181 PCAP_NONNULL(4) PCAP_WARN_UNUSED_RESULT;
1182
1183 /*
1184 * Sampling methods.
1185 *
1186 * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex()
1187 * to see only a sample of packets, rather than all packets.
1188 *
1189 * Currently, they work only on Windows local captures.
1190 */
1191
1192 /*
1193 * Specifies that no sampling is to be done on the current capture.
1194 *
1195 * In this case, no sampling algorithms are applied to the current capture.
1196 */
1197 #define PCAP_SAMP_NOSAMP 0
1198
1199 /*
1200 * Specifies that only 1 out of N packets must be returned to the user.
1201 *
1202 * In this case, the 'value' field of the 'pcap_samp' structure indicates the
1203 * number of packets (minus 1) that must be discarded before one packet got
1204 * accepted.
1205 * In other words, if 'value = 10', the first packet is returned to the
1206 * caller, while the following 9 are discarded.
1207 */
1208 #define PCAP_SAMP_1_EVERY_N 1
1209
1210 /*
1211 * Specifies that we have to return 1 packet every N milliseconds.
1212 *
1213 * In this case, the 'value' field of the 'pcap_samp' structure indicates
1214 * the 'waiting time' in milliseconds before one packet got accepted.
1215 * In other words, if 'value = 10', the first packet is returned to the
1216 * caller; the next returned one will be the first packet that arrives
1217 * when 10ms have elapsed.
1218 */
1219 #define PCAP_SAMP_FIRST_AFTER_N_MS 2
1220
1221 /*
1222 * This structure defines the information related to sampling.
1223 *
1224 * In case the sampling is requested, the capturing device should read
1225 * only a subset of the packets coming from the source. The returned packets
1226 * depend on the sampling parameters.
1227 *
1228 * WARNING: The sampling process is applied *after* the filtering process.
1229 * In other words, packets are filtered first, then the sampling process
1230 * selects a subset of the 'filtered' packets and it returns them to the
1231 * caller.
1232 */
1233 struct pcap_samp
1234 {
1235 /*
1236 * Method used for sampling; see above.
1237 */
1238 int method;
1239
1240 /*
1241 * This value depends on the sampling method defined.
1242 * For its meaning, see above.
1243 */
1244 int value;
1245 };
1246
1247 /*
1248 * New functions.
1249 */
1250 PCAP_AVAILABLE_1_9_REMOTE
1251 PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
1252
1253 /*
1254 * RPCAP active mode.
1255 */
1256
1257 /* Maximum length of an host name (needed for the RPCAP active mode) */
1258 #define RPCAP_HOSTLIST_SIZE 1024
1259
1260 PCAP_AVAILABLE_1_9_REMOTE
1261 PCAP_API PCAP_SOCKET pcap_remoteact_accept(const char *address,
1262 const char *port, const char *hostlist, char *connectinghost,
1263 struct pcap_rmtauth *auth, char *errbuf)
1264 PCAP_NONNULL(6);
1265
1266 PCAP_AVAILABLE_1_10_REMOTE
1267 PCAP_API PCAP_SOCKET pcap_remoteact_accept_ex(const char *address,
1268 const char *port, const char *hostlist, char *connectinghost,
1269 struct pcap_rmtauth *auth, int uses_ssl, char *errbuf)
1270 PCAP_NONNULL(7);
1271
1272 PCAP_AVAILABLE_1_9_REMOTE
1273 PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size,
1274 char *errbuf) PCAP_NONNULL(4) PCAP_WARN_UNUSED_RESULT;
1275
1276 PCAP_AVAILABLE_1_9_REMOTE
1277 PCAP_API int pcap_remoteact_close(const char *host, char *errbuf)
1278 PCAP_NONNULL(2) PCAP_WARN_UNUSED_RESULT;
1279
1280 PCAP_AVAILABLE_1_9_REMOTE
1281 PCAP_API void pcap_remoteact_cleanup(void);
1282
1283 enum pcap_option_name { /* never renumber this */
1284 PON_TSTAMP_PRECISION = 1, /* int */
1285 PON_IO_READ_PLUGIN = 2, /* char * */
1286 PON_IO_WRITE_PLUGIN = 3, /* char * */
1287 };
1288 typedef struct pcap_options pcap_options;
1289 PCAP_AVAILABLE_1_11
1290 PCAP_API pcap_options *pcap_alloc_option(void);
1291
1292 PCAP_AVAILABLE_1_11
1293 PCAP_API void pcap_free_option(pcap_options *po);
1294
1295 PCAP_AVAILABLE_1_11
1296 PCAP_API int pcap_set_option_string(pcap_options *po,
1297 enum pcap_option_name pon, const char *value);
1298
1299 PCAP_AVAILABLE_1_11
1300 PCAP_API int pcap_set_option_int(pcap_options *po,
1301 enum pcap_option_name pon, const int value);
1302
1303 PCAP_AVAILABLE_1_11
1304 PCAP_API const char *pcap_get_option_string(pcap_options *po, enum pcap_option_name pon);
1305
1306 PCAP_AVAILABLE_1_11
1307 PCAP_API int pcap_get_option_int(pcap_options *po, enum pcap_option_name pon);
1308
1309 #ifdef __cplusplus
1310 }
1311 #endif
1312
1313 #endif /* lib_pcap_pcap_h */