Blame pcap/pcap.h

Packit 209cc3
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
Packit 209cc3
/*
Packit 209cc3
 * Copyright (c) 1993, 1994, 1995, 1996, 1997
Packit 209cc3
 *	The Regents of the University of California.  All rights reserved.
Packit 209cc3
 *
Packit 209cc3
 * Redistribution and use in source and binary forms, with or without
Packit 209cc3
 * modification, are permitted provided that the following conditions
Packit 209cc3
 * are met:
Packit 209cc3
 * 1. Redistributions of source code must retain the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer.
Packit 209cc3
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 209cc3
 *    notice, this list of conditions and the following disclaimer in the
Packit 209cc3
 *    documentation and/or other materials provided with the distribution.
Packit 209cc3
 * 3. All advertising materials mentioning features or use of this software
Packit 209cc3
 *    must display the following acknowledgement:
Packit 209cc3
 *	This product includes software developed by the Computer Systems
Packit 209cc3
 *	Engineering Group at Lawrence Berkeley Laboratory.
Packit 209cc3
 * 4. Neither the name of the University nor of the Laboratory may be used
Packit 209cc3
 *    to endorse or promote products derived from this software without
Packit 209cc3
 *    specific prior written permission.
Packit 209cc3
 *
Packit 209cc3
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 209cc3
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 209cc3
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 209cc3
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 209cc3
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 209cc3
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 209cc3
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 209cc3
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 209cc3
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 209cc3
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 209cc3
 * SUCH DAMAGE.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Remote packet capture mechanisms and extensions from WinPcap:
Packit 209cc3
 *
Packit 209cc3
 * Copyright (c) 2002 - 2003
Packit 209cc3
 * NetGroup, Politecnico di Torino (Italy)
Packit 209cc3
 * All rights reserved.
Packit 209cc3
 *
Packit 209cc3
 * Redistribution and use in source and binary forms, with or without
Packit 209cc3
 * modification, are permitted provided that the following conditions
Packit 209cc3
 * are met:
Packit 209cc3
 *
Packit 209cc3
 * 1. Redistributions of source code must retain the above copyright
Packit 209cc3
 * notice, this list of conditions and the following disclaimer.
Packit 209cc3
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 209cc3
 * notice, this list of conditions and the following disclaimer in the
Packit 209cc3
 * documentation and/or other materials provided with the distribution.
Packit 209cc3
 * 3. Neither the name of the Politecnico di Torino nor the names of its
Packit 209cc3
 * contributors may be used to endorse or promote products derived from
Packit 209cc3
 * this software without specific prior written permission.
Packit 209cc3
 *
Packit 209cc3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 209cc3
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 209cc3
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 209cc3
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 209cc3
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 209cc3
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 209cc3
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 209cc3
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 209cc3
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 209cc3
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 209cc3
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 209cc3
 *
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#ifndef lib_pcap_pcap_h
Packit 209cc3
#define lib_pcap_pcap_h
Packit 209cc3
Packit 209cc3
#include <pcap/funcattrs.h>
Packit 209cc3
Packit 209cc3
#include <pcap/pcap-inttypes.h>
Packit 209cc3
Packit 209cc3
#if defined(_WIN32)
Packit 209cc3
  #include <winsock2.h>		/* u_int, u_char etc. */
Packit 209cc3
  #include <io.h>		/* _get_osfhandle() */
Packit 209cc3
#elif defined(MSDOS)
Packit 209cc3
  #include <sys/types.h>	/* u_int, u_char etc. */
Packit 209cc3
  #include <sys/socket.h>
Packit 209cc3
#else /* UN*X */
Packit 209cc3
  #include <sys/types.h>	/* u_int, u_char etc. */
Packit 209cc3
  #include <sys/time.h>
