pcap-int.h revision 147897
117683Spst/* 217683Spst * Copyright (c) 1994, 1995, 1996 317683Spst * The Regents of the University of California. All rights reserved. 417683Spst * 517683Spst * Redistribution and use in source and binary forms, with or without 617683Spst * modification, are permitted provided that the following conditions 717683Spst * are met: 817683Spst * 1. Redistributions of source code must retain the above copyright 917683Spst * notice, this list of conditions and the following disclaimer. 1017683Spst * 2. Redistributions in binary form must reproduce the above copyright 1117683Spst * notice, this list of conditions and the following disclaimer in the 1217683Spst * documentation and/or other materials provided with the distribution. 1317683Spst * 3. All advertising materials mentioning features or use of this software 1417683Spst * must display the following acknowledgement: 1517683Spst * This product includes software developed by the Computer Systems 1617683Spst * Engineering Group at Lawrence Berkeley Laboratory. 1717683Spst * 4. Neither the name of the University nor of the Laboratory may be used 1817683Spst * to endorse or promote products derived from this software without 1917683Spst * specific prior written permission. 2017683Spst * 2117683Spst * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2217683Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2317683Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2417683Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2517683Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2617683Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2717683Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2817683Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2917683Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3017683Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3117683Spst * SUCH DAMAGE. 3217683Spst * 3356891Sfenner * $FreeBSD: head/contrib/libpcap/pcap-int.h 147897 2005-07-11 03:43:25Z sam $ 34147897Ssam * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.2 2005/05/03 18:54:36 guy Exp $ (LBL) 3517683Spst */ 3617683Spst 3717683Spst#ifndef pcap_int_h 3817683Spst#define pcap_int_h 3917683Spst 4038151Sphk#ifdef __cplusplus 4138151Sphkextern "C" { 4238151Sphk#endif 4338151Sphk 4417683Spst#include <pcap.h> 4517683Spst 46127667Sbms#ifdef WIN32 47127667Sbms#include <packet32.h> 48127667Sbms#endif /* WIN32 */ 49127667Sbms 50146771Ssam#ifdef MSDOS 51146771Ssam#include <fcntl.h> 52146771Ssam#include <io.h> 53146771Ssam#endif 54146771Ssam 5517683Spst/* 5617683Spst * Savefile 5717683Spst */ 58127667Sbmstypedef enum { 59127667Sbms NOT_SWAPPED, 60127667Sbms SWAPPED, 61127667Sbms MAYBE_SWAPPED 62127667Sbms} swapped_type_t; 63127667Sbms 6417683Spststruct pcap_sf { 6517683Spst FILE *rfile; 6617683Spst int swapped; 6775110Sfenner int hdrsize; 68127667Sbms swapped_type_t lengths_swapped; 6917683Spst int version_major; 7017683Spst int version_minor; 7117683Spst u_char *base; 7217683Spst}; 7317683Spst 7417683Spststruct pcap_md { 7517683Spst struct pcap_stat stat; 7617683Spst /*XXX*/ 7775110Sfenner int use_bpf; /* using kernel filter */ 7817683Spst u_long TotPkts; /* can't oflow for 79 hrs on ether */ 7917683Spst u_long TotAccepted; /* count accepted by filter */ 8017683Spst u_long TotDrops; /* count of dropped packets */ 8117683Spst long TotMissed; /* missed by i/f during this run */ 8217683Spst long OrigMissed; /* missed by i/f before this run */ 83146771Ssam char *device; /* device name */ 8426175Sfenner#ifdef linux 8575110Sfenner int sock_packet; /* using Linux 2.0 compatible interface */ 8675110Sfenner int timeout; /* timeout specified to pcap_open_live */ 8775110Sfenner int clear_promisc; /* must clear promiscuous mode when we close */ 8875110Sfenner int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */ 89146771Ssam int ifindex; /* interface index of device we're bound to */ 9075110Sfenner int lo_ifindex; /* interface index of the loopback device */ 9175110Sfenner struct pcap *next; /* list of open promiscuous sock_packet pcaps */ 9226175Sfenner#endif 93127667Sbms 94127667Sbms#ifdef HAVE_DAG_API 95127667Sbms void *dag_mem_base; /* DAG card memory base address */ 96127667Sbms u_int dag_mem_bottom; /* DAG card current memory bottom pointer */ 97127667Sbms u_int dag_mem_top; /* DAG card current memory top pointer */ 98127667Sbms int dag_fcs_bits; /* Number of checksum bits from link layer */ 99146771Ssam int dag_offset_flags; /* Flags to pass to dag_offset(). */ 100127667Sbms#endif 10117683Spst}; 10217683Spst 103147897Ssam/* 104147897Ssam * Ultrix, DEC OSF/1^H^H^H^H^H^H^H^H^HDigital UNIX^H^H^H^H^H^H^H^H^H^H^H^H 105147897Ssam * Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary. 106147897Ssam */ 107147897Ssam#if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000) 108147897Ssam#define PCAP_FDDIPAD 3 109147897Ssam#endif 110147897Ssam 11117683Spststruct pcap { 112127667Sbms#ifdef WIN32 113127667Sbms ADAPTER *adapter; 114127667Sbms LPPACKET Packet; 115127667Sbms int timeout; 116127667Sbms int nonblock; 117127667Sbms#else 11817683Spst int fd; 119127667Sbms int selectable_fd; 120146771Ssam int send_fd; 121127667Sbms#endif /* WIN32 */ 12217683Spst int snapshot; 12317683Spst int linktype; 12417683Spst int tzoff; /* timezone offset */ 12517683Spst int offset; /* offset for proper alignment */ 12617683Spst 127127667Sbms int break_loop; /* flag set to force break from packet-reading loop */ 128127667Sbms 129146771Ssam#ifdef PCAP_FDDIPAD 130146771Ssam int fddipad; 131146771Ssam#endif 132146771Ssam 133146771Ssam#ifdef MSDOS 134146771Ssam int inter_packet_wait; /* offline: wait between packets */ 135146771Ssam void (*wait_proc)(void); /* call proc while waiting */ 136146771Ssam#endif 137146771Ssam 13817683Spst struct pcap_sf sf; 13917683Spst struct pcap_md md; 14017683Spst 14117683Spst /* 14217683Spst * Read buffer. 14317683Spst */ 14417683Spst int bufsize; 14517683Spst u_char *buffer; 14617683Spst u_char *bp; 14717683Spst int cc; 14817683Spst 14917683Spst /* 15017683Spst * Place holder for pcap_next(). 15117683Spst */ 15217683Spst u_char *pkt; 15317683Spst 154147897Ssam /* We're accepting only packets in this direction/these directions. */ 155147897Ssam direction_t direction; 156147897Ssam 15717683Spst /* 158127667Sbms * Methods. 159127667Sbms */ 160127667Sbms int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *); 161146771Ssam int (*inject_op)(pcap_t *, const void *, size_t); 162127667Sbms int (*setfilter_op)(pcap_t *, struct bpf_program *); 163147897Ssam int (*setdirection_op)(pcap_t *, direction_t); 164127667Sbms int (*set_datalink_op)(pcap_t *, int); 165127667Sbms int (*getnonblock_op)(pcap_t *, char *); 166127667Sbms int (*setnonblock_op)(pcap_t *, int, char *); 167127667Sbms int (*stats_op)(pcap_t *, struct pcap_stat *); 168127667Sbms void (*close_op)(pcap_t *); 169127667Sbms 170127667Sbms /* 17117683Spst * Placeholder for filter code if bpf not in kernel. 17217683Spst */ 17317683Spst struct bpf_program fcode; 17417683Spst 175127667Sbms char errbuf[PCAP_ERRBUF_SIZE + 1]; 176109841Sfenner int dlt_count; 177146771Ssam u_int *dlt_list; 178127667Sbms 179127667Sbms struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */ 18017683Spst}; 18117683Spst 18256891Sfenner/* 18356891Sfenner * This is a timeval as stored in disk in a dumpfile. 18456891Sfenner * It has to use the same types everywhere, independent of the actual 18556891Sfenner * `struct timeval' 18656891Sfenner */ 18756891Sfenner 18856891Sfennerstruct pcap_timeval { 18956891Sfenner bpf_int32 tv_sec; /* seconds */ 19056891Sfenner bpf_int32 tv_usec; /* microseconds */ 19156891Sfenner}; 19256891Sfenner 19356891Sfenner/* 19456891Sfenner * How a `pcap_pkthdr' is actually stored in the dumpfile. 19575110Sfenner * 19675110Sfenner * Do not change the format of this structure, in any way (this includes 19775110Sfenner * changes that only affect the length of fields in this structure), 19875110Sfenner * and do not make the time stamp anything other than seconds and 19975110Sfenner * microseconds (e.g., seconds and nanoseconds). Instead: 20075110Sfenner * 20175110Sfenner * introduce a new structure for the new format; 20275110Sfenner * 20375110Sfenner * send mail to "tcpdump-workers@tcpdump.org", requesting a new 20475110Sfenner * magic number for your new capture file format, and, when 20575110Sfenner * you get the new magic number, put it in "savefile.c"; 20675110Sfenner * 20775110Sfenner * use that magic number for save files with the changed record 20875110Sfenner * header; 20975110Sfenner * 21075110Sfenner * make the code in "savefile.c" capable of reading files with 21175110Sfenner * the old record header as well as files with the new record header 21275110Sfenner * (using the magic number to determine the header format). 21375110Sfenner * 21475110Sfenner * Then supply the changes to "patches@tcpdump.org", so that future 21575110Sfenner * versions of libpcap and programs that use it (such as tcpdump) will 21675110Sfenner * be able to read your new capture file format. 21756891Sfenner */ 21856891Sfenner 21956891Sfennerstruct pcap_sf_pkthdr { 22056891Sfenner struct pcap_timeval ts; /* time stamp */ 22156891Sfenner bpf_u_int32 caplen; /* length of portion present */ 22256891Sfenner bpf_u_int32 len; /* length this packet (off wire) */ 22356891Sfenner}; 22456891Sfenner 22575110Sfenner/* 22675110Sfenner * How a `pcap_pkthdr' is actually stored in dumpfiles written 22775110Sfenner * by some patched versions of libpcap (e.g. the ones in Red 22875110Sfenner * Hat Linux 6.1 and 6.2). 22975110Sfenner * 23075110Sfenner * Do not change the format of this structure, in any way (this includes 23175110Sfenner * changes that only affect the length of fields in this structure). 23275110Sfenner * Instead, introduce a new structure, as per the above. 23375110Sfenner */ 23475110Sfenner 23575110Sfennerstruct pcap_sf_patched_pkthdr { 23675110Sfenner struct pcap_timeval ts; /* time stamp */ 23775110Sfenner bpf_u_int32 caplen; /* length of portion present */ 23875110Sfenner bpf_u_int32 len; /* length this packet (off wire) */ 23975110Sfenner int index; 24075110Sfenner unsigned short protocol; 24175110Sfenner unsigned char pkt_type; 24275110Sfenner}; 24375110Sfenner 24417683Spstint yylex(void); 24517683Spst 24617683Spst#ifndef min 24717683Spst#define min(a, b) ((a) > (b) ? (b) : (a)) 24817683Spst#endif 24917683Spst 25017683Spst/* XXX should these be in pcap.h? */ 25117683Spstint pcap_offline_read(pcap_t *, int, pcap_handler, u_char *); 25217683Spstint pcap_read(pcap_t *, int cnt, pcap_handler, u_char *); 25317683Spst 254147897Ssam#ifndef HAVE_STRLCPY 255147897Ssam#define strlcpy(x, y, z) \ 256147897Ssam (strncpy((x), (y), (z)), \ 257147897Ssam ((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \ 258147897Ssam strlen((y))) 25917683Spst#endif 26017683Spst 261127667Sbms#include <stdarg.h> 262127667Sbms 263127667Sbms/* 264127667Sbms * Routines that most pcap implementations can use for non-blocking mode. 265127667Sbms */ 266146771Ssam#if !defined(WIN32) && !defined(MSDOS) 267127667Sbmsint pcap_getnonblock_fd(pcap_t *, char *); 268127667Sbmsint pcap_setnonblock_fd(pcap_t *p, int, char *); 269127667Sbms#endif 270127667Sbms 271146771Ssamvoid pcap_close_common(pcap_t *); 272146771Ssam 273127667Sbms/* 274127667Sbms * Internal interfaces for "pcap_findalldevs()". 275127667Sbms * 276127667Sbms * "pcap_platform_finddevs()" is a platform-dependent routine to 277127667Sbms * add devices not found by the "standard" mechanisms (SIOCGIFCONF, 278127667Sbms * "getifaddrs()", etc.. 279127667Sbms * 280127667Sbms * "pcap_add_if()" adds an interface to the list of interfaces. 281127667Sbms */ 282127667Sbmsint pcap_platform_finddevs(pcap_if_t **, char *); 283146771Ssamint add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *, 284127667Sbms size_t, struct sockaddr *, size_t, struct sockaddr *, size_t, 285127667Sbms struct sockaddr *, size_t, char *); 286146771Ssamint pcap_add_if(pcap_if_t **, const char *, u_int, const char *, char *); 287127667Sbmsstruct sockaddr *dup_sockaddr(struct sockaddr *, size_t); 288127667Sbmsint add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int, 289127667Sbms const char *, char *); 290127667Sbms 291127667Sbms#ifdef WIN32 292127667Sbmschar *pcap_win32strerror(void); 293127667Sbms#endif 294127667Sbms 29575110Sfennerint install_bpf_program(pcap_t *, struct bpf_program *); 29675110Sfenner 297127667Sbmsint pcap_strcasecmp(const char *, const char *); 298127667Sbms 29938151Sphk#ifdef __cplusplus 30038151Sphk} 30117683Spst#endif 30238151Sphk 30338151Sphk#endif 304