sl@0: /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ sl@0: /* sl@0: * Copyright (c) 1993, 1994, 1995, 1996, 1997 sl@0: * The Regents of the University of California. All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * This product includes software developed by the Computer Systems sl@0: * Engineering Group at Lawrence Berkeley Laboratory. sl@0: * 4. Neither the name of the University nor of the Laboratory may be used sl@0: * to endorse or promote products derived from this software without sl@0: * specific prior written permission. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52.2.6 2006/02/09 22:26:49 guy Exp $ (LBL) sl@0: */ sl@0: sl@0: #ifndef lib_pcap_h sl@0: #define lib_pcap_h sl@0: sl@0: #if defined(WIN32) sl@0: #include "pcap-stdinc.h" sl@0: #elif defined(MSDOS) sl@0: #include sl@0: #include /* u_int, u_char etc. */ sl@0: #else /* UN*X */ sl@0: #include sl@0: #include sl@0: #endif /* WIN32/MSDOS/UN*X */ sl@0: sl@0: #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H sl@0: #include "pcap-bpf.h" sl@0: #endif sl@0: sl@0: #include sl@0: sl@0: #ifdef HAVE_REMOTE sl@0: // We have to define the SOCKET here, although it has been defined in sockutils.h sl@0: // This is to avoid the distribution of the 'sockutils.h' file around sl@0: // (for example in the WinPcap developer's pack) sl@0: #ifndef SOCKET sl@0: #ifdef WIN32 sl@0: #define SOCKET unsigned int sl@0: #else sl@0: #define SOCKET int sl@0: #endif sl@0: #endif sl@0: #endif sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" { sl@0: #endif sl@0: sl@0: #define PCAP_VERSION_MAJOR 2 sl@0: #define PCAP_VERSION_MINOR 4 sl@0: sl@0: #define PCAP_ERRBUF_SIZE 256 sl@0: sl@0: /* sl@0: * Compatibility for systems that have a bpf.h that sl@0: * predates the bpf typedefs for 64-bit support. sl@0: */ sl@0: #if BPF_RELEASE - 0 < 199406 sl@0: typedef int bpf_int32; sl@0: typedef u_int bpf_u_int32; sl@0: #endif sl@0: sl@0: typedef struct pcap pcap_t; sl@0: typedef struct pcap_dumper pcap_dumper_t; sl@0: typedef struct pcap_if pcap_if_t; sl@0: typedef struct pcap_addr pcap_addr_t; sl@0: sl@0: /* sl@0: * The first record in the file contains saved values for some sl@0: * of the flags used in the printout phases of tcpdump. sl@0: * Many fields here are 32 bit ints so compilers won't insert unwanted sl@0: * padding; these files need to be interchangeable across architectures. sl@0: * sl@0: * Do not change the layout of this structure, in any way (this includes sl@0: * changes that only affect the length of fields in this structure). sl@0: * sl@0: * Also, do not change the interpretation of any of the members of this sl@0: * structure, in any way (this includes using values other than sl@0: * LINKTYPE_ values, as defined in "savefile.c", in the "linktype" sl@0: * field). sl@0: * sl@0: * Instead: sl@0: * sl@0: * introduce a new structure for the new format, if the layout sl@0: * of the structure changed; sl@0: * sl@0: * send mail to "tcpdump-workers@tcpdump.org", requesting a new sl@0: * magic number for your new capture file format, and, when sl@0: * you get the new magic number, put it in "savefile.c"; sl@0: * sl@0: * use that magic number for save files with the changed file sl@0: * header; sl@0: * sl@0: * make the code in "savefile.c" capable of reading files with sl@0: * the old file header as well as files with the new file header sl@0: * (using the magic number to determine the header format). sl@0: * sl@0: * Then supply the changes to "patches@tcpdump.org", so that future sl@0: * versions of libpcap and programs that use it (such as tcpdump) will sl@0: * be able to read your new capture file format. sl@0: */ sl@0: struct pcap_file_header { sl@0: bpf_u_int32 magic; sl@0: u_short version_major; sl@0: u_short version_minor; sl@0: bpf_int32 thiszone; /* gmt to local correction */ sl@0: bpf_u_int32 sigfigs; /* accuracy of timestamps */ sl@0: bpf_u_int32 snaplen; /* max length saved portion of each pkt */ sl@0: bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */ sl@0: }; sl@0: sl@0: typedef enum { sl@0: PCAP_D_INOUT = 0, sl@0: PCAP_D_IN, sl@0: PCAP_D_OUT sl@0: } pcap_direction_t; sl@0: sl@0: /* sl@0: * Generic per-packet information, as supplied by libpcap. sl@0: * sl@0: * The time stamp can and should be a "struct timeval", regardless of sl@0: * whether your system supports 32-bit tv_sec in "struct timeval", sl@0: * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit sl@0: * and 64-bit applications. The on-disk format of savefiles uses 32-bit sl@0: * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit sl@0: * and 64-bit versions of libpcap, even if they're on the same platform, sl@0: * should supply the appropriate version of "struct timeval", even if sl@0: * that's not what the underlying packet capture mechanism supplies. sl@0: */ sl@0: struct pcap_pkthdr { sl@0: struct timeval ts; /* time stamp */ sl@0: bpf_u_int32 caplen; /* length of portion present */ sl@0: bpf_u_int32 len; /* length this packet (off wire) */ sl@0: }; sl@0: sl@0: /* sl@0: * As returned by the pcap_stats() sl@0: */ sl@0: struct pcap_stat { sl@0: u_int ps_recv; /* number of packets received */ sl@0: u_int ps_drop; /* number of packets dropped */ sl@0: u_int ps_ifdrop; /* drops by interface XXX not yet supported */ sl@0: #ifdef HAVE_REMOTE sl@0: u_int ps_capt; /* number of packets that are received by the application; please get rid off the Win32 ifdef */ sl@0: u_int ps_sent; /* number of packets sent by the server on the network */ sl@0: u_int ps_netdrop; /* number of packets lost on the network */ sl@0: #endif /* HAVE_REMOTE */ sl@0: }; sl@0: sl@0: #ifdef MSDOS sl@0: /* sl@0: * As returned by the pcap_stats_ex() sl@0: */ sl@0: struct pcap_stat_ex { sl@0: u_long rx_packets; /* total packets received */ sl@0: u_long tx_packets; /* total packets transmitted */ sl@0: u_long rx_bytes; /* total bytes received */ sl@0: u_long tx_bytes; /* total bytes transmitted */ sl@0: u_long rx_errors; /* bad packets received */ sl@0: u_long tx_errors; /* packet transmit problems */ sl@0: u_long rx_dropped; /* no space in Rx buffers */ sl@0: u_long tx_dropped; /* no space available for Tx */ sl@0: u_long multicast; /* multicast packets received */ sl@0: u_long collisions; sl@0: sl@0: /* detailed rx_errors: */ sl@0: u_long rx_length_errors; sl@0: u_long rx_over_errors; /* receiver ring buff overflow */ sl@0: u_long rx_crc_errors; /* recv'd pkt with crc error */ sl@0: u_long rx_frame_errors; /* recv'd frame alignment error */ sl@0: u_long rx_fifo_errors; /* recv'r fifo overrun */ sl@0: u_long rx_missed_errors; /* recv'r missed packet */ sl@0: sl@0: /* detailed tx_errors */ sl@0: u_long tx_aborted_errors; sl@0: u_long tx_carrier_errors; sl@0: u_long tx_fifo_errors; sl@0: u_long tx_heartbeat_errors; sl@0: u_long tx_window_errors; sl@0: }; sl@0: #endif sl@0: sl@0: /* sl@0: * Item in a list of interfaces. sl@0: */ sl@0: struct pcap_if { sl@0: struct pcap_if *next; sl@0: char *name; /* name to hand to "pcap_open_live()" */ sl@0: char *description; /* textual description of interface, or NULL */ sl@0: struct pcap_addr *addresses; sl@0: bpf_u_int32 flags; /* PCAP_IF_ interface flags */ sl@0: }; sl@0: sl@0: #define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */ sl@0: sl@0: /* sl@0: * Representation of an interface address. sl@0: */ sl@0: struct pcap_addr { sl@0: struct pcap_addr *next; sl@0: struct sockaddr *addr; /* address */ sl@0: struct sockaddr *netmask; /* netmask for that address */ sl@0: struct sockaddr *broadaddr; /* broadcast address for that address */ sl@0: struct sockaddr *dstaddr; /* P2P destination address for that address */ sl@0: }; sl@0: sl@0: typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, sl@0: const u_char *); sl@0: sl@0: char *pcap_lookupdev(char *); sl@0: int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); sl@0: pcap_t *pcap_open_live(const char *, int, int, int, char *); sl@0: pcap_t *pcap_open_dead(int, int); sl@0: pcap_t *pcap_open_offline(const char *, char *); sl@0: pcap_t *pcap_fopen_offline(FILE *, char *); sl@0: void pcap_close(pcap_t *); sl@0: int pcap_loop(pcap_t *, int, pcap_handler, u_char *); sl@0: int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); sl@0: const u_char* sl@0: pcap_next(pcap_t *, struct pcap_pkthdr *); sl@0: int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **); sl@0: void pcap_breakloop(pcap_t *); sl@0: int pcap_stats(pcap_t *, struct pcap_stat *); sl@0: int pcap_setfilter(pcap_t *, struct bpf_program *); sl@0: int pcap_setdirection(pcap_t *, pcap_direction_t); sl@0: int pcap_getnonblock(pcap_t *, char *); sl@0: int pcap_setnonblock(pcap_t *, int, char *); sl@0: void pcap_perror(pcap_t *, char *); sl@0: int pcap_inject(pcap_t *, const void *, size_t); sl@0: int pcap_sendpacket(pcap_t *, const u_char *, int); sl@0: char *pcap_strerror(int); sl@0: char *pcap_geterr(pcap_t *); sl@0: int pcap_compile(pcap_t *, struct bpf_program *, char *, int, sl@0: bpf_u_int32); sl@0: int pcap_compile_nopcap(int, int, struct bpf_program *, sl@0: char *, int, bpf_u_int32); sl@0: void pcap_freecode(struct bpf_program *); sl@0: int pcap_datalink(pcap_t *); sl@0: int pcap_list_datalinks(pcap_t *, int **); sl@0: int pcap_set_datalink(pcap_t *, int); sl@0: int pcap_datalink_name_to_val(const char *); sl@0: const char *pcap_datalink_val_to_name(int); sl@0: const char *pcap_datalink_val_to_description(int); sl@0: int pcap_snapshot(pcap_t *); sl@0: int pcap_is_swapped(pcap_t *); sl@0: int pcap_major_version(pcap_t *); sl@0: int pcap_minor_version(pcap_t *); sl@0: sl@0: /* XXX */ sl@0: FILE *pcap_file(pcap_t *); sl@0: int pcap_fileno(pcap_t *); sl@0: sl@0: pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); sl@0: pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); sl@0: FILE *pcap_dump_file(pcap_dumper_t *); sl@0: long pcap_dump_ftell(pcap_dumper_t *); sl@0: int pcap_dump_flush(pcap_dumper_t *); sl@0: void pcap_dump_close(pcap_dumper_t *); sl@0: void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); sl@0: sl@0: int pcap_findalldevs(pcap_if_t **, char *); sl@0: void pcap_freealldevs(pcap_if_t *); sl@0: sl@0: const char *pcap_lib_version(void); sl@0: sl@0: /* XXX this guy lives in the bpf tree */ sl@0: u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); sl@0: int bpf_validate(struct bpf_insn *f, int len); sl@0: char *bpf_image(struct bpf_insn *, int); sl@0: void bpf_dump(struct bpf_program *, int); sl@0: sl@0: #if defined(WIN32) sl@0: sl@0: /* sl@0: * Win32 definitions sl@0: */ sl@0: sl@0: int pcap_setbuff(pcap_t *p, int dim); sl@0: int pcap_setmode(pcap_t *p, int mode); sl@0: int pcap_setmintocopy(pcap_t *p, int size); sl@0: sl@0: #ifdef WPCAP sl@0: /* Include file with the wpcap-specific extensions */ sl@0: #include sl@0: #endif /* WPCAP */ sl@0: sl@0: #define MODE_CAPT 0 sl@0: #define MODE_STAT 1 sl@0: #define MODE_MON 2 sl@0: sl@0: #elif defined(MSDOS) sl@0: sl@0: /* sl@0: * MS-DOS definitions sl@0: */ sl@0: sl@0: int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *); sl@0: void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait); sl@0: u_long pcap_mac_packets (void); sl@0: sl@0: #else /* UN*X */ sl@0: sl@0: /* sl@0: * UN*X definitions sl@0: */ sl@0: sl@0: int pcap_get_selectable_fd(pcap_t *); sl@0: sl@0: #endif /* WIN32/MSDOS/UN*X */ sl@0: sl@0: #ifdef HAVE_REMOTE sl@0: /* Includes most of the public stuff that is needed for the remote capture */ sl@0: #include "remote-ext.h" sl@0: #endif /* HAVE_REMOTE */ sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: sl@0: #endif