os/boardsupport/emulator/emulatorbsp/wpdpack/include/pcap.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
sl@0
     2
/*
sl@0
     3
 * Copyright (c) 1993, 1994, 1995, 1996, 1997
sl@0
     4
 *	The Regents of the University of California.  All rights reserved.
sl@0
     5
 *
sl@0
     6
 * Redistribution and use in source and binary forms, with or without
sl@0
     7
 * modification, are permitted provided that the following conditions
sl@0
     8
 * are met:
sl@0
     9
 * 1. Redistributions of source code must retain the above copyright
sl@0
    10
 *    notice, this list of conditions and the following disclaimer.
sl@0
    11
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    12
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    13
 *    documentation and/or other materials provided with the distribution.
sl@0
    14
 * 3. All advertising materials mentioning features or use of this software
sl@0
    15
 *    must display the following acknowledgement:
sl@0
    16
 *	This product includes software developed by the Computer Systems
sl@0
    17
 *	Engineering Group at Lawrence Berkeley Laboratory.
sl@0
    18
 * 4. Neither the name of the University nor of the Laboratory may be used
sl@0
    19
 *    to endorse or promote products derived from this software without
sl@0
    20
 *    specific prior written permission.
sl@0
    21
 *
sl@0
    22
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
sl@0
    23
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    25
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
sl@0
    26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sl@0
    27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
sl@0
    28
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    29
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
sl@0
    30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
sl@0
    31
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    32
 * SUCH DAMAGE.
sl@0
    33
 *
sl@0
    34
 * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52.2.6 2006/02/09 22:26:49 guy Exp $ (LBL)
sl@0
    35
 */
sl@0
    36
sl@0
    37
#ifndef lib_pcap_h
sl@0
    38
#define lib_pcap_h
sl@0
    39
sl@0
    40
#if defined(WIN32)
sl@0
    41
  #include "pcap-stdinc.h"
sl@0
    42
#elif defined(MSDOS)
sl@0
    43
  #include <sys/types.h>
sl@0
    44
  #include <sys/socket.h>  /* u_int, u_char etc. */
sl@0
    45
#else /* UN*X */
sl@0
    46
  #include <sys/types.h>
sl@0
    47
  #include <sys/time.h>
sl@0
    48
#endif /* WIN32/MSDOS/UN*X */
sl@0
    49
sl@0
    50
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
sl@0
    51
#include "pcap-bpf.h"
sl@0
    52
#endif
sl@0
    53
sl@0
    54
#include <stdio.h>
sl@0
    55
sl@0
    56
#ifdef HAVE_REMOTE
sl@0
    57
	// We have to define the SOCKET here, although it has been defined in sockutils.h
sl@0
    58
	// This is to avoid the distribution of the 'sockutils.h' file around
sl@0
    59
	// (for example in the WinPcap developer's pack)
sl@0
    60
	#ifndef SOCKET
sl@0
    61
		#ifdef WIN32
sl@0
    62
			#define SOCKET unsigned int
sl@0
    63
		#else
sl@0
    64
			#define SOCKET int
sl@0
    65
		#endif
sl@0
    66
	#endif
sl@0
    67
#endif
sl@0
    68
sl@0
    69
#ifdef __cplusplus
sl@0
    70
