1999-10-07 23:46:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995, 1996
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the Computer Systems
|
|
|
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
|
|
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2008-09-16 00:20:23 +00:00
|
|
|
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.94 2008-09-16 00:20:23 guy Exp $ (LBL)
|
1999-10-07 23:46:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef pcap_int_h
|
2008-03-13 18:13:57 +00:00
|
|
|
#define pcap_int_h
|
1999-10-07 23:46:40 +00:00
|
|
|
|
2007-09-24 23:26:12 +00:00
|
|
|
#include <pcap/pcap.h>
|
2007-09-24 23:24:02 +00:00
|
|
|
|
2000-07-29 07:36:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-03-13 18:13:57 +00:00
|
|
|
#ifdef HAVE_LIBDLPI
|
|
|
|
#include <libdlpi.h>
|
|
|
|
#endif
|
|
|
|
|
2002-08-01 08:33:01 +00:00
|
|
|
#ifdef WIN32
|
2006-02-22 17:09:02 +00:00
|
|
|
#include <Packet32.h>
|
2009-07-15 18:57:07 +00:00
|
|
|
extern CRITICAL_SECTION g_PcapCompileCriticalSection;
|
2002-08-01 08:33:01 +00:00
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2004-12-18 08:52:08 +00:00
|
|
|
#ifdef MSDOS
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2007-09-27 18:01:13 +00:00
|
|
|
#if (defined(_MSC_VER) && (_MSC_VER <= 1200)) /* we are compiling with Visual Studio 6, that doesn't support the LL suffix*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap byte ordering of unsigned long long timestamp on a big endian
|
|
|
|
* machine.
|
|
|
|
*/
|
|
|
|
#define SWAPLL(ull) ((ull & 0xff00000000000000) >> 56) | \
|
|
|
|
((ull & 0x00ff000000000000) >> 40) | \
|
|
|
|
((ull & 0x0000ff0000000000) >> 24) | \
|
|
|
|
((ull & 0x000000ff00000000) >> 8) | \
|
|
|
|
((ull & 0x00000000ff000000) << 8) | \
|
|
|
|
((ull & 0x0000000000ff0000) << 24) | \
|
|
|
|
((ull & 0x000000000000ff00) << 40) | \
|
|
|
|
((ull & 0x00000000000000ff) << 56)
|
|
|
|
|
|
|
|
#else /* A recent Visual studio compiler or not VC */
|
|
|
|
|
2007-01-29 20:08:06 +00:00
|
|
|
/*
|
|
|
|
* Swap byte ordering of unsigned long long timestamp on a big endian
|
|
|
|
* machine.
|
|
|
|
*/
|
|
|
|
#define SWAPLL(ull) ((ull & 0xff00000000000000LL) >> 56) | \
|
|
|
|
((ull & 0x00ff000000000000LL) >> 40) | \
|
|
|
|
((ull & 0x0000ff0000000000LL) >> 24) | \
|
|
|
|
((ull & 0x000000ff00000000LL) >> 8) | \
|
|
|
|
((ull & 0x00000000ff000000LL) << 8) | \
|
|
|
|
((ull & 0x0000000000ff0000LL) << 24) | \
|
|
|
|
((ull & 0x000000000000ff00LL) << 40) | \
|
|
|
|
((ull & 0x00000000000000ffLL) << 56)
|
|
|
|
|
2007-09-27 18:01:13 +00:00
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
/*
|
|
|
|
* Savefile
|
|
|
|
*/
|
2003-10-24 23:55:06 +00:00
|
|
|
typedef enum {
|
|
|
|
NOT_SWAPPED,
|
|
|
|
SWAPPED,
|
|
|
|
MAYBE_SWAPPED
|
|
|
|
} swapped_type_t;
|
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
/*
|
|
|
|
* Used when reading a savefile.
|
|
|
|
*/
|
1999-10-07 23:46:40 +00:00
|
|
|
struct pcap_sf {
|
|
|
|
FILE *rfile;
|
|
|
|
int swapped;
|
2007-09-29 00:29:14 +00:00
|
|
|
size_t hdrsize;
|
2003-10-24 23:55:06 +00:00
|
|
|
swapped_type_t lengths_swapped;
|
1999-10-07 23:46:40 +00:00
|
|
|
int version_major;
|
|
|
|
int version_minor;
|
|
|
|
u_char *base;
|
|
|
|
};
|
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
/*
|
|
|
|
* Used when doing a live capture.
|
|
|
|
*/
|
1999-10-07 23:46:40 +00:00
|
|
|
struct pcap_md {
|
|
|
|
struct pcap_stat stat;
|
|
|
|
/*XXX*/
|
2000-06-08 06:40:09 +00:00
|
|
|
int use_bpf; /* using kernel filter */
|
1999-10-07 23:46:40 +00:00
|
|
|
u_long TotPkts; /* can't oflow for 79 hrs on ether */
|
|
|
|
u_long TotAccepted; /* count accepted by filter */
|
|
|
|
u_long TotDrops; /* count of dropped packets */
|
|
|
|
long TotMissed; /* missed by i/f during this run */
|
|
|
|
long OrigMissed; /* missed by i/f before this run */
|
2004-03-23 19:18:04 +00:00
|
|
|
char *device; /* device name */
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
int timeout; /* timeout for buffering */
|
2009-05-22 12:50:15 +00:00
|
|
|
int must_do_on_close; /* stuff we must do when we close */
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
struct pcap *next; /* list of open pcaps that need stuff cleared on close */
|
1999-10-07 23:46:40 +00:00
|
|
|
#ifdef linux
|
2000-06-08 06:40:09 +00:00
|
|
|
int sock_packet; /* using Linux 2.0 compatible interface */
|
2000-12-21 10:29:21 +00:00
|
|
|
int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */
|
2004-03-23 19:18:04 +00:00
|
|
|
int ifindex; /* interface index of device we're bound to */
|
If we're receiving packets from a PF_PACKET socket, check whether the
interface index of the interface for the packet is the interface index
of the loopback interface and, if it is, check if the packet is an
outgoing packet; if so, ignore it, as we'll also be seeing that packet
as a received packet.
If we don't handle the arphrd type of an interface, and fall back on
cooked mode, report the arphrd type, so we know what type we should
consider supporting (if that type can't be supported well, e.g. if you
don't get any link-layer header, as happens with PPP, we'd be silent).
2000-10-25 07:46:49 +00:00
|
|
|
int lo_ifindex; /* interface index of the loopback device */
|
2005-11-24 19:27:42 +00:00
|
|
|
u_int packets_read; /* count of packets read with recvfrom() */
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
bpf_u_int32 oldmode; /* mode to restore when turning monitor mode off */
|
2009-05-22 12:50:15 +00:00
|
|
|
char *mondevice; /* mac80211 monitor device we created */
|
2009-07-11 18:59:04 +00:00
|
|
|
u_char *mmapbuf; /* memory-mapped region pointer */
|
|
|
|
size_t mmapbuflen; /* size of region */
|
2008-08-06 07:49:19 +00:00
|
|
|
u_int tp_version; /* version of tpacket_hdr for mmaped ring */
|
|
|
|
u_int tp_hdrlen; /* hdrlen of tpacket_hdr for mmaped ring */
|
When doing Linux mmapped capture:
Allocate a buffer into which to copy a packet, and have the
callback for pcap_next() and pcap_next_ex() copy to that buffer
and return a pointer to that buffer; we can't return the packet
data pointer passed to the callback, as, once the callback
returns, that buffer can be overwritten, even before you read
the next packet.
Don't tweak filter programs passed into the kernel to return
65535 on success - we don't have to, as we're not reading
packets with recvfrom(), and we don't want to, as, if we return
the actual snapshot length, the kernel will copy less data to
the ring buffer.
Truncate the packet snapshot length to the specified length, as
we might not have a filter to do that.
2009-07-16 22:08:12 +00:00
|
|
|
u_char *oneshot_buffer; /* buffer for copy of packet */
|
2009-09-07 23:23:15 +00:00
|
|
|
long proc_dropped; /* packets reported dropped by /proc/net/dev */
|
The SITA code in pcap-linux.c shares very little with the Linux code;
move it into pcap-sita.c, and make --with-sita set the pcap type to
"sita", so we build pcap-sita.c instead of, rather than in addition to,
pcap-linux.c.
Use "bpf_u_int32" rather than "ulong" in the SITA code, as it's intended
to be 32 bits long (the "l" in "htonl()" and "ntohl()" is historical -
they work on 32-bit quantities, and the "l" dates back to the days when
32-bit processors were a bit newer and 16-bit Unix was more common).
Those changes also, at least in theory, makes the SITA support work on
other Unix-compatible platforms; note that in README.sita.
Clean up pcap-sita.c, making routines no longer called outside it
static, folding trivial wrappers, and fixing various warnings.
Put the routines used by fad-sita.c and defined by pcap-sita.c into
pcap-sita.h. Remove from pcap-sita.h the files that are now static to
pcap-sita.c. Include pcap-sita.h in both fad-sita.c and pcap-sita.c, so
that we do cross-file prototype checking.
2008-01-06 20:23:17 +00:00
|
|
|
#endif /* linux */
|
2003-07-23 05:29:19 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DAG_API
|
2005-07-07 06:55:19 +00:00
|
|
|
#ifdef HAVE_DAG_STREAMS_API
|
|
|
|
u_char *dag_mem_bottom; /* DAG card current memory bottom pointer */
|
|
|
|
u_char *dag_mem_top; /* DAG card current memory top pointer */
|
The SITA code in pcap-linux.c shares very little with the Linux code;
move it into pcap-sita.c, and make --with-sita set the pcap type to
"sita", so we build pcap-sita.c instead of, rather than in addition to,
pcap-linux.c.
Use "bpf_u_int32" rather than "ulong" in the SITA code, as it's intended
to be 32 bits long (the "l" in "htonl()" and "ntohl()" is historical -
they work on 32-bit quantities, and the "l" dates back to the days when
32-bit processors were a bit newer and 16-bit Unix was more common).
Those changes also, at least in theory, makes the SITA support work on
other Unix-compatible platforms; note that in README.sita.
Clean up pcap-sita.c, making routines no longer called outside it
static, folding trivial wrappers, and fixing various warnings.
Put the routines used by fad-sita.c and defined by pcap-sita.c into
pcap-sita.h. Remove from pcap-sita.h the files that are now static to
pcap-sita.c. Include pcap-sita.h in both fad-sita.c and pcap-sita.c, so
that we do cross-file prototype checking.
2008-01-06 20:23:17 +00:00
|
|
|
#else /* HAVE_DAG_STREAMS_API */
|
2003-07-23 05:29:19 +00:00
|
|
|
void *dag_mem_base; /* DAG card memory base address */
|
2005-07-07 06:55:19 +00:00
|
|
|
u_int dag_mem_bottom; /* DAG card current memory bottom offset */
|
|
|
|
u_int dag_mem_top; /* DAG card current memory top offset */
|
|
|
|
#endif /* HAVE_DAG_STREAMS_API */
|
2003-07-25 06:36:23 +00:00
|
|
|
int dag_fcs_bits; /* Number of checksum bits from link layer */
|
2004-04-03 20:52:41 +00:00
|
|
|
int dag_offset_flags; /* Flags to pass to dag_offset(). */
|
2005-07-07 06:55:19 +00:00
|
|
|
int dag_stream; /* DAG stream number */
|
|
|
|
int dag_timeout; /* timeout specified to pcap_open_live.
|
|
|
|
* Same as in linux above, introduce
|
|
|
|
* generally? */
|
|
|
|
#endif /* HAVE_DAG_API */
|
2008-09-16 00:20:23 +00:00
|
|
|
#ifdef HAVE_ZEROCOPY_BPF
|
|
|
|
/*
|
|
|
|
* Zero-copy read buffer -- for zero-copy BPF. 'buffer' above will
|
|
|
|
* alternative between these two actual mmap'd buffers as required.
|
|
|
|
* As there is a header on the front size of the mmap'd buffer, only
|
|
|
|
* some of the buffer is exposed to libpcap as a whole via bufsize;
|
|
|
|
* zbufsize is the true size. zbuffer tracks the current zbuf
|
|
|
|
* assocated with buffer so that it can be used to decide which the
|
|
|
|
* next buffer to read will be.
|
|
|
|
*/
|
|
|
|
u_char *zbuf1, *zbuf2, *zbuffer;
|
|
|
|
u_int zbufsize;
|
|
|
|
u_int zerocopy;
|
|
|
|
u_int interrupted;
|
|
|
|
struct timespec firstsel;
|
|
|
|
/*
|
|
|
|
* If there's currently a buffer being actively processed, then it is
|
|
|
|
* referenced here; 'buffer' is also pointed at it, but offset by the
|
|
|
|
* size of the header.
|
|
|
|
*/
|
|
|
|
struct bpf_zbuf_header *bzh;
|
|
|
|
#endif /* HAVE_ZEROCOPY_BPF */
|
1999-10-07 23:46:40 +00:00
|
|
|
};
|
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
/*
|
2009-05-22 12:50:15 +00:00
|
|
|
* Stuff to do when we close.
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
*/
|
2009-05-22 12:50:15 +00:00
|
|
|
#define MUST_CLEAR_PROMISC 0x00000001 /* clear promiscuous mode */
|
|
|
|
#define MUST_CLEAR_RFMON 0x00000002 /* clear rfmon (monitor) mode */
|
|
|
|
#define MUST_DELETE_MONIF 0x00000004 /* delete monitor-mode interface */
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
|
|
|
|
struct pcap_opt {
|
|
|
|
int buffer_size;
|
|
|
|
char *source;
|
|
|
|
int promisc;
|
|
|
|
int rfmon;
|
|
|
|
};
|
|
|
|
|
2005-04-07 02:47:34 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2007-03-11 21:44:12 +00:00
|
|
|
* Tru64 UNIX, and some versions of NetBSD pad FDDI packets to make everything
|
|
|
|
* line up on a nice boundary.
|
2005-04-07 02:47:34 +00:00
|
|
|
*/
|
2007-03-11 21:44:12 +00:00
|
|
|
#ifdef __NetBSD__
|
|
|
|
#include <sys/param.h> /* needed to declare __NetBSD_Version__ */
|
|
|
|
#endif
|
|
|
|
|
2005-04-07 02:47:34 +00:00
|
|
|
#if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000)
|
|
|
|
#define PCAP_FDDIPAD 3
|
|
|
|
#endif
|
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
typedef int (*activate_op_t)(pcap_t *);
|
|
|
|
typedef int (*can_set_rfmon_op_t)(pcap_t *);
|
|
|
|
typedef int (*read_op_t)(pcap_t *, int cnt, pcap_handler, u_char *);
|
|
|
|
typedef int (*inject_op_t)(pcap_t *, const void *, size_t);
|
|
|
|
typedef int (*setfilter_op_t)(pcap_t *, struct bpf_program *);
|
|
|
|
typedef int (*setdirection_op_t)(pcap_t *, pcap_direction_t);
|
|
|
|
typedef int (*set_datalink_op_t)(pcap_t *, int);
|
|
|
|
typedef int (*getnonblock_op_t)(pcap_t *, char *);
|
|
|
|
typedef int (*setnonblock_op_t)(pcap_t *, int, char *);
|
|
|
|
typedef int (*stats_op_t)(pcap_t *, struct pcap_stat *);
|
|
|
|
#ifdef WIN32
|
|
|
|
typedef int (*setbuff_op_t)(pcap_t *, int);
|
|
|
|
typedef int (*setmode_op_t)(pcap_t *, int);
|
|
|
|
typedef int (*setmintocopy_op_t)(pcap_t *, int);
|
|
|
|
#endif
|
2008-04-14 20:40:58 +00:00
|
|
|
typedef void (*cleanup_op_t)(pcap_t *);
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
struct pcap {
|
2002-08-01 08:33:01 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
ADAPTER *adapter;
|
|
|
|
LPPACKET Packet;
|
|
|
|
int nonblock;
|
|
|
|
#else
|
1999-10-07 23:46:40 +00:00
|
|
|
int fd;
|
2003-12-20 10:24:52 +00:00
|
|
|
int selectable_fd;
|
2004-04-03 20:52:41 +00:00
|
|
|
int send_fd;
|
2003-12-21 22:00:10 +00:00
|
|
|
#endif /* WIN32 */
|
2008-03-13 18:13:57 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBDLPI
|
|
|
|
dlpi_handle_t dlpi_hd;
|
|
|
|
#endif
|
1999-10-07 23:46:40 +00:00
|
|
|
int snapshot;
|
2007-09-29 19:33:29 +00:00
|
|
|
int linktype; /* Network linktype */
|
|
|
|
int linktype_ext; /* Extended information stored in the linktype field of a file */
|
1999-10-07 23:46:40 +00:00
|
|
|
int tzoff; /* timezone offset */
|
|
|
|
int offset; /* offset for proper alignment */
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
int activated; /* true if the capture is really started */
|
|
|
|
int oldstyle; /* if we're opening with pcap_open_live() */
|
1999-10-07 23:46:40 +00:00
|
|
|
|
2003-11-04 07:05:32 +00:00
|
|
|
int break_loop; /* flag set to force break from packet-reading loop */
|
|
|
|
|
2004-12-15 00:25:08 +00:00
|
|
|
#ifdef PCAP_FDDIPAD
|
|
|
|
int fddipad;
|
|
|
|
#endif
|
|
|
|
|
2004-12-18 08:52:08 +00:00
|
|
|
#ifdef MSDOS
|
|
|
|
void (*wait_proc)(void); /* call proc while waiting */
|
|
|
|
#endif
|
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
struct pcap_sf sf;
|
|
|
|
struct pcap_md md;
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
struct pcap_opt opt;
|
1999-10-07 23:46:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read buffer.
|
|
|
|
*/
|
|
|
|
int bufsize;
|
|
|
|
u_char *buffer;
|
|
|
|
u_char *bp;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place holder for pcap_next().
|
|
|
|
*/
|
|
|
|
u_char *pkt;
|
|
|
|
|
2005-05-03 18:53:58 +00:00
|
|
|
/* We're accepting only packets in this direction/these directions. */
|
2005-07-07 01:57:00 +00:00
|
|
|
pcap_direction_t direction;
|
2005-05-03 18:53:58 +00:00
|
|
|
|
2003-07-25 03:25:45 +00:00
|
|
|
/*
|
|
|
|
* Methods.
|
|
|
|
*/
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
activate_op_t activate_op;
|
|
|
|
can_set_rfmon_op_t can_set_rfmon_op;
|
|
|
|
read_op_t read_op;
|
|
|
|
inject_op_t inject_op;
|
|
|
|
setfilter_op_t setfilter_op;
|
|
|
|
setdirection_op_t setdirection_op;
|
|
|
|
set_datalink_op_t set_datalink_op;
|
|
|
|
getnonblock_op_t getnonblock_op;
|
|
|
|
setnonblock_op_t setnonblock_op;
|
|
|
|
stats_op_t stats_op;
|
2007-10-17 18:52:41 +00:00
|
|
|
|
When doing Linux mmapped capture:
Allocate a buffer into which to copy a packet, and have the
callback for pcap_next() and pcap_next_ex() copy to that buffer
and return a pointer to that buffer; we can't return the packet
data pointer passed to the callback, as, once the callback
returns, that buffer can be overwritten, even before you read
the next packet.
Don't tweak filter programs passed into the kernel to return
65535 on success - we don't have to, as we're not reading
packets with recvfrom(), and we don't want to, as, if we return
the actual snapshot length, the kernel will copy less data to
the ring buffer.
Truncate the packet snapshot length to the specified length, as
we might not have a filter to do that.
2009-07-16 22:08:12 +00:00
|
|
|
/*
|
|
|
|
* Routine to use as callback for pcap_next()/pcap_next_ex().
|
|
|
|
*/
|
|
|
|
pcap_handler oneshot_callback;
|
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
#ifdef WIN32
|
2007-10-17 18:52:41 +00:00
|
|
|
/*
|
|
|
|
* These are, at least currently, specific to the Win32 NPF
|
|
|
|
* driver.
|
|
|
|
*/
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
setbuff_op_t setbuff_op;
|
|
|
|
setmode_op_t setmode_op;
|
|
|
|
setmintocopy_op_t setmintocopy_op;
|
2007-10-17 18:52:41 +00:00
|
|
|
#endif
|
2008-04-14 20:40:58 +00:00
|
|
|
cleanup_op_t cleanup_op;
|
2002-06-11 17:04:44 +00:00
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
/*
|
|
|
|
* Placeholder for filter code if bpf not in kernel.
|
|
|
|
*/
|
|
|
|
struct bpf_program fcode;
|
|
|
|
|
2002-08-20 15:33:31 +00:00
|
|
|
char errbuf[PCAP_ERRBUF_SIZE + 1];
|
2002-12-19 09:05:45 +00:00
|
|
|
int dlt_count;
|
2004-04-07 18:41:00 +00:00
|
|
|
u_int *dlt_list;
|
2003-04-09 10:06:44 +00:00
|
|
|
|
|
|
|
struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */
|
1999-10-07 23:46:40 +00:00
|
|
|
};
|
|
|
|
|
1999-11-21 01:10:20 +00:00
|
|
|
/*
|
2006-02-09 22:26:12 +00:00
|
|
|
* This is a timeval as stored in a savefile.
|
1999-11-21 01:10:20 +00:00
|
|
|
* It has to use the same types everywhere, independent of the actual
|
2006-02-09 22:26:12 +00:00
|
|
|
* `struct timeval'; `struct timeval' has 32-bit tv_sec values on some
|
|
|
|
* platforms and 64-bit tv_sec values on other platforms, and writing
|
|
|
|
* out native `struct timeval' values would mean files could only be
|
|
|
|
* read on systems with the same tv_sec size as the system on which
|
|
|
|
* the file was written.
|
1999-11-21 01:10:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pcap_timeval {
|
|
|
|
bpf_int32 tv_sec; /* seconds */
|
|
|
|
bpf_int32 tv_usec; /* microseconds */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2006-02-09 22:26:12 +00:00
|
|
|
* This is a `pcap_pkthdr' as actually stored in a savefile.
|
2000-09-14 09:49:28 +00:00
|
|
|
*
|
|
|
|
* Do not change the format of this structure, in any way (this includes
|
|
|
|
* changes that only affect the length of fields in this structure),
|
|
|
|
* and do not make the time stamp anything other than seconds and
|
|
|
|
* microseconds (e.g., seconds and nanoseconds). Instead:
|
|
|
|
*
|
|
|
|
* introduce a new structure for the new format;
|
|
|
|
*
|
2008-05-30 01:35:33 +00:00
|
|
|
* send mail to "tcpdump-workers@lists.tcpdump.org", requesting
|
|
|
|
* a new magic number for your new capture file format, and, when
|
2000-09-14 09:49:28 +00:00
|
|
|
* you get the new magic number, put it in "savefile.c";
|
|
|
|
*
|
|
|
|
* use that magic number for save files with the changed record
|
|
|
|
* header;
|
|
|
|
*
|
|
|
|
* make the code in "savefile.c" capable of reading files with
|
|
|
|
* the old record header as well as files with the new record header
|
|
|
|
* (using the magic number to determine the header format).
|
|
|
|
*
|
2008-05-30 01:43:21 +00:00
|
|
|
* Then supply the changes as a patch at
|
|
|
|
*
|
|
|
|
* http://sourceforge.net/projects/libpcap/
|
|
|
|
*
|
|
|
|
* so that future versions of libpcap and programs that use it (such as
|
|
|
|
* tcpdump) will be able to read your new capture file format.
|
1999-11-21 01:10:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pcap_sf_pkthdr {
|
|
|
|
struct pcap_timeval ts; /* time stamp */
|
|
|
|
bpf_u_int32 caplen; /* length of portion present */
|
|
|
|
bpf_u_int32 len; /* length this packet (off wire) */
|
|
|
|
};
|
|
|
|
|
2000-07-18 03:43:47 +00:00
|
|
|
/*
|
2006-02-09 22:26:12 +00:00
|
|
|
* How a `pcap_pkthdr' is actually stored in savefiles written
|
2000-07-18 03:43:47 +00:00
|
|
|
* by some patched versions of libpcap (e.g. the ones in Red
|
|
|
|
* Hat Linux 6.1 and 6.2).
|
2000-09-14 09:49:28 +00:00
|
|
|
*
|
|
|
|
* Do not change the format of this structure, in any way (this includes
|
|
|
|
* changes that only affect the length of fields in this structure).
|
|
|
|
* Instead, introduce a new structure, as per the above.
|
2000-07-18 03:43:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pcap_sf_patched_pkthdr {
|
|
|
|
struct pcap_timeval ts; /* time stamp */
|
|
|
|
bpf_u_int32 caplen; /* length of portion present */
|
|
|
|
bpf_u_int32 len; /* length this packet (off wire) */
|
|
|
|
int index;
|
|
|
|
unsigned short protocol;
|
|
|
|
unsigned char pkt_type;
|
|
|
|
};
|
|
|
|
|
When doing Linux mmapped capture:
Allocate a buffer into which to copy a packet, and have the
callback for pcap_next() and pcap_next_ex() copy to that buffer
and return a pointer to that buffer; we can't return the packet
data pointer passed to the callback, as, once the callback
returns, that buffer can be overwritten, even before you read
the next packet.
Don't tweak filter programs passed into the kernel to return
65535 on success - we don't have to, as we're not reading
packets with recvfrom(), and we don't want to, as, if we return
the actual snapshot length, the kernel will copy less data to
the ring buffer.
Truncate the packet snapshot length to the specified length, as
we might not have a filter to do that.
2009-07-16 22:08:12 +00:00
|
|
|
/*
|
|
|
|
* User data structure for the one-shot callback used for pcap_next()
|
|
|
|
* and pcap_next_ex().
|
|
|
|
*/
|
|
|
|
struct oneshot_userdata {
|
|
|
|
struct pcap_pkthdr *hdr;
|
|
|
|
const u_char **pkt;
|
|
|
|
pcap_t *pd;
|
|
|
|
};
|
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
int yylex(void);
|
|
|
|
|
|
|
|
#ifndef min
|
|
|
|
#define min(a, b) ((a) > (b) ? (b) : (a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* XXX should these be in pcap.h? */
|
|
|
|
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
|
|
|
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
|
|
|
|
|
2000-05-04 13:34:24 +00:00
|
|
|
#ifndef HAVE_STRLCPY
|
|
|
|
#define strlcpy(x, y, z) \
|
2000-07-04 00:22:03 +00:00
|
|
|
(strncpy((x), (y), (z)), \
|
|
|
|
((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \
|
|
|
|
strlen((y)))
|
2000-05-04 13:34:24 +00:00
|
|
|
#endif
|
|
|
|
|
2003-12-15 01:35:03 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#if !defined(HAVE_SNPRINTF)
|
|
|
|
#define snprintf pcap_snprintf
|
|
|
|
extern int snprintf (char *, size_t, const char *, ...);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(HAVE_VSNPRINTF)
|
|
|
|
#define vsnprintf pcap_vsnprintf
|
|
|
|
extern int vsnprintf (char *, size_t, const char *, va_list ap);
|
|
|
|
#endif
|
|
|
|
|
2002-12-19 09:05:45 +00:00
|
|
|
/*
|
2003-11-20 02:02:38 +00:00
|
|
|
* Routines that most pcap implementations can use for non-blocking mode.
|
2002-12-19 09:05:45 +00:00
|
|
|
*/
|
2004-12-18 08:52:08 +00:00
|
|
|
#if !defined(WIN32) && !defined(MSDOS)
|
2003-11-20 02:02:38 +00:00
|
|
|
int pcap_getnonblock_fd(pcap_t *, char *);
|
|
|
|
int pcap_setnonblock_fd(pcap_t *p, int, char *);
|
|
|
|
#endif
|
2002-12-19 09:05:45 +00:00
|
|
|
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
pcap_t *pcap_create_common(const char *, char *);
|
|
|
|
int pcap_do_addexit(pcap_t *);
|
|
|
|
void pcap_add_to_pcaps_to_close(pcap_t *);
|
|
|
|
void pcap_remove_from_pcaps_to_close(pcap_t *);
|
2008-04-14 20:40:58 +00:00
|
|
|
void pcap_cleanup_live_common(pcap_t *);
|
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.
Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5. (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)
Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
|
|
|
int pcap_not_initialized(pcap_t *);
|
|
|
|
int pcap_check_activated(pcap_t *);
|
2004-10-19 07:06:11 +00:00
|
|
|
|
2002-07-11 09:06:30 +00:00
|
|
|
/*
|
|
|
|
* Internal interfaces for "pcap_findalldevs()".
|
|
|
|
*
|
|
|
|
* "pcap_platform_finddevs()" is a platform-dependent routine to
|
|
|
|
* add devices not found by the "standard" mechanisms (SIOCGIFCONF,
|
|
|
|
* "getifaddrs()", etc..
|
|
|
|
*
|
|
|
|
* "pcap_add_if()" adds an interface to the list of interfaces.
|
|
|
|
*/
|
|
|
|
int pcap_platform_finddevs(pcap_if_t **, char *);
|
2004-12-17 20:32:35 +00:00
|
|
|
int add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *,
|
2002-07-30 08:12:13 +00:00
|
|
|
size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
|
|
|
|
struct sockaddr *, size_t, char *);
|
2004-12-17 20:32:35 +00:00
|
|
|
int pcap_add_if(pcap_if_t **, const char *, u_int, const char *, char *);
|
2002-08-02 03:25:32 +00:00
|
|
|
struct sockaddr *dup_sockaddr(struct sockaddr *, size_t);
|
2002-12-22 02:36:48 +00:00
|
|
|
int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int,
|
2002-08-02 03:25:32 +00:00
|
|
|
const char *, char *);
|
2002-07-11 09:06:30 +00:00
|
|
|
|
2002-08-01 08:33:01 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
char *pcap_win32strerror(void);
|
|
|
|
#endif
|
|
|
|
|
2000-11-04 10:09:55 +00:00
|
|
|
int install_bpf_program(pcap_t *, struct bpf_program *);
|
|
|
|
|
2003-04-10 06:07:08 +00:00
|
|
|
int pcap_strcasecmp(const char *, const char *);
|
|
|
|
|
2000-07-29 07:36:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-07 23:46:40 +00:00
|
|
|
#endif
|