os/boardsupport/emulator/emulatorbsp/wpdpack/include/pcap-int.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/emulator/emulatorbsp/wpdpack/include/pcap-int.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,373 @@
     1.4 +/*
     1.5 + * Copyright (c) 1994, 1995, 1996
     1.6 + *	The Regents of the University of California.  All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 3. All advertising materials mentioning features or use of this software
    1.17 + *    must display the following acknowledgement:
    1.18 + *	This product includes software developed by the Computer Systems
    1.19 + *	Engineering Group at Lawrence Berkeley Laboratory.
    1.20 + * 4. Neither the name of the University nor of the Laboratory may be used
    1.21 + *    to endorse or promote products derived from this software without
    1.22 + *    specific prior written permission.
    1.23 + *
    1.24 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.25 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.26 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.27 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.28 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.29 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.30 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.31 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.32 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.33 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.34 + * SUCH DAMAGE.
    1.35 + *
    1.36 + * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.9 2006/02/22 17:09:54 gianluca Exp $ (LBL)
    1.37 + */
    1.38 +
    1.39 +#ifndef pcap_int_h
    1.40 +#define pcap_int_h
    1.41 +
    1.42 +#ifdef __cplusplus
    1.43 +extern "C" {
    1.44 +#endif
    1.45 +
    1.46 +#include <pcap.h>
    1.47 +
    1.48 +#ifdef WIN32
    1.49 +#include <Packet32.h>
    1.50 +#endif /* WIN32 */
    1.51 +
    1.52 +#ifdef MSDOS
    1.53 +#include <fcntl.h>
    1.54 +#include <io.h>
    1.55 +#endif
    1.56 +
    1.57 +/*
    1.58 + * Savefile
    1.59 + */
    1.60 +typedef enum {
    1.61 +	NOT_SWAPPED,
    1.62 +	SWAPPED,
    1.63 +	MAYBE_SWAPPED
    1.64 +} swapped_type_t;
    1.65 +
    1.66 +struct pcap_sf {
    1.67 +	FILE *rfile;
    1.68 +	int swapped;
    1.69 +	int hdrsize;
    1.70 +	swapped_type_t lengths_swapped;
    1.71 +	int version_major;
    1.72 +	int version_minor;
    1.73 +	u_char *base;
    1.74 +};
    1.75 +
    1.76 +struct pcap_md {
    1.77 +	struct pcap_stat stat;
    1.78 +	/*XXX*/
    1.79 +	int use_bpf;		/* using kernel filter */
    1.80 +	u_long	TotPkts;	/* can't oflow for 79 hrs on ether */
    1.81 +	u_long	TotAccepted;	/* count accepted by filter */
    1.82 +	u_long	TotDrops;	/* count of dropped packets */
    1.83 +	long	TotMissed;	/* missed by i/f during this run */
    1.84 +	long	OrigMissed;	/* missed by i/f before this run */
    1.85 +	char	*device;	/* device name */
    1.86 +#ifdef linux
    1.87 +	int	sock_packet;	/* using Linux 2.0 compatible interface */
    1.88 +	int	timeout;	/* timeout specified to pcap_open_live */
    1.89 +	int	clear_promisc;	/* must clear promiscuous mode when we close */
    1.90 +	int	cooked;		/* using SOCK_DGRAM rather than SOCK_RAW */
    1.91 +	int	ifindex;	/* interface index of device we're bound to */
    1.92 +	int	lo_ifindex;	/* interface index of the loopback device */
    1.93 +	struct pcap *next;	/* list of open promiscuous sock_packet pcaps */
    1.94 +	u_int	packets_read;	/* count of packets read with recvfrom() */
    1.95 +#endif
    1.96 +
    1.97 +#ifdef HAVE_DAG_API
    1.98 +#ifdef HAVE_DAG_STREAMS_API
    1.99 +	u_char	*dag_mem_bottom;	/* DAG card current memory bottom pointer */
   1.100 +	u_char	*dag_mem_top;	/* DAG card current memory top pointer */
   1.101 +#else
   1.102 +	void	*dag_mem_base;	/* DAG card memory base address */
   1.103 +	u_int	dag_mem_bottom;	/* DAG card current memory bottom offset */
   1.104 +	u_int	dag_mem_top;	/* DAG card current memory top offset */
   1.105 +#endif /* HAVE_DAG_STREAMS_API */
   1.106 +	int	dag_fcs_bits;	/* Number of checksum bits from link layer */
   1.107 +	int	dag_offset_flags; /* Flags to pass to dag_offset(). */
   1.108 +	int	dag_stream;	/* DAG stream number */
   1.109 +	int	dag_timeout;	/* timeout specified to pcap_open_live.
   1.110 +				 * Same as in linux above, introduce
   1.111 +				 * generally? */
   1.112 +#endif /* HAVE_DAG_API */
   1.113 +
   1.114 +#ifdef HAVE_REMOTE
   1.115 +/*!
   1.116 +	There is really a mess with previous variables, and it seems to me that they are not used
   1.117 +	(they are used in pcap_pf.c only). I think we have to start using them.
   1.118 +	The meaning is the following:
   1.119 +
   1.120 +	- TotPkts: the amount of packets received by the bpf filter, *before* applying the filter
   1.121 +	- TotAccepted: the amount of packets that satisfies the filter
   1.122 +	- TotDrops: the amount of packet that were dropped into the kernel buffer because of lack of space
   1.123 +	- TotMissed: the amount of packets that were dropped by the physical interface; it is basically 
   1.124 +	the value of the hardware counter into the card. This number is never put to zero, so this number
   1.125 +	takes into account the *total* number of interface drops starting from the interface power-on.
   1.126 +	- OrigMissed: the amount of packets that were dropped by the interface *when the capture begins*.
   1.127 +	This value is used to detect the number of packets dropped by the interface *during the present
   1.128 +	capture*, so that (ps_ifdrops= TotMissed - OrigMissed).
   1.129 +*/
   1.130 +	unsigned int TotNetDrops;	//!< keeps the number of packets that have been dropped by the network
   1.131 +/*!
   1.132 +	\brief It keeps the number of packets that have been received by the application.
   1.133 +	
   1.134 +	Packets dropped by the kernel buffer are not counted in this variable. The variable is always 
   1.135 +	equal to (TotAccepted - TotDrops), exept for the case of remote capture, in which we have also
   1.136 +	packets in fligh, i.e. that have been transmitted by the remote host, but that have not been 
   1.137 +	received (yet) from the client. In this case, (TotAccepted - TotDrops - TotNetDrops) gives a
   1.138 +	wrong result, since this number does not corresponds always to the number of packet received by 
   1.139 +	the application. For this reason, in the remote capture we need another variable that takes
   1.140 +	into account of the number of packets actually received by the application.
   1.141 +*/
   1.142 +	unsigned int TotCapt;
   1.143 +#endif /* HAVE_REMOTE */
   1.144 +};
   1.145 +
   1.146 +/*
   1.147 + * 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
   1.148 + * Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary.
   1.149 + */
   1.150 +#if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000)
   1.151 +#define       PCAP_FDDIPAD 3
   1.152 +#endif
   1.153 +
   1.154 +struct pcap {
   1.155 +#ifdef WIN32
   1.156 +	ADAPTER *adapter;
   1.157 +	LPPACKET Packet;
   1.158 +	int timeout;
   1.159 +	int nonblock;
   1.160 +#else
   1.161 +	int fd;
   1.162 +	int selectable_fd;
   1.163 +	int send_fd;
   1.164 +#endif /* WIN32 */
   1.165 +	int snapshot;
   1.166 +	int linktype;
   1.167 +	int tzoff;		/* timezone offset */
   1.168 +	int offset;		/* offset for proper alignment */
   1.169 +
   1.170 +	int break_loop;		/* flag set to force break from packet-reading loop */
   1.171 +
   1.172 +#ifdef PCAP_FDDIPAD
   1.173 +	int fddipad;
   1.174 +#endif
   1.175 +
   1.176 +#ifdef MSDOS
   1.177 +        int inter_packet_wait;   /* offline: wait between packets */
   1.178 +        void (*wait_proc)(void); /*          call proc while waiting */
   1.179 +#endif
   1.180 +
   1.181 +	struct pcap_sf sf;
   1.182 +	struct pcap_md md;
   1.183 +
   1.184 +	/*
   1.185 +	 * Read buffer.
   1.186 +	 */
   1.187 +	int bufsize;
   1.188 +	u_char *buffer;
   1.189 +	u_char *bp;
   1.190 +	int cc;
   1.191 +
   1.192 +	/*
   1.193 +	 * Place holder for pcap_next().
   1.194 +	 */
   1.195 +	u_char *pkt;
   1.196 +
   1.197 +	/* We're accepting only packets in this direction/these directions. */
   1.198 +	pcap_direction_t direction;
   1.199 +
   1.200 +	/*
   1.201 +	 * Methods.
   1.202 +	 */
   1.203 +	int	(*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
   1.204 +	int	(*inject_op)(pcap_t *, const void *, size_t);
   1.205 +	int	(*setfilter_op)(pcap_t *, struct bpf_program *);
   1.206 +	int	(*setdirection_op)(pcap_t *, pcap_direction_t);
   1.207 +	int	(*set_datalink_op)(pcap_t *, int);
   1.208 +	int	(*getnonblock_op)(pcap_t *, char *);
   1.209 +	int	(*setnonblock_op)(pcap_t *, int, char *);
   1.210 +	int	(*stats_op)(pcap_t *, struct pcap_stat *);
   1.211 +	void	(*close_op)(pcap_t *);
   1.212 +
   1.213 +	/*
   1.214 +	 * Placeholder for filter code if bpf not in kernel.
   1.215 +	 */
   1.216 +	struct bpf_program fcode;
   1.217 +
   1.218 +	char errbuf[PCAP_ERRBUF_SIZE + 1];
   1.219 +	int dlt_count;
   1.220 +	u_int *dlt_list;
   1.221 +
   1.222 +	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
   1.223 +
   1.224 +#ifdef HAVE_REMOTE
   1.225 +#ifndef WIN32	// Win32 already defines 'timeout'
   1.226 +	int timeout;				//!< timeout to be used in the pcap_open()
   1.227 +#endif
   1.228 +	/*! \brief '1' if we're the network client; needed by several functions (like pcap_setfilter() ) to know if 
   1.229 +		they have to use the socket or they have to open the local adapter. */
   1.230 +	int rmt_clientside;
   1.231 +
   1.232 +	SOCKET rmt_sockctrl;		//!< socket ID of the socket used for the control connection
   1.233 +	SOCKET rmt_sockdata;		//!< socket ID of the socket used for the data connection
   1.234 +	int rmt_flags;				//!< we have to save flags, since they are passed by the pcap_open_live(), but they are used by the pcap_startcapture()
   1.235 +	int rmt_capstarted;			//!< 'true' if the capture is already started (needed to knoe if we have to call the pcap_startcapture()
   1.236 +	struct pcap_samp rmt_samp;	//!< Keeps the parameters related to the sampling process.
   1.237 +	char *currentfilter;		//!< Pointer to a buffer (allocated at run-time) that stores the current filter. Needed when flag PCAP_OPENFLAG_NOCAPTURE_RPCAP is turned on.
   1.238 +#endif /* HAVE_REMOTE */
   1.239 +};
   1.240 +
   1.241 +/*
   1.242 + * This is a timeval as stored in a savefile.
   1.243 + * It has to use the same types everywhere, independent of the actual
   1.244 + * `struct timeval'; `struct timeval' has 32-bit tv_sec values on some
   1.245 + * platforms and 64-bit tv_sec values on other platforms, and writing
   1.246 + * out native `struct timeval' values would mean files could only be
   1.247 + * read on systems with the same tv_sec size as the system on which
   1.248 + * the file was written.
   1.249 + */
   1.250 +
   1.251 +struct pcap_timeval {
   1.252 +    bpf_int32 tv_sec;		/* seconds */
   1.253 +    bpf_int32 tv_usec;		/* microseconds */
   1.254 +};
   1.255 +
   1.256 +/*
   1.257 + * This is a `pcap_pkthdr' as actually stored in a savefile.
   1.258 + *
   1.259 + * Do not change the format of this structure, in any way (this includes
   1.260 + * changes that only affect the length of fields in this structure),
   1.261 + * and do not make the time stamp anything other than seconds and
   1.262 + * microseconds (e.g., seconds and nanoseconds).  Instead:
   1.263 + *
   1.264 + *	introduce a new structure for the new format;
   1.265 + *
   1.266 + *	send mail to "tcpdump-workers@tcpdump.org", requesting a new
   1.267 + *	magic number for your new capture file format, and, when
   1.268 + *	you get the new magic number, put it in "savefile.c";
   1.269 + *
   1.270 + *	use that magic number for save files with the changed record
   1.271 + *	header;
   1.272 + *
   1.273 + *	make the code in "savefile.c" capable of reading files with
   1.274 + *	the old record header as well as files with the new record header
   1.275 + *	(using the magic number to determine the header format).
   1.276 + *
   1.277 + * Then supply the changes to "patches@tcpdump.org", so that future
   1.278 + * versions of libpcap and programs that use it (such as tcpdump) will
   1.279 + * be able to read your new capture file format.
   1.280 + */
   1.281 +
   1.282 +struct pcap_sf_pkthdr {
   1.283 +    struct pcap_timeval ts;	/* time stamp */
   1.284 +    bpf_u_int32 caplen;		/* length of portion present */
   1.285 +    bpf_u_int32 len;		/* length this packet (off wire) */
   1.286 +};
   1.287 +
   1.288 +/*
   1.289 + * How a `pcap_pkthdr' is actually stored in savefiles written
   1.290 + * by some patched versions of libpcap (e.g. the ones in Red
   1.291 + * Hat Linux 6.1 and 6.2).
   1.292 + *
   1.293 + * Do not change the format of this structure, in any way (this includes
   1.294 + * changes that only affect the length of fields in this structure).
   1.295 + * Instead, introduce a new structure, as per the above.
   1.296 + */
   1.297 +
   1.298 +struct pcap_sf_patched_pkthdr {
   1.299 +    struct pcap_timeval ts;	/* time stamp */
   1.300 +    bpf_u_int32 caplen;		/* length of portion present */
   1.301 +    bpf_u_int32 len;		/* length this packet (off wire) */
   1.302 +    int		index;
   1.303 +    unsigned short protocol;
   1.304 +    unsigned char pkt_type;
   1.305 +};
   1.306 +
   1.307 +int	yylex(void);
   1.308 +
   1.309 +#ifndef min
   1.310 +#define min(a, b) ((a) > (b) ? (b) : (a))
   1.311 +#endif
   1.312 +
   1.313 +/* XXX should these be in pcap.h? */
   1.314 +int	pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
   1.315 +int	pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
   1.316 +
   1.317 +#ifndef HAVE_STRLCPY
   1.318 +#define strlcpy(x, y, z) \
   1.319 +	(strncpy((x), (y), (z)), \
   1.320 +	 ((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \
   1.321 +	 strlen((y)))
   1.322 +#endif
   1.323 +
   1.324 +#include <stdarg.h>
   1.325 +
   1.326 +#if !defined(HAVE_SNPRINTF)
   1.327 +#define snprintf pcap_snprintf
   1.328 +extern int snprintf (char *, size_t, const char *, ...);
   1.329 +#endif
   1.330 +
   1.331 +#if !defined(HAVE_VSNPRINTF)
   1.332 +#define vsnprintf pcap_vsnprintf
   1.333 +extern int vsnprintf (char *, size_t, const char *, va_list ap);
   1.334 +#endif
   1.335 +
   1.336 +/*
   1.337 + * Routines that most pcap implementations can use for non-blocking mode.
   1.338 + */
   1.339 +#if !defined(WIN32) && !defined(MSDOS)
   1.340 +int	pcap_getnonblock_fd(pcap_t *, char *);
   1.341 +int	pcap_setnonblock_fd(pcap_t *p, int, char *);
   1.342 +#endif
   1.343 +
   1.344 +void	pcap_close_common(pcap_t *);
   1.345 +
   1.346 +/*
   1.347 + * Internal interfaces for "pcap_findalldevs()".
   1.348 + *
   1.349 + * "pcap_platform_finddevs()" is a platform-dependent routine to
   1.350 + * add devices not found by the "standard" mechanisms (SIOCGIFCONF,
   1.351 + * "getifaddrs()", etc..
   1.352 + *
   1.353 + * "pcap_add_if()" adds an interface to the list of interfaces.
   1.354 + */
   1.355 +int	pcap_platform_finddevs(pcap_if_t **, char *);
   1.356 +int	add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *,
   1.357 +	    size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
   1.358 +	    struct sockaddr *, size_t, char *);
   1.359 +int	pcap_add_if(pcap_if_t **, const char *, u_int, const char *, char *);
   1.360 +struct sockaddr *dup_sockaddr(struct sockaddr *, size_t);
   1.361 +int	add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int,
   1.362 +	    const char *, char *);
   1.363 +
   1.364 +#ifdef WIN32
   1.365 +char	*pcap_win32strerror(void);
   1.366 +#endif
   1.367 +
   1.368 +int	install_bpf_program(pcap_t *, struct bpf_program *);
   1.369 +
   1.370 +int	pcap_strcasecmp(const char *, const char *);
   1.371 +
   1.372 +#ifdef __cplusplus
   1.373 +}
   1.374 +#endif
   1.375 +
   1.376 +#endif