extern "C" {
sl@0
    71
#endif
sl@0
    72
sl@0
    73
#define PCAP_VERSION_MAJOR 2
sl@0
    74
#define PCAP_VERSION_MINOR 4
sl@0
    75
sl@0
    76
#define PCAP_ERRBUF_SIZE 256
sl@0
    77
sl@0
    78
/*
sl@0
    79
 * Compatibility for systems that have a bpf.h that
sl@0
    80
 * predates the bpf typedefs for 64-bit support.
sl@0
    81
 */
sl@0
    82
#if BPF_RELEASE - 0 < 199406
sl@0
    83
typedef	int bpf_int32;
sl@0
    84
typedef	u_int bpf_u_int32;
sl@0
    85
#endif
sl@0
    86
sl@0
    87
typedef struct pcap pcap_t;
sl@0
    88
typedef struct pcap_dumper pcap_dumper_t;
sl@0
    89
typedef struct pcap_if pcap_if_t;
sl@0
    90
typedef struct pcap_addr pcap_addr_t;
sl@0
    91
sl@0
    92
/*
sl@0
    93
 * The first record in the file contains saved values for some
sl@0
    94
 * of the flags used in the printout phases of tcpdump.
sl@0
    95
 * Many fields here are 32 bit ints so compilers won't insert unwanted
sl@0
    96
 * padding; these files need to be interchangeable across architectures.
sl@0
    97
 *
sl@0
    98
 * Do not change the layout of this structure, in any way (this includes
sl@0
    99
 * changes that only affect the length of fields in this structure).
sl@0
   100
 *
sl@0
   101
 * Also, do not change the interpretation of any of the members of this
sl@0
   102
 * structure, in any way (this includes using values other than
sl@0
   103
 * LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
sl@0
   104
 * field).
sl@0
   105
 *
sl@0
   106
 * Instead:
sl@0
   107
 *
sl@0
   108
 *	introduce a new structure for the new format, if the layout
sl@0
   109
 *	of the structure changed;
sl@0
   110
 *
sl@0
   111
 *	send mail to "tcpdump-workers@tcpdump.org", requesting a new
sl@0
   112
 *	magic number for your new capture file format, and, when
sl@0
   113
 *	you get the new magic number, put it in "savefile.c";
sl@0
   114
 *
sl@0
   115
 *	use that magic number for save files with the changed file
sl@0
   116
 *	header;
sl@0
   117
 *
sl@0
   118
 *	make the code in "savefile.c" capable of reading files with
sl@0
   119
 *	the old file header as well as files with the new file header
sl@0
   120
 *	(using the magic number to determine the header format).
sl@0
   121
 *
sl@0
   122
 * Then supply the changes to "patches@tcpdump.org", so that future
sl@0
   123
 * versions of libpcap and programs that use it (such as tcpdump) will
sl@0
   124
 * be able to read your new capture file format.
sl@0
   125
 */
sl@0
   126
struct pcap_file_header {
sl@0
   127
	bpf_u_int32 magic;
sl@0
   128
	u_short version_major;
sl@0
   129
	u_short version_minor;
sl@0
   130
	bpf_int32 thiszone;	/* gmt to local correction */
sl@0
   131
	bpf_u_int32 sigfigs;	/* accuracy of timestamps */
sl@0
   132
	bpf_u_int32 snaplen;	/* max length saved portion of each pkt */
sl@0
   133
	bpf_u_int32 linktype;	/* data link type (LINKTYPE_*) */
sl@0
   134
};
sl@0
   135
sl@0
   136
typedef enum {
sl@0
   137
       PCAP_D_INOUT = 0,
sl@0
   138
       PCAP_D_IN,
sl@0
   139
       PCAP_D_OUT
sl@0
   140
} pcap_direction_t;
sl@0
   141
sl@0
   142
/*
sl@0
   143
 * Generic per-packet information, as supplied by libpcap.
sl@0
   144
 *
sl@0
   145
 * The time stamp can and should be a "struct timeval", regardless of
sl@0
   146
 * whether your system supports 32-bit tv_sec in "struct timeval",
sl@0
   147
 * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
sl@0
   148
 * and 64-bit applications.  The on-disk format of savefiles uses 32-bit
sl@0
   149
 * tv_sec (and tv_usec); this structure is irrelevant to that.  32-bit
sl@0
   150
 * and 64-bit versions of libpcap, even if they're on the same platform,
sl@0
   151
 * should supply the appropriate version of "struct timeval", even if
sl@0
   152
 * that's not what the underlying packet capture mechanism supplies.
sl@0
   153
 */
sl@0
   154
struct pcap_pkthdr {
sl@0
   155
	struct timeval ts;	/* time stamp */
sl@0
   156
	bpf_u_int32 caplen;	/* length of portion present */
sl@0
   157
	bpf_u_int32 len;	/* length this packet (off wire) */
sl@0
   158
};
sl@0
   159
sl@0
   160
/*
sl@0
   161
 * As returned by the pcap_stats()
sl@0
   162
 */
sl@0
   163
struct pcap_stat {
sl@0
   164
	u_int ps_recv;		/* number of packets received */
sl@0
   165
	u_int ps_drop;		/* number of packets dropped */
sl@0
   166
	u_int ps_ifdrop;	/* drops by interface XXX not yet supported */
sl@0
   167
#ifdef HAVE_REMOTE
sl@0
   168
	u_int ps_capt;		/* number of packets that are received by the application; please get rid off the Win32 ifdef */
sl@0
   169
	u_int ps_sent;		/* number of packets sent by the server on the network */
sl@0
   170
	u_int ps_netdrop;	/* number of packets lost on the network */
sl@0
   171
#endif /* HAVE_REMOTE */
sl@0
   172
};
sl@0
   173
sl@0
   174
#ifdef MSDOS
sl@0
   175
/*
sl@0
   176
 * As returned by the pcap_stats_ex()
sl@0
   177
 */
sl@0
   178
struct pcap_stat_ex {
sl@0
   179
       u_long  rx_packets;        /* total packets received       */
sl@0
   180
       u_long  tx_packets;        /* total packets transmitted    */
sl@0
   181
       u_long  rx_bytes;          /* total bytes received         */
sl@0
   182
       u_long  tx_bytes;          /* total bytes transmitted      */
sl@0
   183
       u_long  rx_errors;         /* bad packets received         */
sl@0
   184
       u_long  tx_errors;         /* packet transmit problems     */
sl@0
   185
       u_long  rx_dropped;        /* no space in Rx buffers       */
sl@0
   186
       u_long  tx_dropped;        /* no space available for Tx    */
sl@0
   187
       u_long  multicast;         /* multicast packets received   */
sl@0
   188
       u_long  collisions;
sl@0
   189
sl@0
   190
       /* detailed rx_errors: */
sl@0
   191
       u_long  rx_length_errors;
sl@0
   192
       u_long  rx_over_errors;    /* receiver ring buff overflow  */
sl@0
   193
       u_long  rx_crc_errors;     /* recv'd pkt with crc error    */
sl@0
   194
       u_long  rx_frame_errors;   /* recv'd frame alignment error */
sl@0
   195
       u_long  rx_fifo_errors;    /* recv'r fifo overrun          */
sl@0
   196
       u_long  rx_missed_errors;  /* recv'r missed packet         */
sl@0
   197
sl@0
   198
       /* detailed tx_errors */
sl@0
   199
       u_long  tx_aborted_errors;
sl@0
   200
       u_long  tx_carrier_errors;
sl@0
   201
       u_long  tx_fifo_errors;
sl@0
   202
       u_long  tx_heartbeat_errors;
sl@0
   203
       u_long  tx_window_errors;
sl@0
   204
     };
sl@0
   205
#endif
sl@0
   206
sl@0
   207
/*
sl@0
   208
 * Item in a list of interfaces.
sl@0
   209
 */
sl@0
   210
struct pcap_if {
sl@0
   211
	struct pcap_if *next;
sl@0
   212
	char *name;		/* name to hand to "pcap_open_live()" */
sl@0
   213
	char *description;	/* textual description of interface, or NULL */
sl@0
   214
	struct pcap_addr *addresses;
sl@0
   215
	bpf_u_int32 flags;	/* PCAP_IF_ interface flags */
sl@0
   216
};
sl@0
   217
sl@0
   218
#define PCAP_IF_LOOPBACK	0x00000001	/* interface is loopback */
sl@0
   219
sl@0
   220
/*
sl@0
   221
 * Representation of an interface address.
sl@0
   222
 */
sl@0
   223
struct pcap_addr {
sl@0
   224
	struct pcap_addr *next;
sl@0
   225
	struct sockaddr *addr;		/* address */
sl@0
   226
	struct sockaddr *netmask;	/* netmask for that address */
sl@0
   227
	struct sockaddr *broadaddr;	/* broadcast address for that address */
sl@0
   228
	struct sockaddr *dstaddr;	/* P2P destination address for that address */
sl@0
   229
};
sl@0
   230
sl@0
   231
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
sl@0
   232
			     const u_char *);