Packit 209cc3
#endif /* _WIN32/MSDOS/UN*X */
Packit 209cc3
Packit 209cc3
#include <pcap/socket.h>	/* for SOCKET, as the active-mode rpcap APIs use it */
Packit 209cc3
Packit 209cc3
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
Packit 209cc3
#include <pcap/bpf.h>
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
#include <stdio.h>
Packit 209cc3
Packit 209cc3
#ifdef __cplusplus
Packit 209cc3
extern "C" {
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Version number of the current version of the pcap file format.
Packit 209cc3
 *
Packit 209cc3
 * NOTE: this is *NOT* the version number of the libpcap library.
Packit 209cc3
 * To fetch the version information for the version of libpcap
Packit 209cc3
 * you're using, use pcap_lib_version().
Packit 209cc3
 */
Packit 209cc3
#define PCAP_VERSION_MAJOR 2
Packit 209cc3
#define PCAP_VERSION_MINOR 4
Packit 209cc3
Packit 209cc3
#define PCAP_ERRBUF_SIZE 256
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Compatibility for systems that have a bpf.h that
Packit 209cc3
 * predates the bpf typedefs for 64-bit support.
Packit 209cc3
 */
Packit 209cc3
#if BPF_RELEASE - 0 < 199406
Packit 209cc3
typedef	int bpf_int32;
Packit 209cc3
typedef	u_int bpf_u_int32;
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
typedef struct pcap pcap_t;
Packit 209cc3
typedef struct pcap_dumper pcap_dumper_t;
Packit 209cc3
typedef struct pcap_if pcap_if_t;
Packit 209cc3
typedef struct pcap_addr pcap_addr_t;
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The first record in the file contains saved values for some
Packit 209cc3
 * of the flags used in the printout phases of tcpdump.
Packit 209cc3
 * Many fields here are 32 bit ints so compilers won't insert unwanted
Packit 209cc3
 * padding; these files need to be interchangeable across architectures.
Packit 209cc3
 *
Packit 209cc3
 * Do not change the layout of this structure, in any way (this includes
Packit 209cc3
 * changes that only affect the length of fields in this structure).
Packit 209cc3
 *
Packit 209cc3
 * Also, do not change the interpretation of any of the members of this
Packit 209cc3
 * structure, in any way (this includes using values other than
Packit 209cc3
 * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
Packit 209cc3
 * field).
Packit 209cc3
 *
Packit 209cc3
 * Instead:
Packit 209cc3
 *
Packit 209cc3
 *	introduce a new structure for the new format, if the layout
Packit 209cc3
 *	of the structure changed;
Packit 209cc3
 *
Packit 209cc3
 *	send mail to "tcpdump-workers@lists.tcpdump.org", requesting
Packit 209cc3
 *	a new magic number for your new capture file format, and, when
Packit 209cc3
 *	you get the new magic number, put it in "savefile.c";
Packit 209cc3
 *
Packit 209cc3
 *	use that magic number for save files with the changed file
Packit 209cc3
 *	header;
Packit 209cc3
 *
Packit 209cc3
 *	make the code in "savefile.c" capable of reading files with
Packit 209cc3
 *	the old file header as well as files with the new file header
Packit 209cc3
 *	(using the magic number to determine the header format).
Packit 209cc3
 *
Packit 209cc3
 * Then supply the changes by forking the branch at
Packit 209cc3
 *
Packit 209cc3
 *	https://github.com/the-tcpdump-group/libpcap/issues
Packit 209cc3
 *
Packit 209cc3
 * and issuing a pull request, so that future versions of libpcap and
Packit 209cc3
 * programs that use it (such as tcpdump) will be able to read your new
Packit 209cc3
 * capture file format.
Packit 209cc3
 */
Packit 209cc3
struct pcap_file_header {
Packit 209cc3
	bpf_u_int32 magic;
Packit 209cc3
	u_short version_major;
Packit 209cc3
	u_short version_minor;
Packit 209cc3
	bpf_int32 thiszone;	/* gmt to local correction */
Packit 209cc3
	bpf_u_int32 sigfigs;	/* accuracy of timestamps */
Packit 209cc3
	bpf_u_int32 snaplen;	/* max length saved portion of each pkt */
Packit 209cc3
	bpf_u_int32 linktype;	/* data link type (LINKTYPE_*) */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Macros for the value returned by pcap_datalink_ext().
Packit 209cc3
 *
Packit 209cc3
 * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
Packit 209cc3
 * gives the FCS length of packets in the capture.
Packit 209cc3
 */
Packit 209cc3
#define LT_FCS_LENGTH_PRESENT(x)	((x) & 0x04000000)
Packit 209cc3
#define LT_FCS_LENGTH(x)		(((x) & 0xF0000000) >> 28)
Packit 209cc3
#define LT_FCS_DATALINK_EXT(x)		((((x) & 0xF) << 28) | 0x04000000)
Packit 209cc3
Packit 209cc3
typedef enum {
Packit 209cc3
       PCAP_D_INOUT = 0,
Packit 209cc3
       PCAP_D_IN,
Packit 209cc3
       PCAP_D_OUT
Packit 209cc3
} pcap_direction_t;
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Generic per-packet information, as supplied by libpcap.
Packit 209cc3
 *
Packit 209cc3
 * The time stamp can and should be a "struct timeval", regardless of
Packit 209cc3
 * whether your system supports 32-bit tv_sec in "struct timeval",
Packit 209cc3
 * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
Packit 209cc3
 * and 64-bit applications.  The on-disk format of savefiles uses 32-bit
Packit 209cc3
 * tv_sec (and tv_usec); this structure is irrelevant to that.  32-bit
Packit 209cc3
 * and 64-bit versions of libpcap, even if they're on the same platform,
Packit 209cc3
 * should supply the appropriate version of "struct timeval", even if
Packit 209cc3
 * that's not what the underlying packet capture mechanism supplies.
Packit 209cc3
 */
Packit 209cc3
struct pcap_pkthdr {
Packit 209cc3
	struct timeval ts;	/* time stamp */
Packit 209cc3
	bpf_u_int32 caplen;	/* length of portion present */
Packit 209cc3
	bpf_u_int32 len;	/* length this packet (off wire) */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * As returned by the pcap_stats()
Packit 209cc3
 */
Packit 209cc3
struct pcap_stat {
Packit 209cc3
	u_int ps_recv;		/* number of packets received */
Packit 209cc3
	u_int ps_drop;		/* number of packets dropped */
Packit 209cc3
	u_int ps_ifdrop;	/* drops by interface -- only supported on some platforms */
Packit 209cc3
#ifdef _WIN32
Packit 209cc3
	u_int ps_capt;		/* number of packets that reach the application */
Packit 209cc3
	u_int ps_sent;		/* number of packets sent by the server on the network */
Packit 209cc3
	u_int ps_netdrop;	/* number of packets lost on the network */
Packit 209cc3
#endif /* _WIN32 */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
#ifdef MSDOS
Packit 209cc3
/*
Packit 209cc3
 * As returned by the pcap_stats_ex()
Packit 209cc3
 */
Packit 209cc3
struct pcap_stat_ex {
Packit 209cc3
       u_long  rx_packets;        /* total packets received       */
Packit 209cc3
       u_long  tx_packets;        /* total packets transmitted    */
Packit 209cc3
       u_long  rx_bytes;          /* total bytes received         */
Packit 209cc3
       u_long  tx_bytes;          /* total bytes transmitted      */
Packit 209cc3
       u_long  rx_errors;         /* bad packets received         */
Packit 209cc3
       u_long  tx_errors;         /* packet transmit problems     */
Packit 209cc3
       u_long  rx_dropped;        /* no space in Rx buffers       */
Packit 209cc3
       u_long  tx_dropped;        /* no space available for Tx    */
Packit 209cc3
       u_long  multicast;         /* multicast packets received   */
Packit 209cc3
       u_long  collisions;
Packit 209cc3
Packit 209cc3
       /* detailed rx_errors: */
Packit 209cc3
       u_long  rx_length_errors;
Packit 209cc3
       u_long  rx_over_errors;    /* receiver ring buff overflow  */
Packit 209cc3
       u_long  rx_crc_errors;     /* recv'd pkt with crc error    */
Packit 209cc3
       u_long  rx_frame_errors;   /* recv'd frame alignment error */
Packit 209cc3
       u_long  rx_fifo_errors;    /* recv'r fifo overrun          */
Packit 209cc3
       u_long  rx_missed_errors;  /* recv'r missed packet         */
Packit 209cc3
Packit 209cc3
       /* detailed tx_errors */
Packit 209cc3
       u_long  tx_aborted_errors;
Packit 209cc3
       u_long  tx_carrier_errors;
Packit 209cc3
       u_long  tx_fifo_errors;
Packit 209cc3
       u_long  tx_heartbeat_errors;
Packit 209cc3
       u_long  tx_window_errors;
Packit 209cc3
     };
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Item in a list of interfaces.
Packit 209cc3
 */
Packit 209cc3
struct pcap_if {
Packit 209cc3
	struct pcap_if *next;
Packit 209cc3
	char *name;		/* name to hand to "pcap_open_live()" */
Packit 209cc3
	char *description;	/* textual description of interface, or NULL */
Packit 209cc3
	struct pcap_addr *addresses;
Packit 209cc3
	bpf_u_int32 flags;	/* PCAP_IF_ interface flags */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
#define PCAP_IF_LOOPBACK				0x00000001	/* interface is loopback */
Packit 209cc3
#define PCAP_IF_UP					0x00000002	/* interface is up */
Packit 209cc3
#define PCAP_IF_RUNNING					0x00000004	/* interface is running */
Packit 209cc3
#define PCAP_IF_WIRELESS				0x00000008	/* interface is wireless (*NOT* necessarily Wi-Fi!) */
Packit 209cc3
#define PCAP_IF_CONNECTION_STATUS			0x00000030	/* connection status: */
Packit 209cc3
#define PCAP_IF_CONNECTION_STATUS_UNKNOWN		0x00000000	/* unknown */
Packit 209cc3
#define PCAP_IF_CONNECTION_STATUS_CONNECTED		0x00000010	/* connected */
Packit 209cc3
#define PCAP_IF_CONNECTION_STATUS_DISCONNECTED		0x00000020	/* disconnected */
Packit 209cc3
#define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE	0x00000030	/* not applicable */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Representation of an interface address.
Packit 209cc3
 */
Packit 209cc3
struct pcap_addr {
Packit 209cc3
	struct pcap_addr *next;
Packit 209cc3
	struct sockaddr *addr;		/* address */
Packit 209cc3
	struct sockaddr *netmask;	/* netmask for that address */
Packit 209cc3
	struct sockaddr *broadaddr;	/* broadcast address for that address */
Packit 209cc3
	struct sockaddr *dstaddr;	/* P2P destination address for that address */
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
Packit 209cc3
			     const u_char *);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Error codes for the pcap API.
Packit 209cc3
 * These will all be negative, so you can check for the success or
Packit 209cc3
 * failure of a call that returns these codes by checking for a
Packit 209cc3
 * negative value.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_ERROR			-1	/* generic error code */
Packit 209cc3
#define PCAP_ERROR_BREAK		-2	/* loop terminated by pcap_breakloop */
Packit 209cc3
#define PCAP_ERROR_NOT_ACTIVATED	-3	/* the capture needs to be activated */
Packit 209cc3
#define PCAP_ERROR_ACTIVATED		-4	/* the operation can't be performed on already activated captures */
Packit 209cc3
#define PCAP_ERROR_NO_SUCH_DEVICE	-5	/* no such device exists */
Packit 209cc3
#define PCAP_ERROR_RFMON_NOTSUP		-6	/* this device doesn't support rfmon (monitor) mode */
Packit 209cc3
#define PCAP_ERROR_NOT_RFMON		-7	/* operation supported only in monitor mode */
Packit 209cc3
#define PCAP_ERROR_PERM_DENIED		-8	/* no permission to open the device */
Packit 209cc3
#define PCAP_ERROR_IFACE_NOT_UP		-9	/* interface isn't up */
Packit 209cc3
#define PCAP_ERROR_CANTSET_TSTAMP_TYPE	-10	/* this device doesn't support setting the time stamp type */
Packit 209cc3
#define PCAP_ERROR_PROMISC_PERM_DENIED	-11	/* you don't have permission to capture in promiscuous mode */
Packit 209cc3
#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12  /* the requested time stamp precision is not supported */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Warning codes for the pcap API.
Packit 209cc3
 * These will all be positive and non-zero, so they won't look like
Packit 209cc3
 * errors.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_WARNING			1	/* generic warning code */
Packit 209cc3
#define PCAP_WARNING_PROMISC_NOTSUP	2	/* this device doesn't support promiscuous mode */
Packit 209cc3
#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP	3	/* the requested time stamp type is not supported */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Value to pass to pcap_compile() as the netmask if you don't know what
Packit 209cc3
 * the netmask is.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_NETMASK_UNKNOWN	0xffffffff
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * We're deprecating pcap_lookupdev() for various reasons (not
Packit 209cc3
 * thread-safe, can behave weirdly with WinPcap).  Callers
Packit 209cc3
 * should use pcap_findalldevs() and use the first device.
Packit 209cc3
 */
Packit 209cc3
PCAP_API char	*pcap_lookupdev(char *)
Packit 209cc3
PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device");
Packit 209cc3
Packit 209cc3
PCAP_API int	pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
Packit 209cc3
Packit 209cc3
PCAP_API pcap_t	*pcap_create(const char *, char *);
Packit 209cc3
PCAP_API int	pcap_set_snaplen(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_promisc(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_can_set_rfmon(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_set_rfmon(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_timeout(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_tstamp_type(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_immediate_mode(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_buffer_size(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_set_tstamp_precision(pcap_t *, int);
Packit 209cc3
PCAP_API int	pcap_get_tstamp_precision(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_activate(pcap_t *);
Packit 209cc3
Packit 209cc3
PCAP_API int	pcap_list_tstamp_types(pcap_t *, int **);
Packit 209cc3
PCAP_API void	pcap_free_tstamp_types(int *);
Packit 209cc3
PCAP_API int	pcap_tstamp_type_name_to_val(const char *);
Packit 209cc3
PCAP_API const char *pcap_tstamp_type_val_to_name(int);
Packit 209cc3
PCAP_API const char *pcap_tstamp_type_val_to_description(int);
Packit 209cc3
Packit 209cc3
#ifdef __linux__
Packit 209cc3
PCAP_API int	pcap_set_protocol_linux(pcap_t *, int);
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Time stamp types.
Packit 209cc3
 * Not all systems and interfaces will necessarily support all of these.
Packit 209cc3
 *
Packit 209cc3
 * A system that supports PCAP_TSTAMP_HOST is offering time stamps
Packit 209cc3
 * provided by the host machine, rather than by the capture device,
Packit 209cc3
 * but not committing to any characteristics of the time stamp;
Packit 209cc3
 * it will not offer any of the PCAP_TSTAMP_HOST_ subtypes.
Packit 209cc3
 *
Packit 209cc3
 * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine,
Packit 209cc3
 * that's low-precision but relatively cheap to fetch; it's normally done
Packit 209cc3
 * using the system clock, so it's normally synchronized with times you'd
Packit 209cc3
 * fetch from system calls.
Packit 209cc3
 *
Packit 209cc3
 * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine,
Packit 209cc3
 * that's high-precision; it might be more expensive to fetch.  It might
Packit 209cc3
 * or might not be synchronized with the system clock, and might have
Packit 209cc3
 * problems with time stamps for packets received on different CPUs,
Packit 209cc3
 * depending on the platform.
Packit 209cc3
 *
Packit 209cc3
 * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the
Packit 209cc3
 * capture device; it's synchronized with the system clock.
Packit 209cc3
 *
Packit 209cc3
 * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by
Packit 209cc3
 * the capture device; it's not synchronized with the system clock.
Packit 209cc3
 *
Packit 209cc3
 * Note that time stamps synchronized with the system clock can go
Packit 209cc3
 * backwards, as the system clock can go backwards.  If a clock is
Packit 209cc3
 * not in sync with the system clock, that could be because the
Packit 209cc3
 * system clock isn't keeping accurate time, because the other
Packit 209cc3
 * clock isn't keeping accurate time, or both.
Packit 209cc3
 *
Packit 209cc3
 * Note that host-provided time stamps generally correspond to the
Packit 209cc3
 * time when the time-stamping code sees the packet; this could
Packit 209cc3
 * be some unknown amount of time after the first or last bit of
Packit 209cc3
 * the packet is received by the network adapter, due to batching
Packit 209cc3
 * of interrupts for packet arrival, queueing delays, etc..
Packit 209cc3
 */
Packit 209cc3
#define PCAP_TSTAMP_HOST		0	/* host-provided, unknown characteristics */
Packit 209cc3
#define PCAP_TSTAMP_HOST_LOWPREC	1	/* host-provided, low precision */
Packit 209cc3
#define PCAP_TSTAMP_HOST_HIPREC		2	/* host-provided, high precision */
Packit 209cc3
#define PCAP_TSTAMP_ADAPTER		3	/* device-provided, synced with the system clock */
Packit 209cc3
#define PCAP_TSTAMP_ADAPTER_UNSYNCED	4	/* device-provided, not synced with the system clock */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Time stamp resolution types.
Packit 209cc3
 * Not all systems and interfaces will necessarily support all of these
Packit 209cc3
 * resolutions when doing live captures; all of them can be requested
Packit 209cc3
 * when reading a savefile.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_TSTAMP_PRECISION_MICRO	0	/* use timestamps with microsecond precision, default */
Packit 209cc3
#define PCAP_TSTAMP_PRECISION_NANO	1	/* use timestamps with nanosecond precision */
Packit 209cc3
Packit 209cc3
PCAP_API pcap_t	*pcap_open_live(const char *, int, int, int, char *);
Packit 209cc3
PCAP_API pcap_t	*pcap_open_dead(int, int);
Packit 209cc3
PCAP_API pcap_t	*pcap_open_dead_with_tstamp_precision(int, int, u_int);
Packit 209cc3
PCAP_API pcap_t	*pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
Packit 209cc3
PCAP_API pcap_t	*pcap_open_offline(const char *, char *);
Packit 209cc3
#ifdef _WIN32
Packit 209cc3
  PCAP_API pcap_t  *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
Packit 209cc3
  PCAP_API pcap_t  *pcap_hopen_offline(intptr_t, char *);
Packit 209cc3
  /*
Packit 209cc3
   * If we're building libpcap, these are internal routines in savefile.c,
Packit 209cc3
   * so we must not define them as macros.
Packit 209cc3
   *
Packit 209cc3
   * If we're not building libpcap, given that the version of the C runtime
Packit 209cc3
   * with which libpcap was built might be different from the version
Packit 209cc3
   * of the C runtime with which an application using libpcap was built,
Packit 209cc3
   * and that a FILE structure may differ between the two versions of the
Packit 209cc3
   * C runtime, calls to _fileno() must use the version of _fileno() in
Packit 209cc3
   * the C runtime used to open the FILE *, not the version in the C
Packit 209cc3
   * runtime with which libpcap was built.  (Maybe once the Universal CRT
Packit 209cc3
   * rules the world, this will cease to be a problem.)
Packit 209cc3
   */
Packit 209cc3
  #ifndef BUILDING_PCAP
Packit 209cc3
    #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
Packit 209cc3
	pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
Packit 209cc3
    #define pcap_fopen_offline(f,b) \
Packit 209cc3
	pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
Packit 209cc3
  #endif
Packit 209cc3
#else /*_WIN32*/
Packit 209cc3
  PCAP_API pcap_t	*pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
Packit 209cc3
  PCAP_API pcap_t	*pcap_fopen_offline(FILE *, char *);
Packit 209cc3
#endif /*_WIN32*/
Packit 209cc3
Packit 209cc3
PCAP_API void	pcap_close(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_loop(pcap_t *, int, pcap_handler, u_char *);
Packit 209cc3
PCAP_API int	pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
Packit 209cc3
PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
Packit 209cc3
PCAP_API int 	pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
Packit 209cc3
PCAP_API void	pcap_breakloop(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_stats(pcap_t *, struct pcap_stat *);
Packit 209cc3
PCAP_API int	pcap_setfilter(pcap_t *, struct bpf_program *);
Packit 209cc3
PCAP_API int 	pcap_setdirection(pcap_t *, pcap_direction_t);
Packit 209cc3
PCAP_API int	pcap_getnonblock(pcap_t *, char *);
Packit 209cc3
PCAP_API int	pcap_setnonblock(pcap_t *, int, char *);
Packit 209cc3
PCAP_API int	pcap_inject(pcap_t *, const void *, size_t);
Packit 209cc3
PCAP_API int	pcap_sendpacket(pcap_t *, const u_char *, int);
Packit 209cc3
PCAP_API const char *pcap_statustostr(int);
Packit 209cc3
PCAP_API const char *pcap_strerror(int);
Packit 209cc3
PCAP_API char	*pcap_geterr(pcap_t *);
Packit 209cc3
PCAP_API void	pcap_perror(pcap_t *, const char *);
Packit 209cc3
PCAP_API int	pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
Packit 209cc3
	    bpf_u_int32);
Packit 209cc3
PCAP_API int	pcap_compile_nopcap(int, int, struct bpf_program *,
Packit 209cc3
	    const char *, int, bpf_u_int32);
Packit 209cc3
PCAP_API void	pcap_freecode(struct bpf_program *);
Packit 209cc3
PCAP_API int	pcap_offline_filter(const struct bpf_program *,
Packit 209cc3
	    const struct pcap_pkthdr *, const u_char *);
Packit 209cc3
PCAP_API int	pcap_datalink(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_datalink_ext(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_list_datalinks(pcap_t *, int **);
Packit 209cc3
PCAP_API int	pcap_set_datalink(pcap_t *, int);
Packit 209cc3
PCAP_API void	pcap_free_datalinks(int *);
Packit 209cc3
PCAP_API int	pcap_datalink_name_to_val(const char *);
Packit 209cc3
PCAP_API const char *pcap_datalink_val_to_name(int);
Packit 209cc3
PCAP_API const char *pcap_datalink_val_to_description(int);
Packit 209cc3
PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
Packit 209cc3
PCAP_API int	pcap_snapshot(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_is_swapped(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_major_version(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_minor_version(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_bufsize(pcap_t *);
Packit 209cc3
Packit 209cc3
/* XXX */
Packit 209cc3
PCAP_API FILE	*pcap_file(pcap_t *);
Packit 209cc3
PCAP_API int	pcap_fileno(pcap_t *);
Packit 209cc3
Packit 209cc3
#ifdef _WIN32
Packit 209cc3
  PCAP_API int	pcap_wsockinit(void);
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
Packit 209cc3
#ifdef _WIN32
Packit 209cc3
  PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
Packit 209cc3
  /*
Packit 209cc3
   * If we're building libpcap, this is an internal routine in sf-pcap.c, so
Packit 209cc3
   * we must not define it as a macro.
Packit 209cc3
   *
Packit 209cc3
   * If we're not building libpcap, given that the version of the C runtime
Packit 209cc3
   * with which libpcap was built might be different from the version
Packit 209cc3
   * of the C runtime with which an application using libpcap was built,
Packit 209cc3
   * and that a FILE structure may differ between the two versions of the
Packit 209cc3
   * C runtime, calls to _fileno() must use the version of _fileno() in
Packit 209cc3
   * the C runtime used to open the FILE *, not the version in the C
Packit 209cc3
   * runtime with which libpcap was built.  (Maybe once the Universal CRT
Packit 209cc3
   * rules the world, this will cease to be a problem.)
Packit 209cc3
   */
Packit 209cc3
  #ifndef BUILDING_PCAP
Packit 209cc3
    #define pcap_dump_fopen(p,f) \
Packit 209cc3
	pcap_dump_hopen(p, _get_osfhandle(_fileno(f)))
Packit 209cc3
  #endif
Packit 209cc3
#else /*_WIN32*/
Packit 209cc3
  PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
Packit 209cc3
#endif /*_WIN32*/
Packit 209cc3
PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
Packit 209cc3
PCAP_API FILE	*pcap_dump_file(pcap_dumper_t *);
Packit 209cc3
PCAP_API long	pcap_dump_ftell(pcap_dumper_t *);
Packit 209cc3
PCAP_API int64_t	pcap_dump_ftell64(pcap_dumper_t *);
Packit 209cc3
PCAP_API int	pcap_dump_flush(pcap_dumper_t *);
Packit 209cc3
PCAP_API void	pcap_dump_close(pcap_dumper_t *);
Packit 209cc3
PCAP_API void	pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
Packit 209cc3
Packit 209cc3
PCAP_API int	pcap_findalldevs(pcap_if_t **, char *);
Packit 209cc3
PCAP_API void	pcap_freealldevs(pcap_if_t *);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * We return a pointer to the version string, rather than exporting the
Packit 209cc3
 * version string directly.
Packit 209cc3
 *
Packit 209cc3
 * On at least some UNIXes, if you import data from a shared library into
Packit 209cc3
 * an program, the data is bound into the program binary, so if the string
Packit 209cc3
 * in the version of the library with which the program was linked isn't
Packit 209cc3
 * the same as the string in the version of the library with which the
Packit 209cc3
 * program is being run, various undesirable things may happen (warnings,
Packit 209cc3
 * the string being the one from the version of the library with which the
Packit 209cc3
 * program was linked, or even weirder things, such as the string being the
Packit 209cc3
 * one from the library but being truncated).
Packit 209cc3
 *
Packit 209cc3
 * On Windows, the string is constructed at run time.
Packit 209cc3
 */
Packit 209cc3
PCAP_API const char *pcap_lib_version(void);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * On at least some versions of NetBSD and QNX, we don't want to declare
Packit 209cc3
 * bpf_filter() here, as it's also be declared in <net/bpf.h>, with a
Packit 209cc3
 * different signature, but, on other BSD-flavored UN*Xes, it's not
Packit 209cc3
 * declared in <net/bpf.h>, so we *do* want to declare it here, so it's
Packit 209cc3
 * declared when we build pcap-bpf.c.
Packit 209cc3
 */
Packit 209cc3
#if !defined(__NetBSD__) && !defined(__QNX__)
Packit 209cc3
  PCAP_API u_int	bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
Packit 209cc3
#endif
Packit 209cc3
PCAP_API int	bpf_validate(const struct bpf_insn *f, int len);
Packit 209cc3
PCAP_API char	*bpf_image(const struct bpf_insn *, int);
Packit 209cc3
PCAP_API void	bpf_dump(const struct bpf_program *, int);
Packit 209cc3
Packit 209cc3
#if defined(_WIN32)
Packit 209cc3
Packit 209cc3
  /*
Packit 209cc3
   * Win32 definitions
Packit 209cc3
   */
Packit 209cc3
Packit 209cc3
  /*!
Packit 209cc3
    \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
Packit 209cc3
  */
Packit 209cc3
  struct pcap_send_queue
Packit 209cc3
  {
Packit 209cc3
	u_int maxlen;	/* Maximum size of the queue, in bytes. This
Packit 209cc3
			   variable contains the size of the buffer field. */
Packit 209cc3
	u_int len;	/* Current size of the queue, in bytes. */
Packit 209cc3
	char *buffer;	/* Buffer containing the packets to be sent. */
Packit 209cc3
  };
Packit 209cc3
Packit 209cc3
  typedef struct pcap_send_queue pcap_send_queue;
Packit 209cc3
Packit 209cc3
  /*!
Packit 209cc3
    \brief This typedef is a support for the pcap_get_airpcap_handle() function
Packit 209cc3
  */
Packit 209cc3
  #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
Packit 209cc3
    #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
Packit 209cc3
    typedef struct _AirpcapHandle *PAirpcapHandle;
Packit 209cc3
  #endif
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_setbuff(pcap_t *p, int dim);
Packit 209cc3
  PCAP_API int pcap_setmode(pcap_t *p, int mode);
Packit 209cc3
  PCAP_API int pcap_setmintocopy(pcap_t *p, int size);
Packit 209cc3
Packit 209cc3
  PCAP_API HANDLE pcap_getevent(pcap_t *p);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
Packit 209cc3
  PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
Packit 209cc3
Packit 209cc3
  PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
Packit 209cc3
Packit 209cc3
  PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
Packit 209cc3
Packit 209cc3
  PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
Packit 209cc3
Packit 209cc3
  PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_setuserbuffer(pcap_t *p, int size);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync);
Packit 209cc3
Packit 209cc3
  PCAP_API int pcap_start_oem(char* err_str, int flags);
Packit 209cc3
Packit 209cc3
  PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
Packit 209cc3
Packit 209cc3
  #define MODE_CAPT 0
Packit 209cc3
  #define MODE_STAT 1
Packit 209cc3
  #define MODE_MON 2
Packit 209cc3
Packit 209cc3
#elif defined(MSDOS)
Packit 209cc3
Packit 209cc3
  /*
Packit 209cc3
   * MS-DOS definitions
Packit 209cc3
   */
Packit 209cc3
Packit 209cc3
  PCAP_API int  pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
Packit 209cc3
  PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
Packit 209cc3
  PCAP_API u_long pcap_mac_packets (void);
Packit 209cc3
Packit 209cc3
#else /* UN*X */
Packit 209cc3
Packit 209cc3
  /*
Packit 209cc3
   * UN*X definitions
Packit 209cc3
   */
Packit 209cc3
Packit 209cc3
  PCAP_API int	pcap_get_selectable_fd(pcap_t *);
Packit 209cc3
  PCAP_API struct timeval *pcap_get_required_select_timeout(pcap_t *);
Packit 209cc3
Packit 209cc3
#endif /* _WIN32/MSDOS/UN*X */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Remote capture definitions.
Packit 209cc3
 *
Packit 209cc3
 * These routines are only present if libpcap has been configured to
Packit 209cc3
 * include remote capture support.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The maximum buffer size in which address, port, interface names are kept.
Packit 209cc3
 *
Packit 209cc3
 * In case the adapter name or such is larger than this value, it is truncated.
Packit 209cc3
 * This is not used by the user; however it must be aware that an hostname / interface
Packit 209cc3
 * name longer than this value will be truncated.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_BUF_SIZE 1024
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The type of input source, passed to pcap_open().
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SRC_FILE		2	/* local savefile */
Packit 209cc3
#define PCAP_SRC_IFLOCAL	3	/* local network interface */
Packit 209cc3
#define PCAP_SRC_IFREMOTE	4	/* interface on a remote host, using RPCAP */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * The formats allowed by pcap_open() are the following:
Packit 209cc3
 * - file://path_and_filename [opens a local file]
Packit 209cc3
 * - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
Packit 209cc3
 * - rpcap://host/devicename [opens the selected device available on a remote host]
Packit 209cc3
 * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
Packit 209cc3
 * - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
Packit 209cc3
 * - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]
Packit 209cc3
 *
Packit 209cc3
 * The formats allowed by the pcap_findalldevs_ex() are the following:
Packit 209cc3
 * - file://folder/ [lists all the files in the given folder]
Packit 209cc3
 * - rpcap:// [lists all local adapters]
Packit 209cc3
 * - rpcap://host:port/ [lists the devices available on a remote host]
Packit 209cc3
 *
Packit 209cc3
 * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since
Packit 209cc3
 * IPv6 is fully supported, these are the allowed formats:
Packit 209cc3
 *
Packit 209cc3
 * - host (literal): e.g. host.foo.bar
Packit 209cc3
 * - host (numeric IPv4): e.g. 10.11.12.13
Packit 209cc3
 * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
Packit 209cc3
 * - host (numeric IPv6): e.g. [1:2:3::4]
Packit 209cc3
 * - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
Packit 209cc3
 *
Packit 209cc3
 * Here you find some allowed examples:
Packit 209cc3
 * - rpcap://host.foo.bar/devicename [everything literal, no port number]
Packit 209cc3
 * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
Packit 209cc3
 * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
Packit 209cc3
 * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
Packit 209cc3
 * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
Packit 209cc3
 * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
Packit 209cc3
 * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
Packit 209cc3
 * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * URL schemes for capture source.
Packit 209cc3
 */
Packit 209cc3
/*
Packit 209cc3
 * This string indicates that the user wants to open a capture from a
Packit 209cc3
 * local file.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SRC_FILE_STRING "file://"
Packit 209cc3
/*
Packit 209cc3
 * This string indicates that the user wants to open a capture from a
Packit 209cc3
 * network interface.  This string does not necessarily involve the use
Packit 209cc3
 * of the RPCAP protocol. If the interface required resides on the local
Packit 209cc3
 * host, the RPCAP protocol is not involved and the local functions are used.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SRC_IF_STRING "rpcap://"
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Flags to pass to pcap_open().
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies whether promiscuous mode is to be used.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_OPENFLAG_PROMISCUOUS		0x00000001
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies, for an RPCAP capture, whether the data transfer (in
Packit 209cc3
 * case of a remote capture) has to be done with UDP protocol.
Packit 209cc3
 *
Packit 209cc3
 * If it is '1' if you want a UDP data connection, '0' if you want
Packit 209cc3
 * a TCP data connection; control connection is always TCP-based.
Packit 209cc3
 * A UDP connection is much lighter, but it does not guarantee that all
Packit 209cc3
 * the captured packets arrive to the client workstation. Moreover,
Packit 209cc3
 * it could be harmful in case of network congestion.
Packit 209cc3
 * This flag is meaningless if the source is not a remote interface.
Packit 209cc3
 * In that case, it is simply ignored.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_OPENFLAG_DATATX_UDP		0x00000002
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies wheether the remote probe will capture its own generated
Packit 209cc3
 * traffic.
Packit 209cc3
 *
Packit 209cc3
 * In case the remote probe uses the same interface to capture traffic
Packit 209cc3
 * and to send data back to the caller, the captured traffic includes
Packit 209cc3
 * the RPCAP traffic as well.  If this flag is turned on, the RPCAP
Packit 209cc3
 * traffic is excluded from the capture, so that the trace returned
Packit 209cc3
 * back to the collector is does not include this traffic.
Packit 209cc3
 *
Packit 209cc3
 * Has no effect on local interfaces or savefiles.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_OPENFLAG_NOCAPTURE_RPCAP		0x00000004
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies whether the local adapter will capture its own generated traffic.
Packit 209cc3
 *
Packit 209cc3
 * This flag tells the underlying capture driver to drop the packets
Packit 209cc3
 * that were sent by itself.  This is useful when building applications
Packit 209cc3
 * such as bridges that should ignore the traffic they just sent.
Packit 209cc3
 *
Packit 209cc3
 * Supported only on Windows.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_OPENFLAG_NOCAPTURE_LOCAL		0x00000008
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This flag configures the adapter for maximum responsiveness.
Packit 209cc3
 *
Packit 209cc3
 * In presence of a large value for nbytes, WinPcap waits for the arrival
Packit 209cc3
 * of several packets before copying the data to the user. This guarantees
Packit 209cc3
 * a low number of system calls, i.e. lower processor usage, i.e. better
Packit 209cc3
 * performance, which is good for applications like sniffers. If the user
Packit 209cc3
 * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will
Packit 209cc3
 * copy the packets as soon as the application is ready to receive them.
Packit 209cc3
 * This is suggested for real time applications (such as, for example,
Packit 209cc3
 * a bridge) that need the best responsiveness.
Packit 209cc3
 *
Packit 209cc3
 * The equivalent with pcap_create()/pcap_activate() is "immediate mode".
Packit 209cc3
 */
Packit 209cc3
#define PCAP_OPENFLAG_MAX_RESPONSIVENESS	0x00000010
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Remote authentication methods.
Packit 209cc3
 * These are used in the 'type' member of the pcap_rmtauth structure.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * NULL authentication.
Packit 209cc3
 *
Packit 209cc3
 * The 'NULL' authentication has to be equal to 'zero', so that old
Packit 209cc3
 * applications can just put every field of struct pcap_rmtauth to zero,
Packit 209cc3
 * and it does work.
Packit 209cc3
 */
Packit 209cc3
#define RPCAP_RMTAUTH_NULL 0
Packit 209cc3
/*
Packit 209cc3
 * Username/password authentication.
Packit 209cc3
 *
Packit 209cc3
 * With this type of authentication, the RPCAP protocol will use the username/
Packit 209cc3
 * password provided to authenticate the user on the remote machine. If the
Packit 209cc3
 * authentication is successful (and the user has the right to open network
Packit 209cc3
 * devices) the RPCAP connection will continue; otherwise it will be dropped.
Packit 209cc3
 *
Packit 209cc3
 * *******NOTE********: the username and password are sent over the network
Packit 209cc3
 * to the capture server *IN CLEAR TEXT*.  Don't use this on a network
Packit 209cc3
 * that you don't completely control!  (And be *really* careful in your
Packit 209cc3
 * definition of "completely"!)
Packit 209cc3
 */
Packit 209cc3
#define RPCAP_RMTAUTH_PWD 1
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This structure keeps the information needed to autheticate the user
Packit 209cc3
 * on a remote machine.
Packit 209cc3
 *
Packit 209cc3
 * The remote machine can either grant or refuse the access according
Packit 209cc3
 * to the information provided.
Packit 209cc3
 * In case the NULL authentication is required, both 'username' and
Packit 209cc3
 * 'password' can be NULL pointers.
Packit 209cc3
 *
Packit 209cc3
 * This structure is meaningless if the source is not a remote interface;
Packit 209cc3
 * in that case, the functions which requires such a structure can accept
Packit 209cc3
 * a NULL pointer as well.
Packit 209cc3
 */
Packit 209cc3
struct pcap_rmtauth
Packit 209cc3
{
Packit 209cc3
	/*
Packit 209cc3
	 * \brief Type of the authentication required.
Packit 209cc3
	 *
Packit 209cc3
	 * In order to provide maximum flexibility, we can support different types
Packit 209cc3
	 * of authentication based on the value of this 'type' variable. The currently
Packit 209cc3
	 * supported authentication methods are defined into the
Packit 209cc3
	 * \link remote_auth_methods Remote Authentication Methods Section\endlink.
Packit 209cc3
	 */
Packit 209cc3
	int type;
Packit 209cc3
	/*
Packit 209cc3
	 * \brief Zero-terminated string containing the username that has to be
Packit 209cc3
	 * used on the remote machine for authentication.
Packit 209cc3
	 *
Packit 209cc3
	 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
Packit 209cc3
	 * and it can be NULL.
Packit 209cc3
	 */
Packit 209cc3
	char *username;
Packit 209cc3
	/*
Packit 209cc3
	 * \brief Zero-terminated string containing the password that has to be
Packit 209cc3
	 * used on the remote machine for authentication.
Packit 209cc3
	 *
Packit 209cc3
	 * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
Packit 209cc3
	 * and it can be NULL.
Packit 209cc3
	 */
Packit 209cc3
	char *password;
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This routine can open a savefile, a local device, or a device on
Packit 209cc3
 * a remote machine running an RPCAP server.
Packit 209cc3
 *
Packit 209cc3
 * For opening a savefile, the pcap_open_offline routines can be used,
Packit 209cc3
 * and will work just as well; code using them will work on more
Packit 209cc3
 * platforms than code using pcap_open() to open savefiles.
Packit 209cc3
 *
Packit 209cc3
 * For opening a local device, pcap_open_live() can be used; it supports
Packit 209cc3
 * most of the capabilities that pcap_open() supports, and code using it
Packit 209cc3
 * will work on more platforms than code using pcap_open().  pcap_create()
Packit 209cc3
 * and pcap_activate() can also be used; they support all capabilities
Packit 209cc3
 * that pcap_open() supports, except for the Windows-only
Packit 209cc3
 * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities.
Packit 209cc3
 *
Packit 209cc3
 * For opening a remote capture, pcap_open() is currently the only
Packit 209cc3
 * API available.
Packit 209cc3
 */
Packit 209cc3
PCAP_API pcap_t	*pcap_open(const char *source, int snaplen, int flags,
Packit 209cc3
	    int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
Packit 209cc3
PCAP_API int	pcap_createsrcstr(char *source, int type, const char *host,
Packit 209cc3
	    const char *port, const char *name, char *errbuf);
Packit 209cc3
PCAP_API int	pcap_parsesrcstr(const char *source, int *type, char *host,
Packit 209cc3
	    char *port, char *name, char *errbuf);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This routine can scan a directory for savefiles, list local capture
Packit 209cc3
 * devices, or list capture devices on a remote machine running an RPCAP
Packit 209cc3
 * server.
Packit 209cc3
 *
Packit 209cc3
 * For scanning for savefiles, it can be used on both UN*X systems and
Packit 209cc3
 * Windows systems; for each directory entry it sees, it tries to open
Packit 209cc3
 * the file as a savefile using pcap_open_offline(), and only includes
Packit 209cc3
 * it in the list of files if the open succeeds, so it filters out
Packit 209cc3
 * files for which the user doesn't have read permission, as well as
Packit 209cc3
 * files that aren't valid savefiles readable by libpcap.
Packit 209cc3
 *
Packit 209cc3
 * For listing local capture devices, it's just a wrapper around
Packit 209cc3
 * pcap_findalldevs(); code using pcap_findalldevs() will work on more
Packit 209cc3
 * platforms than code using pcap_findalldevs_ex().
Packit 209cc3
 *
Packit 209cc3
 * For listing remote capture devices, pcap_findalldevs_ex() is currently
Packit 209cc3
 * the only API available.
Packit 209cc3
 */
Packit 209cc3
PCAP_API int	pcap_findalldevs_ex(const char *source,
Packit 209cc3
	    struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Sampling methods.
Packit 209cc3
 *
Packit 209cc3
 * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex()
Packit 209cc3
 * to see only a sample of packets, rather than all packets.
Packit 209cc3
 *
Packit 209cc3
 * Currently, they work only on Windows local captures.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies that no sampling is to be done on the current capture.
Packit 209cc3
 *
Packit 209cc3
 * In this case, no sampling algorithms are applied to the current capture.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SAMP_NOSAMP	0
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies that only 1 out of N packets must be returned to the user.
Packit 209cc3
 *
Packit 209cc3
 * In this case, the 'value' field of the 'pcap_samp' structure indicates the
Packit 209cc3
 * number of packets (minus 1) that must be discarded before one packet got
Packit 209cc3
 * accepted.
Packit 209cc3
 * In other words, if 'value = 10', the first packet is returned to the
Packit 209cc3
 * caller, while the following 9 are discarded.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SAMP_1_EVERY_N	1
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * Specifies that we have to return 1 packet every N milliseconds.
Packit 209cc3
 *
Packit 209cc3
 * In this case, the 'value' field of the 'pcap_samp' structure indicates
Packit 209cc3
 * the 'waiting time' in milliseconds before one packet got accepted.
Packit 209cc3
 * In other words, if 'value = 10', the first packet is returned to the
Packit 209cc3
 * caller; the next returned one will be the first packet that arrives
Packit 209cc3
 * when 10ms have elapsed.
Packit 209cc3
 */
Packit 209cc3
#define PCAP_SAMP_FIRST_AFTER_N_MS 2
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * This structure defines the information related to sampling.
Packit 209cc3
 *
Packit 209cc3
 * In case the sampling is requested, the capturing device should read
Packit 209cc3
 * only a subset of the packets coming from the source. The returned packets
Packit 209cc3
 * depend on the sampling parameters.
Packit 209cc3
 *
Packit 209cc3
 * WARNING: The sampling process is applied *after* the filtering process.
Packit 209cc3
 * In other words, packets are filtered first, then the sampling process
Packit 209cc3
 * selects a subset of the 'filtered' packets and it returns them to the
Packit 209cc3
 * caller.
Packit 209cc3
 */
Packit 209cc3
struct pcap_samp
Packit 209cc3
{
Packit 209cc3
	/*
Packit 209cc3
	 * Method used for sampling; see above.
Packit 209cc3
	 */
Packit 209cc3
	int method;
Packit 209cc3
Packit 209cc3
	/*
Packit 209cc3
	 * This value depends on the sampling method defined.
Packit 209cc3
	 * For its meaning, see above.
Packit 209cc3
	 */
Packit 209cc3
	int value;
Packit 209cc3
};
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * New functions.
Packit 209cc3
 */
Packit 209cc3
PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
Packit 209cc3
Packit 209cc3
/*
Packit 209cc3
 * RPCAP active mode.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
/* Maximum length of an host name (needed for the RPCAP active mode) */
Packit 209cc3
#define RPCAP_HOSTLIST_SIZE 1024
Packit 209cc3
Packit 209cc3
PCAP_API SOCKET	pcap_remoteact_accept(const char *address, const char *port,
Packit 209cc3
	    const char *hostlist, char *connectinghost,
Packit 209cc3
	    struct pcap_rmtauth *auth, char *errbuf);
Packit 209cc3
PCAP_API int	pcap_remoteact_list(char *hostlist, char sep, int size,
Packit 209cc3
	    char *errbuf);
Packit 209cc3
PCAP_API int	pcap_remoteact_close(const char *host, char *errbuf);
Packit 209cc3
PCAP_API void	pcap_remoteact_cleanup(void);
Packit 209cc3
Packit 209cc3
#ifdef __cplusplus
Packit 209cc3
}
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
#endif /* lib_pcap_pcap_h */