1335640Shselasky/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ 2335640Shselasky/* 3335640Shselasky * Copyright (c) 1993, 1994, 1995, 1996, 1997 4335640Shselasky * The Regents of the University of California. All rights reserved. 5335640Shselasky * 6335640Shselasky * Redistribution and use in source and binary forms, with or without 7335640Shselasky * modification, are permitted provided that the following conditions 8335640Shselasky * are met: 9335640Shselasky * 1. Redistributions of source code must retain the above copyright 10335640Shselasky * notice, this list of conditions and the following disclaimer. 11335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright 12335640Shselasky * notice, this list of conditions and the following disclaimer in the 13335640Shselasky * documentation and/or other materials provided with the distribution. 14335640Shselasky * 3. All advertising materials mentioning features or use of this software 15335640Shselasky * must display the following acknowledgement: 16335640Shselasky * This product includes software developed by the Computer Systems 17335640Shselasky * Engineering Group at Lawrence Berkeley Laboratory. 18335640Shselasky * 4. Neither the name of the University nor of the Laboratory may be used 19335640Shselasky * to endorse or promote products derived from this software without 20335640Shselasky * specific prior written permission. 21335640Shselasky * 22335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23335640Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24335640Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25335640Shselasky * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26335640Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27335640Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28335640Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29335640Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30335640Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31335640Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32335640Shselasky * SUCH DAMAGE. 33335640Shselasky */ 34335640Shselasky 35335640Shselasky/* 36335640Shselasky * Remote packet capture mechanisms and extensions from WinPcap: 37335640Shselasky * 38335640Shselasky * Copyright (c) 2002 - 2003 39335640Shselasky * NetGroup, Politecnico di Torino (Italy) 40335640Shselasky * All rights reserved. 41335640Shselasky * 42335640Shselasky * Redistribution and use in source and binary forms, with or without 43335640Shselasky * modification, are permitted provided that the following conditions 44335640Shselasky * are met: 45335640Shselasky * 46335640Shselasky * 1. Redistributions of source code must retain the above copyright 47335640Shselasky * notice, this list of conditions and the following disclaimer. 48335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright 49335640Shselasky * notice, this list of conditions and the following disclaimer in the 50335640Shselasky * documentation and/or other materials provided with the distribution. 51335640Shselasky * 3. Neither the name of the Politecnico di Torino nor the names of its 52335640Shselasky * contributors may be used to endorse or promote products derived from 53335640Shselasky * this software without specific prior written permission. 54335640Shselasky * 55335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 56335640Shselasky * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 57335640Shselasky * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 58335640Shselasky * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 59335640Shselasky * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 60335640Shselasky * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 61335640Shselasky * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62335640Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63335640Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64335640Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 65335640Shselasky * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66335640Shselasky * 67335640Shselasky */ 68335640Shselasky 69335640Shselasky#ifndef lib_pcap_pcap_h 70335640Shselasky#define lib_pcap_pcap_h 71335640Shselasky 72335640Shselasky#include <pcap/funcattrs.h> 73335640Shselasky 74335640Shselasky#include <pcap/pcap-inttypes.h> 75335640Shselasky 76335640Shselasky#if defined(_WIN32) 77335640Shselasky #include <winsock2.h> /* u_int, u_char etc. */ 78335640Shselasky #include <io.h> /* _get_osfhandle() */ 79335640Shselasky#elif defined(MSDOS) 80335640Shselasky #include <sys/types.h> /* u_int, u_char etc. */ 81335640Shselasky #include <sys/socket.h> 82335640Shselasky#else /* UN*X */ 83335640Shselasky #include <sys/types.h> /* u_int, u_char etc. */ 84335640Shselasky #include <sys/time.h> 85335640Shselasky#endif /* _WIN32/MSDOS/UN*X */ 86335640Shselasky 87356341Scy#include <pcap/socket.h> /* for SOCKET, as the active-mode rpcap APIs use it */ 88335640Shselasky#include <net/bpf.h> 89335640Shselasky 90335640Shselasky#include <stdio.h> 91335640Shselasky 92335640Shselasky#ifdef __cplusplus 93335640Shselaskyextern "C" { 94335640Shselasky#endif 95335640Shselasky 96335640Shselasky/* 97335640Shselasky * Version number of the current version of the pcap file format. 98335640Shselasky * 99335640Shselasky * NOTE: this is *NOT* the version number of the libpcap library. 100335640Shselasky * To fetch the version information for the version of libpcap 101335640Shselasky * you're using, use pcap_lib_version(). 102335640Shselasky */ 103335640Shselasky#define PCAP_VERSION_MAJOR 2 104335640Shselasky#define PCAP_VERSION_MINOR 4 105335640Shselasky 106335640Shselasky#define PCAP_ERRBUF_SIZE 256 107335640Shselasky 108335640Shselasky/* 109335640Shselasky * Compatibility for systems that have a bpf.h that 110335640Shselasky * predates the bpf typedefs for 64-bit support. 111335640Shselasky */ 112335640Shselasky#if BPF_RELEASE - 0 < 199406 113335640Shselaskytypedef int bpf_int32; 114335640Shselaskytypedef u_int bpf_u_int32; 115335640Shselasky#endif 116335640Shselasky 117335640Shselaskytypedef struct pcap pcap_t; 118335640Shselaskytypedef struct pcap_dumper pcap_dumper_t; 119335640Shselaskytypedef struct pcap_if pcap_if_t; 120335640Shselaskytypedef struct pcap_addr pcap_addr_t; 121335640Shselasky 122335640Shselasky/* 123335640Shselasky * The first record in the file contains saved values for some 124335640Shselasky * of the flags used in the printout phases of tcpdump. 125335640Shselasky * Many fields here are 32 bit ints so compilers won't insert unwanted 126335640Shselasky * padding; these files need to be interchangeable across architectures. 127335640Shselasky * 128335640Shselasky * Do not change the layout of this structure, in any way (this includes 129335640Shselasky * changes that only affect the length of fields in this structure). 130335640Shselasky * 131335640Shselasky * Also, do not change the interpretation of any of the members of this 132335640Shselasky * structure, in any way (this includes using values other than 133335640Shselasky * LINKTYPE_ values, as defined in "savefile.c", in the "linktype" 134335640Shselasky * field). 135335640Shselasky * 136335640Shselasky * Instead: 137335640Shselasky * 138335640Shselasky * introduce a new structure for the new format, if the layout 139335640Shselasky * of the structure changed; 140335640Shselasky * 141335640Shselasky * send mail to "tcpdump-workers@lists.tcpdump.org", requesting 142335640Shselasky * a new magic number for your new capture file format, and, when 143335640Shselasky * you get the new magic number, put it in "savefile.c"; 144335640Shselasky * 145335640Shselasky * use that magic number for save files with the changed file 146335640Shselasky * header; 147335640Shselasky * 148335640Shselasky * make the code in "savefile.c" capable of reading files with 149335640Shselasky * the old file header as well as files with the new file header 150335640Shselasky * (using the magic number to determine the header format). 151335640Shselasky * 152335640Shselasky * Then supply the changes by forking the branch at 153335640Shselasky * 154335640Shselasky * https://github.com/the-tcpdump-group/libpcap/issues 155335640Shselasky * 156335640Shselasky * and issuing a pull request, so that future versions of libpcap and 157335640Shselasky * programs that use it (such as tcpdump) will be able to read your new 158335640Shselasky * capture file format. 159335640Shselasky */ 160335640Shselaskystruct pcap_file_header { 161335640Shselasky bpf_u_int32 magic; 162335640Shselasky u_short version_major; 163335640Shselasky u_short version_minor; 164335640Shselasky bpf_int32 thiszone; /* gmt to local correction */ 165335640Shselasky bpf_u_int32 sigfigs; /* accuracy of timestamps */ 166335640Shselasky bpf_u_int32 snaplen; /* max length saved portion of each pkt */ 167335640Shselasky bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */ 168335640Shselasky}; 169335640Shselasky 170335640Shselasky/* 171335640Shselasky * Macros for the value returned by pcap_datalink_ext(). 172335640Shselasky * 173335640Shselasky * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro 174335640Shselasky * gives the FCS length of packets in the capture. 175335640Shselasky */ 176335640Shselasky#define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000) 177335640Shselasky#define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28) 178335640Shselasky#define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000) 179335640Shselasky 180335640Shselaskytypedef enum { 181335640Shselasky PCAP_D_INOUT = 0, 182335640Shselasky PCAP_D_IN, 183335640Shselasky PCAP_D_OUT 184335640Shselasky} pcap_direction_t; 185335640Shselasky 186335640Shselasky/* 187335640Shselasky * Generic per-packet information, as supplied by libpcap. 188335640Shselasky * 189335640Shselasky * The time stamp can and should be a "struct timeval", regardless of 190335640Shselasky * whether your system supports 32-bit tv_sec in "struct timeval", 191335640Shselasky * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit 192335640Shselasky * and 64-bit applications. The on-disk format of savefiles uses 32-bit 193335640Shselasky * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit 194335640Shselasky * and 64-bit versions of libpcap, even if they're on the same platform, 195335640Shselasky * should supply the appropriate version of "struct timeval", even if 196335640Shselasky * that's not what the underlying packet capture mechanism supplies. 197335640Shselasky */ 198335640Shselaskystruct pcap_pkthdr { 199335640Shselasky struct timeval ts; /* time stamp */ 200335640Shselasky bpf_u_int32 caplen; /* length of portion present */ 201335640Shselasky bpf_u_int32 len; /* length this packet (off wire) */ 202335640Shselasky}; 203335640Shselasky 204335640Shselasky/* 205335640Shselasky * As returned by the pcap_stats() 206335640Shselasky */ 207335640Shselaskystruct pcap_stat { 208335640Shselasky u_int ps_recv; /* number of packets received */ 209335640Shselasky u_int ps_drop; /* number of packets dropped */ 210335640Shselasky u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */ 211335640Shselasky#ifdef _WIN32 212335640Shselasky u_int ps_capt; /* number of packets that reach the application */ 213335640Shselasky u_int ps_sent; /* number of packets sent by the server on the network */ 214335640Shselasky u_int ps_netdrop; /* number of packets lost on the network */ 215335640Shselasky#endif /* _WIN32 */ 216335640Shselasky}; 217335640Shselasky 218335640Shselasky#ifdef MSDOS 219335640Shselasky/* 220335640Shselasky * As returned by the pcap_stats_ex() 221335640Shselasky */ 222335640Shselaskystruct pcap_stat_ex { 223335640Shselasky u_long rx_packets; /* total packets received */ 224335640Shselasky u_long tx_packets; /* total packets transmitted */ 225335640Shselasky u_long rx_bytes; /* total bytes received */ 226335640Shselasky u_long tx_bytes; /* total bytes transmitted */ 227335640Shselasky u_long rx_errors; /* bad packets received */ 228335640Shselasky u_long tx_errors; /* packet transmit problems */ 229335640Shselasky u_long rx_dropped; /* no space in Rx buffers */ 230335640Shselasky u_long tx_dropped; /* no space available for Tx */ 231335640Shselasky u_long multicast; /* multicast packets received */ 232335640Shselasky u_long collisions; 233335640Shselasky 234335640Shselasky /* detailed rx_errors: */ 235335640Shselasky u_long rx_length_errors; 236335640Shselasky u_long rx_over_errors; /* receiver ring buff overflow */ 237335640Shselasky u_long rx_crc_errors; /* recv'd pkt with crc error */ 238335640Shselasky u_long rx_frame_errors; /* recv'd frame alignment error */ 239335640Shselasky u_long rx_fifo_errors; /* recv'r fifo overrun */ 240335640Shselasky u_long rx_missed_errors; /* recv'r missed packet */ 241335640Shselasky 242335640Shselasky /* detailed tx_errors */ 243335640Shselasky u_long tx_aborted_errors; 244335640Shselasky u_long tx_carrier_errors; 245335640Shselasky u_long tx_fifo_errors; 246335640Shselasky u_long tx_heartbeat_errors; 247335640Shselasky u_long tx_window_errors; 248335640Shselasky }; 249335640Shselasky#endif 250335640Shselasky 251335640Shselasky/* 252335640Shselasky * Item in a list of interfaces. 253335640Shselasky */ 254335640Shselaskystruct pcap_if { 255335640Shselasky struct pcap_if *next; 256335640Shselasky char *name; /* name to hand to "pcap_open_live()" */ 257335640Shselasky char *description; /* textual description of interface, or NULL */ 258335640Shselasky struct pcap_addr *addresses; 259335640Shselasky bpf_u_int32 flags; /* PCAP_IF_ interface flags */ 260335640Shselasky}; 261335640Shselasky 262335640Shselasky#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */ 263335640Shselasky#define PCAP_IF_UP 0x00000002 /* interface is up */ 264335640Shselasky#define PCAP_IF_RUNNING 0x00000004 /* interface is running */ 265335640Shselasky#define PCAP_IF_WIRELESS 0x00000008 /* interface is wireless (*NOT* necessarily Wi-Fi!) */ 266335640Shselasky#define PCAP_IF_CONNECTION_STATUS 0x00000030 /* connection status: */ 267335640Shselasky#define PCAP_IF_CONNECTION_STATUS_UNKNOWN 0x00000000 /* unknown */ 268335640Shselasky#define PCAP_IF_CONNECTION_STATUS_CONNECTED 0x00000010 /* connected */ 269335640Shselasky#define PCAP_IF_CONNECTION_STATUS_DISCONNECTED 0x00000020 /* disconnected */ 270335640Shselasky#define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE 0x00000030 /* not applicable */ 271335640Shselasky 272335640Shselasky/* 273335640Shselasky * Representation of an interface address. 274335640Shselasky */ 275335640Shselaskystruct pcap_addr { 276335640Shselasky struct pcap_addr *next; 277335640Shselasky struct sockaddr *addr; /* address */ 278335640Shselasky struct sockaddr *netmask; /* netmask for that address */ 279335640Shselasky struct sockaddr *broadaddr; /* broadcast address for that address */ 280335640Shselasky struct sockaddr *dstaddr; /* P2P destination address for that address */ 281335640Shselasky}; 282335640Shselasky 283335640Shselaskytypedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, 284335640Shselasky const u_char *); 285335640Shselasky 286335640Shselasky/* 287335640Shselasky * Error codes for the pcap API. 288335640Shselasky * These will all be negative, so you can check for the success or 289335640Shselasky * failure of a call that returns these codes by checking for a 290335640Shselasky * negative value. 291335640Shselasky */ 292335640Shselasky#define PCAP_ERROR -1 /* generic error code */ 293335640Shselasky#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */ 294335640Shselasky#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */ 295335640Shselasky#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */ 296335640Shselasky#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */ 297335640Shselasky#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */ 298335640Shselasky#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */ 299335640Shselasky#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */ 300335640Shselasky#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */ 301335640Shselasky#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */ 302335640Shselasky#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */ 303335640Shselasky#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */ 304335640Shselasky 305335640Shselasky/* 306335640Shselasky * Warning codes for the pcap API. 307335640Shselasky * These will all be positive and non-zero, so they won't look like 308335640Shselasky * errors. 309335640Shselasky */ 310335640Shselasky#define PCAP_WARNING 1 /* generic warning code */ 311335640Shselasky#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */ 312335640Shselasky#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */ 313335640Shselasky 314335640Shselasky/* 315335640Shselasky * Value to pass to pcap_compile() as the netmask if you don't know what 316335640Shselasky * the netmask is. 317335640Shselasky */ 318335640Shselasky#define PCAP_NETMASK_UNKNOWN 0xffffffff 319335640Shselasky 320335640Shselasky/* 321335640Shselasky * We're deprecating pcap_lookupdev() for various reasons (not 322335640Shselasky * thread-safe, can behave weirdly with WinPcap). Callers 323335640Shselasky * should use pcap_findalldevs() and use the first device. 324335640Shselasky */ 325335640ShselaskyPCAP_API char *pcap_lookupdev(char *) 326335640ShselaskyPCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device"); 327335640Shselasky 328335640ShselaskyPCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); 329335640Shselasky 330335640ShselaskyPCAP_API pcap_t *pcap_create(const char *, char *); 331335640ShselaskyPCAP_API int pcap_set_snaplen(pcap_t *, int); 332335640ShselaskyPCAP_API int pcap_set_promisc(pcap_t *, int); 333335640ShselaskyPCAP_API int pcap_can_set_rfmon(pcap_t *); 334335640ShselaskyPCAP_API int pcap_set_rfmon(pcap_t *, int); 335335640ShselaskyPCAP_API int pcap_set_timeout(pcap_t *, int); 336335640ShselaskyPCAP_API int pcap_set_tstamp_type(pcap_t *, int); 337335640ShselaskyPCAP_API int pcap_set_immediate_mode(pcap_t *, int); 338335640ShselaskyPCAP_API int pcap_set_buffer_size(pcap_t *, int); 339335640ShselaskyPCAP_API int pcap_set_tstamp_precision(pcap_t *, int); 340335640ShselaskyPCAP_API int pcap_get_tstamp_precision(pcap_t *); 341335640ShselaskyPCAP_API int pcap_activate(pcap_t *); 342335640Shselasky 343335640ShselaskyPCAP_API int pcap_list_tstamp_types(pcap_t *, int **); 344335640ShselaskyPCAP_API void pcap_free_tstamp_types(int *); 345335640ShselaskyPCAP_API int pcap_tstamp_type_name_to_val(const char *); 346335640ShselaskyPCAP_API const char *pcap_tstamp_type_val_to_name(int); 347335640ShselaskyPCAP_API const char *pcap_tstamp_type_val_to_description(int); 348335640Shselasky 349335640Shselasky#ifdef __linux__ 350356341ScyPCAP_API int pcap_set_protocol_linux(pcap_t *, int); 351335640Shselasky#endif 352335640Shselasky 353335640Shselasky/* 354335640Shselasky * Time stamp types. 355335640Shselasky * Not all systems and interfaces will necessarily support all of these. 356335640Shselasky * 357335640Shselasky * A system that supports PCAP_TSTAMP_HOST is offering time stamps 358335640Shselasky * provided by the host machine, rather than by the capture device, 359335640Shselasky * but not committing to any characteristics of the time stamp; 360335640Shselasky * it will not offer any of the PCAP_TSTAMP_HOST_ subtypes. 361335640Shselasky * 362335640Shselasky * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine, 363335640Shselasky * that's low-precision but relatively cheap to fetch; it's normally done 364335640Shselasky * using the system clock, so it's normally synchronized with times you'd 365335640Shselasky * fetch from system calls. 366335640Shselasky * 367335640Shselasky * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine, 368335640Shselasky * that's high-precision; it might be more expensive to fetch. It might 369335640Shselasky * or might not be synchronized with the system clock, and might have 370335640Shselasky * problems with time stamps for packets received on different CPUs, 371335640Shselasky * depending on the platform. 372335640Shselasky * 373335640Shselasky * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the 374335640Shselasky * capture device; it's synchronized with the system clock. 375335640Shselasky * 376335640Shselasky * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by 377335640Shselasky * the capture device; it's not synchronized with the system clock. 378335640Shselasky * 379335640Shselasky * Note that time stamps synchronized with the system clock can go 380335640Shselasky * backwards, as the system clock can go backwards. If a clock is 381335640Shselasky * not in sync with the system clock, that could be because the 382335640Shselasky * system clock isn't keeping accurate time, because the other 383335640Shselasky * clock isn't keeping accurate time, or both. 384335640Shselasky * 385335640Shselasky * Note that host-provided time stamps generally correspond to the 386335640Shselasky * time when the time-stamping code sees the packet; this could 387335640Shselasky * be some unknown amount of time after the first or last bit of 388335640Shselasky * the packet is received by the network adapter, due to batching 389335640Shselasky * of interrupts for packet arrival, queueing delays, etc.. 390335640Shselasky */ 391335640Shselasky#define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */ 392335640Shselasky#define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision */ 393335640Shselasky#define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision */ 394335640Shselasky#define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */ 395335640Shselasky#define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */ 396335640Shselasky 397335640Shselasky/* 398335640Shselasky * Time stamp resolution types. 399335640Shselasky * Not all systems and interfaces will necessarily support all of these 400335640Shselasky * resolutions when doing live captures; all of them can be requested 401335640Shselasky * when reading a savefile. 402335640Shselasky */ 403335640Shselasky#define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */ 404335640Shselasky#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */ 405335640Shselasky 406335640ShselaskyPCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *); 407335640ShselaskyPCAP_API pcap_t *pcap_open_dead(int, int); 408335640ShselaskyPCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int); 409335640ShselaskyPCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *); 410335640ShselaskyPCAP_API pcap_t *pcap_open_offline(const char *, char *); 411335640Shselasky#ifdef _WIN32 412335640Shselasky PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *); 413335640Shselasky PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *); 414335640Shselasky /* 415335640Shselasky * If we're building libpcap, these are internal routines in savefile.c, 416335640Shselasky * so we must not define them as macros. 417335640Shselasky * 418335640Shselasky * If we're not building libpcap, given that the version of the C runtime 419335640Shselasky * with which libpcap was built might be different from the version 420335640Shselasky * of the C runtime with which an application using libpcap was built, 421335640Shselasky * and that a FILE structure may differ between the two versions of the 422335640Shselasky * C runtime, calls to _fileno() must use the version of _fileno() in 423335640Shselasky * the C runtime used to open the FILE *, not the version in the C 424335640Shselasky * runtime with which libpcap was built. (Maybe once the Universal CRT 425335640Shselasky * rules the world, this will cease to be a problem.) 426335640Shselasky */ 427335640Shselasky #ifndef BUILDING_PCAP 428335640Shselasky #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \ 429335640Shselasky pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b) 430335640Shselasky #define pcap_fopen_offline(f,b) \ 431335640Shselasky pcap_hopen_offline(_get_osfhandle(_fileno(f)), b) 432335640Shselasky #endif 433335640Shselasky#else /*_WIN32*/ 434335640Shselasky PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *); 435335640Shselasky PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *); 436335640Shselasky#endif /*_WIN32*/ 437335640Shselasky 438335640ShselaskyPCAP_API void pcap_close(pcap_t *); 439335640ShselaskyPCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *); 440335640ShselaskyPCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); 441335640ShselaskyPCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *); 442335640ShselaskyPCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **); 443335640ShselaskyPCAP_API void pcap_breakloop(pcap_t *); 444335640ShselaskyPCAP_API int pcap_stats(pcap_t *, struct pcap_stat *); 445335640ShselaskyPCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *); 446335640ShselaskyPCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t); 447335640ShselaskyPCAP_API int pcap_getnonblock(pcap_t *, char *); 448335640ShselaskyPCAP_API int pcap_setnonblock(pcap_t *, int, char *); 449335640ShselaskyPCAP_API int pcap_inject(pcap_t *, const void *, size_t); 450335640ShselaskyPCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int); 451335640ShselaskyPCAP_API const char *pcap_statustostr(int); 452335640ShselaskyPCAP_API const char *pcap_strerror(int); 453335640ShselaskyPCAP_API char *pcap_geterr(pcap_t *); 454335640ShselaskyPCAP_API void pcap_perror(pcap_t *, const char *); 455335640ShselaskyPCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int, 456335640Shselasky bpf_u_int32); 457335640ShselaskyPCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *, 458335640Shselasky const char *, int, bpf_u_int32); 459335640ShselaskyPCAP_API void pcap_freecode(struct bpf_program *); 460335640ShselaskyPCAP_API int pcap_offline_filter(const struct bpf_program *, 461335640Shselasky const struct pcap_pkthdr *, const u_char *); 462335640ShselaskyPCAP_API int pcap_datalink(pcap_t *); 463335640ShselaskyPCAP_API int pcap_datalink_ext(pcap_t *); 464335640ShselaskyPCAP_API int pcap_list_datalinks(pcap_t *, int **); 465335640ShselaskyPCAP_API int pcap_set_datalink(pcap_t *, int); 466335640ShselaskyPCAP_API void pcap_free_datalinks(int *); 467335640ShselaskyPCAP_API int pcap_datalink_name_to_val(const char *); 468335640ShselaskyPCAP_API const char *pcap_datalink_val_to_name(int); 469335640ShselaskyPCAP_API const char *pcap_datalink_val_to_description(int); 470356341ScyPCAP_API const char *pcap_datalink_val_to_description_or_dlt(int); 471335640ShselaskyPCAP_API int pcap_snapshot(pcap_t *); 472335640ShselaskyPCAP_API int pcap_is_swapped(pcap_t *); 473335640ShselaskyPCAP_API int pcap_major_version(pcap_t *); 474335640ShselaskyPCAP_API int pcap_minor_version(pcap_t *); 475335640ShselaskyPCAP_API int pcap_bufsize(pcap_t *); 476335640Shselasky 477335640Shselasky/* XXX */ 478335640ShselaskyPCAP_API FILE *pcap_file(pcap_t *); 479335640ShselaskyPCAP_API int pcap_fileno(pcap_t *); 480335640Shselasky 481335640Shselasky#ifdef _WIN32 482335640Shselasky PCAP_API int pcap_wsockinit(void); 483335640Shselasky#endif 484335640Shselasky 485335640ShselaskyPCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); 486356341Scy#ifdef _WIN32 487356341Scy PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t); 488356341Scy /* 489356341Scy * If we're building libpcap, this is an internal routine in sf-pcap.c, so 490356341Scy * we must not define it as a macro. 491356341Scy * 492356341Scy * If we're not building libpcap, given that the version of the C runtime 493356341Scy * with which libpcap was built might be different from the version 494356341Scy * of the C runtime with which an application using libpcap was built, 495356341Scy * and that a FILE structure may differ between the two versions of the 496356341Scy * C runtime, calls to _fileno() must use the version of _fileno() in 497356341Scy * the C runtime used to open the FILE *, not the version in the C 498356341Scy * runtime with which libpcap was built. (Maybe once the Universal CRT 499356341Scy * rules the world, this will cease to be a problem.) 500356341Scy */ 501356341Scy #ifndef BUILDING_PCAP 502356341Scy #define pcap_dump_fopen(p,f) \ 503356341Scy pcap_dump_hopen(p, _get_osfhandle(_fileno(f))) 504356341Scy #endif 505356341Scy#else /*_WIN32*/ 506356341Scy PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); 507356341Scy#endif /*_WIN32*/ 508335640ShselaskyPCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *); 509335640ShselaskyPCAP_API FILE *pcap_dump_file(pcap_dumper_t *); 510335640ShselaskyPCAP_API long pcap_dump_ftell(pcap_dumper_t *); 511335640ShselaskyPCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *); 512335640ShselaskyPCAP_API int pcap_dump_flush(pcap_dumper_t *); 513335640ShselaskyPCAP_API void pcap_dump_close(pcap_dumper_t *); 514335640ShselaskyPCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); 515335640Shselasky 516335640ShselaskyPCAP_API int pcap_findalldevs(pcap_if_t **, char *); 517335640ShselaskyPCAP_API void pcap_freealldevs(pcap_if_t *); 518335640Shselasky 519335640Shselasky/* 520335640Shselasky * We return a pointer to the version string, rather than exporting the 521335640Shselasky * version string directly. 522335640Shselasky * 523335640Shselasky * On at least some UNIXes, if you import data from a shared library into 524335640Shselasky * an program, the data is bound into the program binary, so if the string 525335640Shselasky * in the version of the library with which the program was linked isn't 526335640Shselasky * the same as the string in the version of the library with which the 527335640Shselasky * program is being run, various undesirable things may happen (warnings, 528335640Shselasky * the string being the one from the version of the library with which the 529335640Shselasky * program was linked, or even weirder things, such as the string being the 530335640Shselasky * one from the library but being truncated). 531335640Shselasky * 532335640Shselasky * On Windows, the string is constructed at run time. 533335640Shselasky */ 534335640ShselaskyPCAP_API const char *pcap_lib_version(void); 535335640Shselasky 536335640Shselasky/* 537335640Shselasky * On at least some versions of NetBSD and QNX, we don't want to declare 538335640Shselasky * bpf_filter() here, as it's also be declared in <net/bpf.h>, with a 539335640Shselasky * different signature, but, on other BSD-flavored UN*Xes, it's not 540335640Shselasky * declared in <net/bpf.h>, so we *do* want to declare it here, so it's 541335640Shselasky * declared when we build pcap-bpf.c. 542335640Shselasky */ 543335640Shselasky#if !defined(__NetBSD__) && !defined(__QNX__) 544335640Shselasky PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); 545335640Shselasky#endif 546335640ShselaskyPCAP_API int bpf_validate(const struct bpf_insn *f, int len); 547335640ShselaskyPCAP_API char *bpf_image(const struct bpf_insn *, int); 548335640ShselaskyPCAP_API void bpf_dump(const struct bpf_program *, int); 549335640Shselasky 550335640Shselasky#if defined(_WIN32) 551335640Shselasky 552335640Shselasky /* 553335640Shselasky * Win32 definitions 554335640Shselasky */ 555335640Shselasky 556335640Shselasky /*! 557335640Shselasky \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit(). 558335640Shselasky */ 559335640Shselasky struct pcap_send_queue 560335640Shselasky { 561335640Shselasky u_int maxlen; /* Maximum size of the queue, in bytes. This 562335640Shselasky variable contains the size of the buffer field. */ 563335640Shselasky u_int len; /* Current size of the queue, in bytes. */ 564335640Shselasky char *buffer; /* Buffer containing the packets to be sent. */ 565335640Shselasky }; 566335640Shselasky 567335640Shselasky typedef struct pcap_send_queue pcap_send_queue; 568335640Shselasky 569335640Shselasky /*! 570335640Shselasky \brief This typedef is a support for the pcap_get_airpcap_handle() function 571335640Shselasky */ 572335640Shselasky #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) 573335640Shselasky #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ 574335640Shselasky typedef struct _AirpcapHandle *PAirpcapHandle; 575335640Shselasky #endif 576335640Shselasky 577335640Shselasky PCAP_API int pcap_setbuff(pcap_t *p, int dim); 578335640Shselasky PCAP_API int pcap_setmode(pcap_t *p, int mode); 579335640Shselasky PCAP_API int pcap_setmintocopy(pcap_t *p, int size); 580335640Shselasky 581335640Shselasky PCAP_API HANDLE pcap_getevent(pcap_t *p); 582335640Shselasky 583335640Shselasky PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *); 584335640Shselasky PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *); 585335640Shselasky 586335640Shselasky PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize); 587335640Shselasky 588335640Shselasky PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue); 589335640Shselasky 590335640Shselasky PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data); 591335640Shselasky 592335640Shselasky PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync); 593335640Shselasky 594335640Shselasky PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size); 595335640Shselasky 596335640Shselasky PCAP_API int pcap_setuserbuffer(pcap_t *p, int size); 597335640Shselasky 598335640Shselasky PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks); 599335640Shselasky 600335640Shselasky PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync); 601335640Shselasky 602335640Shselasky PCAP_API int pcap_start_oem(char* err_str, int flags); 603335640Shselasky 604335640Shselasky PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p); 605335640Shselasky 606335640Shselasky #define MODE_CAPT 0 607335640Shselasky #define MODE_STAT 1 608335640Shselasky #define MODE_MON 2 609335640Shselasky 610335640Shselasky#elif defined(MSDOS) 611335640Shselasky 612335640Shselasky /* 613335640Shselasky * MS-DOS definitions 614335640Shselasky */ 615335640Shselasky 616335640Shselasky PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *); 617335640Shselasky PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait); 618335640Shselasky PCAP_API u_long pcap_mac_packets (void); 619335640Shselasky 620335640Shselasky#else /* UN*X */ 621335640Shselasky 622335640Shselasky /* 623335640Shselasky * UN*X definitions 624335640Shselasky */ 625335640Shselasky 626335640Shselasky PCAP_API int pcap_get_selectable_fd(pcap_t *); 627335640Shselasky PCAP_API struct timeval *pcap_get_required_select_timeout(pcap_t *); 628335640Shselasky 629335640Shselasky#endif /* _WIN32/MSDOS/UN*X */ 630335640Shselasky 631335640Shselasky#if 0 /* Remote capture is disabled on FreeBSD */ 632335640Shselasky/* 633335640Shselasky * Remote capture definitions. 634335640Shselasky * 635335640Shselasky * These routines are only present if libpcap has been configured to 636335640Shselasky * include remote capture support. 637335640Shselasky */ 638335640Shselasky 639335640Shselasky/* 640335640Shselasky * The maximum buffer size in which address, port, interface names are kept. 641335640Shselasky * 642335640Shselasky * In case the adapter name or such is larger than this value, it is truncated. 643335640Shselasky * This is not used by the user; however it must be aware that an hostname / interface 644335640Shselasky * name longer than this value will be truncated. 645335640Shselasky */ 646335640Shselasky#define PCAP_BUF_SIZE 1024 647335640Shselasky 648335640Shselasky/* 649335640Shselasky * The type of input source, passed to pcap_open(). 650335640Shselasky */ 651335640Shselasky#define PCAP_SRC_FILE 2 /* local savefile */ 652335640Shselasky#define PCAP_SRC_IFLOCAL 3 /* local network interface */ 653335640Shselasky#define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */ 654335640Shselasky 655335640Shselasky/* 656335640Shselasky * The formats allowed by pcap_open() are the following: 657335640Shselasky * - file://path_and_filename [opens a local file] 658335640Shselasky * - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol] 659335640Shselasky * - rpcap://host/devicename [opens the selected device available on a remote host] 660335640Shselasky * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP] 661335640Shselasky * - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged] 662335640Shselasky * - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged] 663335640Shselasky * 664335640Shselasky * The formats allowed by the pcap_findalldevs_ex() are the following: 665335640Shselasky * - file://folder/ [lists all the files in the given folder] 666335640Shselasky * - rpcap:// [lists all local adapters] 667335640Shselasky * - rpcap://host:port/ [lists the devices available on a remote host] 668335640Shselasky * 669335640Shselasky * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since 670335640Shselasky * IPv6 is fully supported, these are the allowed formats: 671335640Shselasky * 672335640Shselasky * - host (literal): e.g. host.foo.bar 673335640Shselasky * - host (numeric IPv4): e.g. 10.11.12.13 674335640Shselasky * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13] 675335640Shselasky * - host (numeric IPv6): e.g. [1:2:3::4] 676335640Shselasky * - port: can be either numeric (e.g. '80') or literal (e.g. 'http') 677335640Shselasky * 678335640Shselasky * Here you find some allowed examples: 679335640Shselasky * - rpcap://host.foo.bar/devicename [everything literal, no port number] 680335640Shselasky * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number] 681335640Shselasky * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number] 682335640Shselasky * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number] 683335640Shselasky * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number] 684335640Shselasky * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number] 685335640Shselasky * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number] 686335640Shselasky * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number] 687335640Shselasky */ 688335640Shselasky 689335640Shselasky/* 690335640Shselasky * URL schemes for capture source. 691335640Shselasky */ 692335640Shselasky/* 693335640Shselasky * This string indicates that the user wants to open a capture from a 694335640Shselasky * local file. 695335640Shselasky */ 696335640Shselasky#define PCAP_SRC_FILE_STRING "file://" 697335640Shselasky/* 698335640Shselasky * This string indicates that the user wants to open a capture from a 699335640Shselasky * network interface. This string does not necessarily involve the use 700335640Shselasky * of the RPCAP protocol. If the interface required resides on the local 701335640Shselasky * host, the RPCAP protocol is not involved and the local functions are used. 702335640Shselasky */ 703335640Shselasky#define PCAP_SRC_IF_STRING "rpcap://" 704335640Shselasky 705335640Shselasky/* 706335640Shselasky * Flags to pass to pcap_open(). 707335640Shselasky */ 708335640Shselasky 709335640Shselasky/* 710335640Shselasky * Specifies whether promiscuous mode is to be used. 711335640Shselasky */ 712335640Shselasky#define PCAP_OPENFLAG_PROMISCUOUS 0x00000001 713335640Shselasky 714335640Shselasky/* 715335640Shselasky * Specifies, for an RPCAP capture, whether the data transfer (in 716335640Shselasky * case of a remote capture) has to be done with UDP protocol. 717335640Shselasky * 718335640Shselasky * If it is '1' if you want a UDP data connection, '0' if you want 719335640Shselasky * a TCP data connection; control connection is always TCP-based. 720335640Shselasky * A UDP connection is much lighter, but it does not guarantee that all 721335640Shselasky * the captured packets arrive to the client workstation. Moreover, 722335640Shselasky * it could be harmful in case of network congestion. 723335640Shselasky * This flag is meaningless if the source is not a remote interface. 724335640Shselasky * In that case, it is simply ignored. 725335640Shselasky */ 726335640Shselasky#define PCAP_OPENFLAG_DATATX_UDP 0x00000002 727335640Shselasky 728335640Shselasky/* 729335640Shselasky * Specifies wheether the remote probe will capture its own generated 730335640Shselasky * traffic. 731335640Shselasky * 732335640Shselasky * In case the remote probe uses the same interface to capture traffic 733335640Shselasky * and to send data back to the caller, the captured traffic includes 734335640Shselasky * the RPCAP traffic as well. If this flag is turned on, the RPCAP 735335640Shselasky * traffic is excluded from the capture, so that the trace returned 736335640Shselasky * back to the collector is does not include this traffic. 737335640Shselasky * 738335640Shselasky * Has no effect on local interfaces or savefiles. 739335640Shselasky */ 740335640Shselasky#define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004 741335640Shselasky 742335640Shselasky/* 743335640Shselasky * Specifies whether the local adapter will capture its own generated traffic. 744335640Shselasky * 745335640Shselasky * This flag tells the underlying capture driver to drop the packets 746335640Shselasky * that were sent by itself. This is useful when building applications 747335640Shselasky * such as bridges that should ignore the traffic they just sent. 748335640Shselasky * 749335640Shselasky * Supported only on Windows. 750335640Shselasky */ 751335640Shselasky#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008 752335640Shselasky 753335640Shselasky/* 754335640Shselasky * This flag configures the adapter for maximum responsiveness. 755335640Shselasky * 756335640Shselasky * In presence of a large value for nbytes, WinPcap waits for the arrival 757335640Shselasky * of several packets before copying the data to the user. This guarantees 758335640Shselasky * a low number of system calls, i.e. lower processor usage, i.e. better 759335640Shselasky * performance, which is good for applications like sniffers. If the user 760335640Shselasky * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will 761335640Shselasky * copy the packets as soon as the application is ready to receive them. 762335640Shselasky * This is suggested for real time applications (such as, for example, 763335640Shselasky * a bridge) that need the best responsiveness. 764335640Shselasky * 765335640Shselasky * The equivalent with pcap_create()/pcap_activate() is "immediate mode". 766335640Shselasky */ 767335640Shselasky#define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010 768335640Shselasky 769335640Shselasky/* 770335640Shselasky * Remote authentication methods. 771335640Shselasky * These are used in the 'type' member of the pcap_rmtauth structure. 772335640Shselasky */ 773335640Shselasky 774335640Shselasky/* 775335640Shselasky * NULL authentication. 776335640Shselasky * 777335640Shselasky * The 'NULL' authentication has to be equal to 'zero', so that old 778335640Shselasky * applications can just put every field of struct pcap_rmtauth to zero, 779335640Shselasky * and it does work. 780335640Shselasky */ 781335640Shselasky#define RPCAP_RMTAUTH_NULL 0 782335640Shselasky/* 783335640Shselasky * Username/password authentication. 784335640Shselasky * 785335640Shselasky * With this type of authentication, the RPCAP protocol will use the username/ 786335640Shselasky * password provided to authenticate the user on the remote machine. If the 787335640Shselasky * authentication is successful (and the user has the right to open network 788335640Shselasky * devices) the RPCAP connection will continue; otherwise it will be dropped. 789335640Shselasky * 790335640Shselasky * *******NOTE********: the username and password are sent over the network 791335640Shselasky * to the capture server *IN CLEAR TEXT*. Don't use this on a network 792335640Shselasky * that you don't completely control! (And be *really* careful in your 793335640Shselasky * definition of "completely"!) 794335640Shselasky */ 795335640Shselasky#define RPCAP_RMTAUTH_PWD 1 796335640Shselasky 797335640Shselasky/* 798335640Shselasky * This structure keeps the information needed to autheticate the user 799335640Shselasky * on a remote machine. 800335640Shselasky * 801335640Shselasky * The remote machine can either grant or refuse the access according 802335640Shselasky * to the information provided. 803335640Shselasky * In case the NULL authentication is required, both 'username' and 804335640Shselasky * 'password' can be NULL pointers. 805335640Shselasky * 806335640Shselasky * This structure is meaningless if the source is not a remote interface; 807335640Shselasky * in that case, the functions which requires such a structure can accept 808335640Shselasky * a NULL pointer as well. 809335640Shselasky */ 810335640Shselaskystruct pcap_rmtauth 811335640Shselasky{ 812335640Shselasky /* 813335640Shselasky * \brief Type of the authentication required. 814335640Shselasky * 815335640Shselasky * In order to provide maximum flexibility, we can support different types 816335640Shselasky * of authentication based on the value of this 'type' variable. The currently 817335640Shselasky * supported authentication methods are defined into the 818335640Shselasky * \link remote_auth_methods Remote Authentication Methods Section\endlink. 819335640Shselasky */ 820335640Shselasky int type; 821335640Shselasky /* 822335640Shselasky * \brief Zero-terminated string containing the username that has to be 823335640Shselasky * used on the remote machine for authentication. 824335640Shselasky * 825335640Shselasky * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication 826335640Shselasky * and it can be NULL. 827335640Shselasky */ 828335640Shselasky char *username; 829335640Shselasky /* 830335640Shselasky * \brief Zero-terminated string containing the password that has to be 831335640Shselasky * used on the remote machine for authentication. 832335640Shselasky * 833335640Shselasky * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication 834335640Shselasky * and it can be NULL. 835335640Shselasky */ 836335640Shselasky char *password; 837335640Shselasky}; 838335640Shselasky 839335640Shselasky/* 840335640Shselasky * This routine can open a savefile, a local device, or a device on 841335640Shselasky * a remote machine running an RPCAP server. 842335640Shselasky * 843335640Shselasky * For opening a savefile, the pcap_open_offline routines can be used, 844335640Shselasky * and will work just as well; code using them will work on more 845335640Shselasky * platforms than code using pcap_open() to open savefiles. 846335640Shselasky * 847335640Shselasky * For opening a local device, pcap_open_live() can be used; it supports 848335640Shselasky * most of the capabilities that pcap_open() supports, and code using it 849335640Shselasky * will work on more platforms than code using pcap_open(). pcap_create() 850335640Shselasky * and pcap_activate() can also be used; they support all capabilities 851335640Shselasky * that pcap_open() supports, except for the Windows-only 852335640Shselasky * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities. 853335640Shselasky * 854335640Shselasky * For opening a remote capture, pcap_open() is currently the only 855335640Shselasky * API available. 856335640Shselasky */ 857335640ShselaskyPCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags, 858335640Shselasky int read_timeout, struct pcap_rmtauth *auth, char *errbuf); 859335640ShselaskyPCAP_API int pcap_createsrcstr(char *source, int type, const char *host, 860335640Shselasky const char *port, const char *name, char *errbuf); 861335640ShselaskyPCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host, 862335640Shselasky char *port, char *name, char *errbuf); 863335640Shselasky 864335640Shselasky/* 865335640Shselasky * This routine can scan a directory for savefiles, list local capture 866335640Shselasky * devices, or list capture devices on a remote machine running an RPCAP 867335640Shselasky * server. 868335640Shselasky * 869335640Shselasky * For scanning for savefiles, it can be used on both UN*X systems and 870335640Shselasky * Windows systems; for each directory entry it sees, it tries to open 871335640Shselasky * the file as a savefile using pcap_open_offline(), and only includes 872335640Shselasky * it in the list of files if the open succeeds, so it filters out 873335640Shselasky * files for which the user doesn't have read permission, as well as 874335640Shselasky * files that aren't valid savefiles readable by libpcap. 875335640Shselasky * 876335640Shselasky * For listing local capture devices, it's just a wrapper around 877335640Shselasky * pcap_findalldevs(); code using pcap_findalldevs() will work on more 878335640Shselasky * platforms than code using pcap_findalldevs_ex(). 879335640Shselasky * 880335640Shselasky * For listing remote capture devices, pcap_findalldevs_ex() is currently 881335640Shselasky * the only API available. 882335640Shselasky */ 883356341ScyPCAP_API int pcap_findalldevs_ex(const char *source, 884356341Scy struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf); 885335640Shselasky 886335640Shselasky/* 887335640Shselasky * Sampling methods. 888335640Shselasky * 889335640Shselasky * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex() 890335640Shselasky * to see only a sample of packets, rather than all packets. 891335640Shselasky * 892335640Shselasky * Currently, they work only on Windows local captures. 893335640Shselasky */ 894335640Shselasky 895335640Shselasky/* 896335640Shselasky * Specifies that no sampling is to be done on the current capture. 897335640Shselasky * 898335640Shselasky * In this case, no sampling algorithms are applied to the current capture. 899335640Shselasky */ 900335640Shselasky#define PCAP_SAMP_NOSAMP 0 901335640Shselasky 902335640Shselasky/* 903335640Shselasky * Specifies that only 1 out of N packets must be returned to the user. 904335640Shselasky * 905335640Shselasky * In this case, the 'value' field of the 'pcap_samp' structure indicates the 906335640Shselasky * number of packets (minus 1) that must be discarded before one packet got 907335640Shselasky * accepted. 908335640Shselasky * In other words, if 'value = 10', the first packet is returned to the 909335640Shselasky * caller, while the following 9 are discarded. 910335640Shselasky */ 911335640Shselasky#define PCAP_SAMP_1_EVERY_N 1 912335640Shselasky 913335640Shselasky/* 914335640Shselasky * Specifies that we have to return 1 packet every N milliseconds. 915335640Shselasky * 916335640Shselasky * In this case, the 'value' field of the 'pcap_samp' structure indicates 917335640Shselasky * the 'waiting time' in milliseconds before one packet got accepted. 918335640Shselasky * In other words, if 'value = 10', the first packet is returned to the 919335640Shselasky * caller; the next returned one will be the first packet that arrives 920335640Shselasky * when 10ms have elapsed. 921335640Shselasky */ 922335640Shselasky#define PCAP_SAMP_FIRST_AFTER_N_MS 2 923335640Shselasky 924335640Shselasky/* 925335640Shselasky * This structure defines the information related to sampling. 926335640Shselasky * 927335640Shselasky * In case the sampling is requested, the capturing device should read 928335640Shselasky * only a subset of the packets coming from the source. The returned packets 929335640Shselasky * depend on the sampling parameters. 930335640Shselasky * 931335640Shselasky * WARNING: The sampling process is applied *after* the filtering process. 932335640Shselasky * In other words, packets are filtered first, then the sampling process 933335640Shselasky * selects a subset of the 'filtered' packets and it returns them to the 934335640Shselasky * caller. 935335640Shselasky */ 936335640Shselaskystruct pcap_samp 937335640Shselasky{ 938335640Shselasky /* 939335640Shselasky * Method used for sampling; see above. 940335640Shselasky */ 941335640Shselasky int method; 942335640Shselasky 943335640Shselasky /* 944335640Shselasky * This value depends on the sampling method defined. 945335640Shselasky * For its meaning, see above. 946335640Shselasky */ 947335640Shselasky int value; 948335640Shselasky}; 949335640Shselasky 950335640Shselasky/* 951335640Shselasky * New functions. 952335640Shselasky */ 953335640ShselaskyPCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p); 954335640Shselasky 955335640Shselasky/* 956335640Shselasky * RPCAP active mode. 957335640Shselasky */ 958335640Shselasky 959335640Shselasky/* Maximum length of an host name (needed for the RPCAP active mode) */ 960335640Shselasky#define RPCAP_HOSTLIST_SIZE 1024 961335640Shselasky 962335640ShselaskyPCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port, 963335640Shselasky const char *hostlist, char *connectinghost, 964335640Shselasky struct pcap_rmtauth *auth, char *errbuf); 965335640ShselaskyPCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size, 966335640Shselasky char *errbuf); 967335640ShselaskyPCAP_API int pcap_remoteact_close(const char *host, char *errbuf); 968335640ShselaskyPCAP_API void pcap_remoteact_cleanup(void); 969335640Shselasky#endif /* Remote capture is disabled on FreeBSD */ 970335640Shselasky 971335640Shselasky#ifdef __cplusplus 972335640Shselasky} 973335640Shselasky#endif 974335640Shselasky 975335640Shselasky#endif /* lib_pcap_pcap_h */ 976