sl@0
   233
sl@0
   234
char	*pcap_lookupdev(char *);
sl@0
   235
int	pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
sl@0
   236
pcap_t	*pcap_open_live(const char *, int, int, int, char *);
sl@0
   237
pcap_t	*pcap_open_dead(int, int);
sl@0
   238
pcap_t	*pcap_open_offline(const char *, char *);
sl@0
   239
pcap_t	*pcap_fopen_offline(FILE *, char *);
sl@0
   240
void	pcap_close(pcap_t *);
sl@0
   241
int	pcap_loop(pcap_t *, int, pcap_handler, u_char *);
sl@0
   242
int	pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
sl@0
   243
const u_char*
sl@0
   244
	pcap_next(pcap_t *, struct pcap_pkthdr *);
sl@0
   245
int 	pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
sl@0
   246
void	pcap_breakloop(pcap_t *);
sl@0
   247
int	pcap_stats(pcap_t *, struct pcap_stat *);
sl@0
   248
int	pcap_setfilter(pcap_t *, struct bpf_program *);
sl@0
   249
int 	pcap_setdirection(pcap_t *, pcap_direction_t);
sl@0
   250
int	pcap_getnonblock(pcap_t *, char *);
sl@0
   251
int	pcap_setnonblock(pcap_t *, int, char *);
sl@0
   252
void	pcap_perror(pcap_t *, char *);
sl@0
   253
