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