int	pcap_inject(pcap_t *, const void *, size_t);
sl@0
   254
int	pcap_sendpacket(pcap_t *, const u_char *, int);
sl@0
   255
char	*pcap_strerror(int);
sl@0
   256
char	*pcap_geterr(pcap_t *);
sl@0
   257
int	pcap_compile(pcap_t *, struct bpf_program *, char *, int,
sl@0
   258
	    bpf_u_int32);
sl@0
   259
int	pcap_compile_nopcap(int, int, struct bpf_program *,
sl@0
   260
	    char *, int, bpf_u_int32);
sl@0
   261
void	pcap_freecode(struct bpf_program *);
sl@0
   262
int	pcap_datalink(pcap_t *);
sl@0
   263
int	pcap_list_datalinks(pcap_t *, int **);
sl@0
   264
int	pcap_set_datalink(pcap_t *, int);
sl@0
   265
int	pcap_datalink_name_to_val(const char *);
sl@0
   266
const char *pcap_datalink_val_to_name(int);
sl@0
   267
const char *pcap_datalink_val_to_description(int);
sl@0
   268
int	pcap_snapshot(pcap_t *);
sl@0
   269
int	pcap_is_swapped(pcap_t *);
sl@0
   270
int	pcap_major_version(pcap_t *);
sl@0
   271
int	pcap_minor_version(pcap_t *);
sl@0
   272
sl@0
   273
/* XXX */
sl@0
   274
FILE	*pcap_file(pcap_t *);
sl@0
   275
int	pcap_fileno(pcap_t *);
sl@0
   276
sl@0
   277
pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
sl@0
   278
pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
sl@0
   279
FILE	*pcap_dump_file(pcap_dumper_t *);
sl@0
   280
long	pcap_dump_ftell(pcap_dumper_t *);
sl@0
   281
int	pcap_dump_flush(pcap_dumper_t *);
sl@0
   282
void	pcap_dump_close(pcap_dumper_t *);
sl@0
   283
void	pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
sl@0
   284
sl@0
   285
int	pcap_findalldevs(pcap_if_t **, char *);
sl@0
   286
void	pcap_freealldevs(pcap_if_t *);
sl@0
   287
sl@0
   288
const char *pcap_lib_version(void);
sl@0
   289
sl@0
   290
/* XXX this guy lives in the bpf tree */
sl@0
   291
u_int	bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
sl@0
   292
int	bpf_validate(struct bpf_insn *f, int len);
sl@0
   293
char	*bpf_image(struct bpf_insn *, int);
sl@0
   294
void	bpf_dump(struct bpf_program *, int);
sl@0
   295
sl@0
   296
#if defined(WIN32)
sl@0
   297
sl@0
   298
/*
sl@0
   299
 * Win32 definitions
sl@0
   300
 */
sl@0
   301
sl@0
   302
int pcap_setbuff(pcap_t *p, int dim);
sl@0
   303
int pcap_setmode(pcap_t *p, int mode);
sl@0
   304
int pcap_setmintocopy(pcap_t *p, int size);
sl@0
   305
sl@0
   306
#ifdef WPCAP
sl@0
   307
/* Include file with the wpcap-specific extensions */
sl@0
   308
#include <Win32-Extensions.h>
sl@0
   309
#endif /* WPCAP */
sl@0
   310
sl@0
   311
#define MODE_CAPT 0
sl@0
   312
#define MODE_STAT 1
sl@0
   313
#define MODE_MON 2
sl@0
   314
sl@0
   315
#elif defined(MSDOS)
sl@0
   316
sl@0
   317
/*
sl@0
   318
 * MS-DOS definitions
sl@0
   319
 */
sl@0
   320
sl@0
   321
int  pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
sl@0
   322
void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
sl@0
   323
u_long pcap_mac_packets (void);
sl@0
   324
sl@0
   325
#else /* UN*X */
sl@0
   326
sl@0
   327
/*
sl@0
   328
 * UN*X definitions
sl@0
   329
 */
sl@0
   330
sl@0
   331
int	pcap_get_selectable_fd(pcap_t *);
sl@0
   332
sl@0
   333
#endif /* WIN32/MSDOS/UN*X */
sl@0
   334
sl@0
   335
#ifdef HAVE_REMOTE
sl@0
   336
/* Includes most of the public stuff that is needed for the remote capture */
sl@0
   337
#include "remote-ext.h"
sl@0
   338
#endif	 /* HAVE_REMOTE */
sl@0
   339
sl@0
   340
#ifdef __cplusplus
sl@0
   341
}
sl@0
   342
#endif
sl@0
   343
sl@0
   344
#endif