MFV r276759: libpcap 1.6.2.

MFC after:	1 month
This commit is contained in:
Xin LI 2015-01-06 22:29:12 +00:00
commit 681ed54caa
176 changed files with 11843 additions and 10579 deletions

View File

@ -1,9 +1,66 @@
Monday March 18, 2013 guy@alum.mit.edu
Monday Aug. 12, 2014 guy@alum.mit.edu
Summary for 1.6.2 tcpdump release
Don't crash on filters testing a non-existent link-layer type
field.
Fix sending in non-blocking mode on Linux with memory-mapped
capture.
Fix timestamps when reading pcap-ng files on big-endian
machines.
Saturday Jul. 19, 2014 mcr@sandelman.ca
Summary for 1.6.1 tcpdump release
some fixes for the any device
changes for how --enable-XXX works
Wednesday Jul. 2, 2014 mcr@sandelman.ca
Summary for 1.6.0 tcpdump release
Don't support D-Bus sniffing on OS X
fixes for byte order issues with NFLOG captures
Handle using cooked mode for DLT_NETLINK in activate_new().
on platforms where you can not capture on down interfaces, do not list them
but: do list interfaces which are down, if you can capture on them!
Wednesday December 18, 2013 guy@alum.mit.edu
Summary for 1.5.3 libpcap release
Don't let packets that don't match the current filter get to the
application when TPACKET_V3 is used. (GitHub issue #331)
Fix handling of pcap_loop()/pcap_dispatch() with a packet count
of 0 on some platforms (including Linux with TPACKET_V3).
(GitHub issue #333)
Work around TPACKET_V3 deficiency that causes packets to be lost
when a timeout of 0 is specified. (GitHub issue #335)
Man page formatting fixes.
Wednesday December 4, 2013 guy@alum.mit.edu
Summary for 1.5.2 libpcap release
Fix libpcap to work when compiled with TPACKET_V3 support and
running on a kernel without TPACKET_V3 support. (GitHub
issue #329)
Wednesday November 20, 2013 guy@alum.mit.edu
Summary for 1.5.1 libpcap release
Report an error, rather than crashing, if an IPv6 address is
used for link-layer filtering. (Wireshark bug 9376)
Wednesday October 30, 2013 guy@alum.mit.edu
Summary for 1.5.0 libpcap release
TPACKET_V3 support added for Linux
Point users to the the-tcpdump-group repository on GitHub rather
than the mcr repository
Checks added for malloc()/realloc()/etc. failures
Fixed build on Solaris 11
Support filtering filtering E1 SS7 traffic on MTP2 layer Annex A
Use "ln -s" to link man pages by default
Add support for getting nanosecond-resolution time stamps when
capturing and reading capture files
Many changes to autoconf to deal better with non-GCC compilers
added many new DLT types
Saturday April 6, 2013 guy@alum.mit.edu
Summary for 1.4.0 libpcap release
Add netfilter/nfqueue interface.
If we don't have support for IPv6 address resolution, support,
in filter expressions, what IPv6 stuff we can.
Checks added for malloc()/realloc()/etc. failures.
Fix pcap-config to include -lpthread if canusb support is
present
Try to fix "pcap_parse not defined" problems when --without-flex
@ -29,6 +86,7 @@ Summary for 1.4.0 libpcap release
kernels, for VLAN tag valid flag
Clean up some man pages
Support libnl3 as well as libnl1 and libnl2 on Linux
Fix handling of Bluetooth devices on 3.x Linux kernels
Friday March 30, 2012. mcr@sandelman.ca
Summary for 1.3.0 libpcap release
@ -208,7 +266,7 @@ Mon. October 27, 2008. ken@netfunctional.ca. Summary for 1.0.0 libpcap rele
DLT: Add JUNIPER_ST
802.15.4 support
Variable length 802.11 header support
X2E data type support
X2E data type support
SITA ACN Interface support - see README.sita
Support for memory-mapped capture on Linux
Support for zerocopy BPF on platforms that support it
@ -220,7 +278,7 @@ Mon. October 27, 2008. ken@netfunctional.ca. Summary for 1.0.0 libpcap rele
can print better diagnostic information
Return PCAP_ERROR_PERM_DENIED if we don't have permission to open a device, so
applications can tell the user they need to go play with permissions
On Linux, ignore ENETDOWN so we can continue to capture packets if the
On Linux, ignore ENETDOWN so we can continue to capture packets if the
interface goes down and comes back up again.
On Linux, support new tpacket frame headers (2.6.27+)
On Mac OS X, add scripts for changing permissions on /dev/bpf* and launchd plist
@ -233,14 +291,14 @@ Mon. September 10, 2007. ken@xelerance.com. Summary for 0.9.8 libpcap relea
Change build process to put public libpcap headers into pcap subir
DLT: Add value for IPMI IPMB packets
DLT: Add value for u10 Networks boards
Require <net/pfvar.h> for pf definitions - allows reading of pflog formatted
Require <net/pfvar.h> for pf definitions - allows reading of pflog formatted
libpcap files on an OS other than where the file was generated
Wed. April 25, 2007. ken@xelerance.com. Summary for 0.9.6 libpcap release
Put the public libpcap headers into a pcap subdirectory in both the
source directory and the target include directory, and have include
files at the top-level directory to include those headers, for
files at the top-level directory to include those headers, for
backwards compatibility.
Add Bluetooth support
Add USB capturing support on Linux
@ -248,30 +306,30 @@ Wed. April 25, 2007. ken@xelerance.com. Summary for 0.9.6 libpcap release
Add support for new FreeBSD BIOCSDIRECTION ioctl
Add additional filter operations for 802.11 frame types
Add support for filtering on MTP2 frame types
Propagate some changes from the main branch, so the x.9 branch has
Propagate some changes from the main branch, so the x.9 branch has
all the DLT_ and LINKTYPE_ values that the main branch does
Reserved a DLT_ and SAVEFILE_ value for PPI (Per Packet Info)
Reserved a DLT_ and SAVEFILE_ value for PPI (Per Packet Info)
encapsulated packets
Add LINKTYPE_ for IEEE 802.15.4, with address fields padded as done
Add LINKTYPE_ for IEEE 802.15.4, with address fields padded as done
by Linux drivers
Add LINKTYPE_ value corresponding to DLT_IEEE802_16_MAC_CPS.
Add DLT for IEEE 802.16 (WiMAX) MAC Common Part Sublayer
Add DLT for Bluetooth HCI UART transport layer
When building a shared library, build with "-fPIC" on Linux to support x86_64
Link with "$(CC) -shared" rather than "ld -shared" when building a
Link with "$(CC) -shared" rather than "ld -shared" when building a
".so" shared library
Add support for autoconf 2.60
Fixes to discard unread packets when changing filters
Changes to handle name changes in the DAG library resulting from
Changes to handle name changes in the DAG library resulting from
switching to libtool.
Add support for new DAG ERF types.
Add an explicit "-ldag" when building the shared library, so the DAG
Add an explicit "-ldag" when building the shared library, so the DAG
library dependency is explicit.
Mac OSX fixes for dealing with "wlt" devices
Fixes in add_or_find_if() & pcap_findalldevs() to optimize generating
device lists
Fixed a bug in pcap_open_live(). The return value of PacketSetHwFilter
was not checked.
was not checked.
Tue. September 19, 2006. ken@xelerance.com. Summary for 0.9.5 libpcap release
@ -283,19 +341,19 @@ Tue. September 19, 2006. ken@xelerance.com. Summary for 0.9.5 libpcap release
OP_PACKET now matches the beginning of the packet, instead of
beginning+link-layer
Add DLT/LINKTYPE for carrying FRF.16 Multi-link Frame Relay
Fix allocation of buffer for list of link-layer types
Fix allocation of buffer for list of link-layer types
Added a new DLT and LINKTYPE value for ARINC 653 Interpartition Communcation Messages
Fixed a typo in a DLT value: it should start with DLT_ and not LINKTYPE_
Redefined DLT_CAN20B and LINKTYPE_CAN20B as #190 (as this is the right value for CAN).
Added definition for DLT_A429 and LINKTYPE_A429 as #184.
Added a new DLT and LINKTYPE value for CAN v2.0B frames.
Add support for DLT_JUNIPER_VP.
Don't double-count received packets on Linux systems that
support the PACKET_STATISTICS getsockopt() argument on
Don't double-count received packets on Linux systems that
support the PACKET_STATISTICS getsockopt() argument on
PF_PACKET sockets.
Add support for DLT_IEEE802_11 and DLT_IEEE802_11_RADIO link
Add support for DLT_IEEE802_11 and DLT_IEEE802_11_RADIO link
layers in Windows
Add support to build libpcap.lib and wpcap.dll under Cygnus and
Add support to build libpcap.lib and wpcap.dll under Cygnus and
MingW32.
Mon. September 5, 2005. ken@xelerance.com. Summary for 0.9.4 libpcap release

View File

@ -2,6 +2,7 @@ This file lists people who have contributed to libpcap:
The current maintainers:
Bill Fenner <fenner at research dot att dot com>
Denis Ovsienko <infrastation at yandex dot ru>
Fulvio Risso <risso at polito dot it>
Guy Harris <guy at alum dot mit dot edu>
Hannes Gredler <hannes at juniper dot net>
@ -9,20 +10,24 @@ The current maintainers:
Additional people who have contributed patches:
Akos Vandra <axos88 at gmail dot com>
Alan Bawden <Alan at LCS dot MIT dot EDU>
Albert Chin <china at thewrittenword dot com>
Alexander 'Leo' Bergolth <Leo dot Bergolth at wu-wien dot ac dot at>
Alexey Kuznetsov <kuznet at ms2 dot inr dot ac dot ru>
Alon Bar-Lev <alonbl at sourceforge dot net>
Andres Perera <andres dot p at zoho dot com>
Andrew Brown <atatat at atatdot dot net>
<andy-1 at sourceforge dot net>
Ani Sinha <ani at aristanetworks dot com>
Antti Kantee <pooka at netbsd dot org>
Arien Vijn <arienvijn at sourceforge dot net>
Arkadiusz Miskiewicz <misiek at pld dot org dot pl>
Armando L. Caro Jr. <acaro at mail dot eecis dot udel dot edu>
Assar Westerlund <assar at sics dot se>
Bill Parker <wp02855 at gmail dot com>
Brent Cook <brent at boundary dot com>
Brian Ginsbach <ginsbach at cray dot com>
Bill Parker <wp02855 at gmail dot com>
Charles M. Hannum <mycroft at netbsd dot org>
Chris G. Demetriou <cgd at netbsd dot org>
Chris Lightfoot <cwrl at users dot sourceforge dot net>
@ -30,15 +35,21 @@ Additional people who have contributed patches:
Chris Pepper <pepper at mail dot reppep dot com>
Christian Bell <csbell at myri dot com>
Christian Peron <csjp at freebsd dot org>
Christian Svensson <blue at cmd dot nu>
Daniele Orlandi <daniele at orlandi dot com>
Darren Lim <darren dot lim at endace dot com>
Darren Reed <darrenr at sun dot com>
David Clark <david dot clark at datasoft dot com>
David Kaelbling <drk at sgi dot com>
David Ward <david dot ward at ll dot mit dot edu>
David Young <dyoung at ojctech dot com>
Dean Gaudet <dean at arctic dot org>
dhruv <rsrivat at sourceforge dot net>
Don Ebright <Don dot Ebright at compuware dot com>
Dug Song <dugsong at monkey dot org>
Dustin Spicuzza <dustin at virtualroadside dot com>
dzejarczech <dzejarczech at sourceforge dot net>
Edward Sheldrake <ejs1920 at sourceforge dot net>
Eric Anderson <anderse at hpl dot hp dot com>
Erik de Castro Lopo <erik dot de dot castro dot lopo at sensorynetworks dot com>
Felix Obenhuber <felix at obenhuber dot de>
@ -47,15 +58,18 @@ Additional people who have contributed patches:
frederich <frederich at sourceforge dot net>
Fulko Hew <fulko dot hew at gmail dot com>
Fumiyuki Shimizu <fumifumi at abacustech dot jp>
Gabor Tatarka <gabor dot tatarka at ericsson dot com>
Garrett Cooper <yaberauneya at sourceforge dot net>
George Neville-Neil <gnn at freebsd dot org>
Gianluca Varenni <gianluca dot varenni at gmail dot com>
Gilbert Hoyek <gil_hoyek at hotmail dot com>
Gisle Vanem <gvanem at broadpark dot no>
Graeme Hewson <ghewson at cix dot compulink dot co dot uk>
Gregor Maier <gregor at net dot in dot tum dot de>
Greg Stark <gsstark at mit dot edu>
Greg Troxel <gdt at ir dot bbn dot com>
Gregor Maier <gregor at net dot in dot tum dot de>
Guillaume Pelat <endymion_ at users dot sourceforge dot net>
Gustavo Zacarias <gustavo at zacarias dot com dot ar>
Hagen Paul Pfeifer <hagen at jauu dot net>
Henri Doreau <hdoreau at sourceforge dot net>
Hyung Sik Yoon <hsyn at kr dot ibm dot com>
@ -64,15 +78,17 @@ Additional people who have contributed patches:
Jan-Philip Velders <jpv at veldersjes dot net>
Jason R. Thorpe <thorpej at netbsd dot org>
Javier Achirica <achirica at ttd dot net>
Jean-Louis Charton <Jean-Louis dot CHARTON at oikialog dot com>
Jean Tourrilhes <jt at hpl dot hp dot com>
Jean-Louis Charton <Jean-Louis.CHARTON at oikialog dot com>
Jefferson Ogata <jogata at nodc dot noaa dot gov>
Jesper Dangaard Brouer <hawk at comx dot dk>
Jesper Peterson <jesper at endace dot com>
Jiri Slaby <jirislaby at gmail dot com>
Joerg Mayer <jmayer at loplof dot de>
John Bankier <jbankier at rainfinity dot com>
Jon Lindgren <jonl at yubyub dot net>
Jon Smirl <jonsmirl at gmail dot com>
Jorge Boncompte [DTI2] <jorge at dti2 dot net>
Juergen Schoenwaelder <schoenw at ibr dot cs dot tu-bs dot de>
Julien Moutinho <julm at savines dot alpes dot fr dot eu dot org>
Jung-uk Kim <jkim at FreeBSD dot org>
@ -86,6 +102,7 @@ Additional people who have contributed patches:
Love Hörnquist-Åstrand <lha at stacken dot kth dot se>
Luis MartinGarcia <luis dot mgarc at gmail dot com>
Maciej W. Rozycki <macro at ds2 dot pg dot gda dot pl>
Mansour Behabadi <mansour at oxplot dot com>
Marcus Felipe Pereira <marcus at task dot com dot br>
Mark C. Brown <mbrown at hp dot com>
Mark Pizzolato <List-tcpdump-workers at subscriptions dot pizzolato dot net>
@ -94,14 +111,17 @@ Additional people who have contributed patches:
Márton Németh <nm127 at freemail dot hu>
Matthew Luckie <mjl at luckie dot org dot nz>
Max Laier <max at love2party dot net>
Michal Labedzki <michal dot labedzki at tieto dot com>
Michal Sekletar <msekleta at redhat dot com>
Mike Frysinger <vapier at gmail dot com>
Mike Kershaw <dragorn at kismetwireless dot net>
Mike Wiacek <mike at iroot dot net>
Miroslav Lichvar <mlichvar at redhat dot com>
Monroe Williams <monroe at pobox dot com>
<nvercamm at sourceforge dot net>
N. Leiten <nleiten at sourceforge dot net>
Nicolas Dade <ndade at nsd dot dyndns dot org>
Niko Delarich <niko dot delarich at gmail dot com>
N. Leiten <nleiten at sourceforge dot net>
<nvercamm at sourceforge dot net>
Octavian Cerna <tavy at ylabs dot com>
Olaf Kirch <okir at caldera dot de>
Ollie Wild <aaw at users dot sourceforge dot net>
@ -145,8 +165,8 @@ Additional people who have contributed patches:
Xianjie Zhang <xzhang at cup dot hp dot com>
Xin Li <delphij at FreeBSD dot org>
Yen Yen Lim
Yvan Vanhullebus <vanhu at sourceforge dot net>
Yoann Vandoorselaere <yoann at prelude-ids dot org>
Yvan Vanhullebus <vanhu at sourceforge dot net>
The original LBL crew:
Steve McCanne

View File

@ -1,5 +1,3 @@
@(#) $Header: /tcpdump/master/libpcap/INSTALL.txt,v 1.29 2008-06-12 20:21:51 guy Exp $ (LBL)
To build libpcap, run "./configure" (a shell script). The configure
script will determine your system attributes and generate an
appropriate Makefile from Makefile.in. Next run "make". If everything
@ -31,19 +29,14 @@ where the configure scripts fails to detect it.
You will need an ANSI C compiler to build libpcap. The configure script
will abort if your compiler is not ANSI compliant. If this happens, use
the GNU C compiler, available via anonymous ftp:
ftp://ftp.gnu.org/pub/gnu/gcc/
the generally available GNU C compiler (GCC).
If you use flex, you must use version 2.4.6 or higher. The configure
script automatically detects the version of flex and will not use it
unless it is new enough. You can use "flex -V" to see what version you
have (unless it's really old). The current version of flex is available
via anonymous ftp:
ftp://ftp.ee.lbl.gov/flex-*.tar.Z
As of this writing, the current version is 2.5.4.
at flex.sourceforge.net and often comes packaged by means of the OS.
As of this writing, the current version is 2.5.37.
If you use bison, you must use flex (and visa versa). The configure
script automatically falls back to lex and yacc if both flex and bison

View File

@ -0,0 +1,22 @@
#
# Auto-regenerate configure script or Makefile when things change.
# From autoconf.info . Works best with GNU Make.
#
${srcdir}/configure: configure.in aclocal.m4
cd ${srcdir} && autoconf
# autoheader might not change config.h.in, so touch a stamp file.
${srcdir}/config.h.in: ${srcdir}/stamp-h.in
${srcdir}/stamp-h.in: configure.in aclocal.m4
cd ${srcdir} && autoheader
echo timestamp > ${srcdir}/stamp-h.in
config.h: stamp-h
stamp-h: ${srcdir}/config.h.in config.status
./config.status
Makefile: Makefile.in config.status
./config.status
config.status: ${srcdir}/configure
./config.status --recheck

View File

@ -16,8 +16,6 @@
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.142 2008-11-22 17:30:24 guy Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@ -47,6 +45,8 @@ VPATH = @srcdir@
LD = /usr/bin/ld
CC = @CC@
AR = @AR@
LN_S = @LN_S@
MKDEP = @MKDEP@
CCOPT = @V_CCOPT@
INCLS = -I. @V_INCLS@
DEFS = @DEFS@ @V_DEFS@
@ -57,6 +57,7 @@ CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
DYEXT = @DYEXT@
V_RPATH_OPT = @V_RPATH_OPT@
DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
PROG=libpcap
# Standard CFLAGS
@ -82,7 +83,7 @@ YACC = @V_YACC@
@rm -f $@
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
PSRC = pcap-@V_PCAP@.c @USB_SRC@ @BT_SRC@ @CAN_SRC@ @NETFILTER_SRC@ @CANUSB_SRC@
PSRC = pcap-@V_PCAP@.c @USB_SRC@ @BT_SRC@ @BT_MONITOR_SRC@ @CAN_SRC@ @NETFILTER_SRC@ @CANUSB_SRC@ @DBUS_SRC@
FSRC = fad-@V_FINDALLDEVS@.c
SSRC = @SSRC@
CSRC = pcap.c inet.c gencode.c optimize.c nametoaddr.c etherent.c \
@ -104,6 +105,7 @@ PUBHDR = \
pcap/bluetooth.h \
pcap/ipnet.h \
pcap/namedb.h \
pcap/nflog.h \
pcap/pcap.h \
pcap/sll.h \
pcap/vlan.h \
@ -126,19 +128,21 @@ HDR = $(PUBHDR) \
sunatmpos.h
TESTS = \
capturetest \
filtertest \
findalldevstest \
nonblocktest \
opentest \
selpolltest
selpolltest \
valgrindtest
TESTS_SRC = \
tests/capturetest.c \
tests/filtertest.c \
tests/findalldevstest.c \
tests/nonblocktest.c \
tests/opentest.c \
tests/reactivatetest.c \
tests/selpolltest.c
tests/selpolltest.c \
tests/valgrindtest.c
GENHDR = \
scanner.h tokdefs.h version.h
@ -157,10 +161,12 @@ MAN3PCAP_EXPAND = \
pcap_compile.3pcap.in \
pcap_datalink.3pcap.in \
pcap_dump_open.3pcap.in \
pcap_get_tstamp_precision.3pcap.in \
pcap_list_datalinks.3pcap.in \
pcap_list_tstamp_types.3pcap.in \
pcap_open_dead.3pcap.in \
pcap_open_offline.3pcap.in \
pcap_set_tstamp_precision.3pcap.in \
pcap_set_tstamp_type.3pcap.in
MAN3PCAP_NOEXPAND = \
@ -194,6 +200,7 @@ MAN3PCAP_NOEXPAND = \
pcap_open_live.3pcap \
pcap_set_buffer_size.3pcap \
pcap_set_datalink.3pcap \
pcap_set_immediate_mode.3pcap \
pcap_set_promisc.3pcap \
pcap_set_rfmon.3pcap \
pcap_set_snaplen.3pcap \
@ -227,6 +234,7 @@ EXTRA_DIST = \
INSTALL.txt \
LICENSE \
Makefile.in \
Makefile-devel-adds \
README \
README.aix \
README.dag \
@ -287,6 +295,8 @@ EXTRA_DIST = \
pcap-bpf.c \
pcap-bt-linux.c \
pcap-bt-linux.h \
pcap-bt-monitor-linux.c \
pcap-bt-monitor-linux.h \
pcap-can-linux.c \
pcap-can-linux.h \
pcap-canusb-linux.c \
@ -294,6 +304,8 @@ EXTRA_DIST = \
pcap-config.in \
pcap-dag.c \
pcap-dag.h \
pcap-dbus.c \
pcap-dbus.h \
pcap-dlpi.c \
pcap-dos.c \
pcap-dos.h \
@ -515,21 +527,24 @@ pcap-config: $(srcdir)/pcap-config.in ./config.status
#
tests: $(TESTS)
capturetest: tests/capturetest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o capturetest $(srcdir)/tests/capturetest.c libpcap.a $(LIBS)
filtertest: tests/filtertest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o filtertest $(srcdir)/tests/filtertest.c libpcap.a $(LIBS)
findalldevstest: tests/findalldevstest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o findalldevstest $(srcdir)/tests/findalldevstest.c libpcap.a $(LIBS)
nonblocktest: tests/nonblocktest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o nonblocktest $(srcdir)/tests/nonblocktest.c libpcap.a $(LIBS)
opentest: tests/opentest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o opentest $(srcdir)/tests/opentest.c libpcap.a $(LIBS)
selpolltest: tests/selpolltest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o selpolltest $(srcdir)/tests/selpolltest.c libpcap.a $(LIBS)
valgrindtest: tests/valgrindtest.c libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o valgrindtest $(srcdir)/tests/valgrindtest.c libpcap.a $(LIBS)
install: install-shared install-archive pcap-config
[ -d $(DESTDIR)$(libdir) ] || \
(mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
@ -560,42 +575,41 @@ install: install-shared install-archive pcap-config
for i in $(MAN3PCAP_EXPAND:.in=); do \
$(INSTALL_DATA) $$i \
$(DESTDIR)$(mandir)/man3/$$i; done
rm -f $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_name.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_dump_fopen.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_dump_open.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_dump_fopen.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_freealldevs.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_findalldevs.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_freealldevs.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_perror.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_geterr.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_perror.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_sendpacket.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_inject.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_sendpacket.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_free_datalinks.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_list_datalinks.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_free_datalinks.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_free_tstamp_types.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_list_tstamp_types.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_free_tstamp_types.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_dispatch.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_loop.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_dispatch.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_minor_version.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_major_version.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_minor_version.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_next.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_next_ex.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_next.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_open_offline.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_fopen_offline.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_getnonblock.3pcap
ln $(DESTDIR)$(mandir)/man3/pcap_setnonblock.3pcap \
$(DESTDIR)$(mandir)/man3/pcap_getnonblock.3pcap
(cd $(DESTDIR)$(mandir)/man3 && \
rm -f pcap_datalink_val_to_description.3pcap && \
$(LN_S) pcap_datalink_val_to_name.3pcap \
pcap_datalink_val_to_description.3pcap && \
rm -f pcap_dump_fopen.3pcap && \
$(LN_S) pcap_dump_open.3pcap pcap_dump_fopen.3pcap && \
rm -f pcap_freealldevs.3pcap && \
$(LN_S) pcap_findalldevs.3pcap pcap_freealldevs.3pcap && \
rm -f pcap_perror.3pcap && \
$(LN_S) pcap_geterr.3pcap pcap_perror.3pcap && \
rm -f pcap_sendpacket.3pcap && \
$(LN_S) pcap_inject.3pcap pcap_sendpacket.3pcap && \
rm -f pcap_free_datalinks.3pcap && \
$(LN_S) pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap && \
rm -f pcap_free_tstamp_types.3pcap && \
$(LN_S) pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap && \
rm -f pcap_dispatch.3pcap && \
$(LN_S) pcap_loop.3pcap pcap_dispatch.3pcap && \
rm -f pcap_minor_version.3pcap && \
$(LN_S) pcap_major_version.3pcap pcap_minor_version.3pcap && \
rm -f pcap_next.3pcap && \
$(LN_S) pcap_next_ex.3pcap pcap_next.3pcap && \
rm -f pcap_open_dead_with_tstamp_precision.3pcap && \
$(LN_S) pcap_open_dead.3pcap \
pcap_open_dead_with_tstamp_precision.3pcap && \
rm -f pcap_open_offline_with_tstamp_precision.3pcap && \
$(LN_S) pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap && \
rm -f pcap_fopen_offline.3pcap && \
$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline.3pcap && \
rm -f pcap_fopen_offline_with_tstamp_precision.3pcap && \
$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap && \
rm -f pcap_tstamp_type_val_to_description.3pcap && \
$(LN_S) pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap && \
rm -f pcap_getnonblock.3pcap && \
$(LN_S) pcap_setnonblock.3pcap pcap_getnonblock.3pcap)
for i in $(MANFILE); do \
$(INSTALL_DATA) `echo $$i | sed 's/.manfile.in/.manfile/'` \
$(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
@ -672,8 +686,12 @@ uninstall: uninstall-shared
rm -f $(DESTDIR)$(mandir)/man3/pcap_dispatch.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_minor_version.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_next.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_open_dead_with_tstamp_precision.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_open_offline_with_tstamp_precision.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline_with_tstamp_precision.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_getnonblock.3pcap
rm -f $(DESTDIR)$(mandir)/man3/pcap_tstamp_type_val_to_description.3pcap
for i in $(MANFILE); do \
rm -f $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
for i in $(MANMISC); do \
@ -717,7 +735,7 @@ packaging/pcap.spec: packaging/pcap.spec.in VERSION
RPMVERSION=`cat VERSION | sed s/-.*//g`; \
sed -e s/@VERSION@/$$RPMVERSION/ -e s/@NAME@/libpcap-`cat VERSION`/ $< > $@
releasetar:
releasetar:
@cwd=`pwd` ; dir=`basename $$cwd` ; name=$(PROG)-`cat VERSION` ; \
mkdir $$name; \
tar cf - $(CSRC) $(HDR) $(MAN1) $(MAN3PCAP_EXPAND) \
@ -727,9 +745,4 @@ releasetar:
rm -rf $$name
depend: $(GENSRC) $(GENHDR) bpf_filter.c
./mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC)
Makefile: Makefile.in config.status
./config.status
@echo your Makefile was out of date, now run $(MAKE) again
exit 1
$(MKDEP) -c $(CC) -m $(CFLAGS) $(DEPENDENCY_CFLAG) $(DEFS) $(INCLS) $(SRC)

View File

@ -1,5 +1,3 @@
@(#) $Header: /tcpdump/master/libpcap/README,v 1.34 2008-12-14 19:44:14 guy Exp $ (LBL)
LIBPCAP 1.x.y
www.tcpdump.org
@ -10,18 +8,15 @@ Please send inquiries/comments/reports to:
Anonymous Git is available via:
git clone git://bpf.tcpdump.org/libpcap
Version 1.x.y of LIBPCAP can be retrieved with the CVS tag "libpcap_1_{x}rel{y}":
cvs -d :pserver:tcpdump@cvs.tcpdump.org:/tcpdump/master checkout -r libpcap_1_{x}rel{y} libpcap
Please submit patches by forking the branch on GitHub at
http://github.com/mcr/libpcap/tree/master
http://github.com/the-tcpdump-group/libpcap/tree/master
and issuing a pull request.
formerly from Lawrence Berkeley National Laboratory
Network Research Group <libpcap@ee.lbl.gov>
ftp://ftp.ee.lbl.gov/libpcap.tar.Z (0.4)
ftp://ftp.ee.lbl.gov/old/libpcap-0.4a7.tar.Z
This directory contains source code for libpcap, a system-independent
interface for user-level packet capture. libpcap provides a portable
@ -97,12 +92,12 @@ to the address "tcpdump-workers@lists.tcpdump.org". Bugs, support
requests, and feature requests may also be submitted on the GitHub issue
tracker for libpcap at
https://github.com/mcr/libpcap/issues
https://github.com/the-tcpdump-group/libpcap/issues
Source code contributions, etc. should be sent to the email address
above or submitted by forking the branch on GitHub at
http://github.com/mcr/libpcap/tree/master
http://github.com/the-tcpdump-group/libpcap/tree/master
and issuing a pull request.

View File

@ -1 +1 @@
1.4.0
1.6.2

View File

@ -30,8 +30,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Id: arcnet.h,v 1.2 2001-04-24 02:17:52 guy Exp $ (LBL)
*
* from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp
*/

View File

@ -28,8 +28,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/atmuni31.h,v 1.3 2007-10-22 19:28:58 guy Exp $ (LBL)
*/
/* Based on UNI3.1 standard by ATM Forum */

View File

@ -38,11 +38,6 @@
* @(#)bpf.c 7.5 (Berkeley) 7/15/91
*/
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.46 2008-01-02 04:16:46 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -469,6 +464,12 @@ bpf_filter(pc, p, wirelen, buflen)
A /= X;
continue;
case BPF_ALU|BPF_MOD|BPF_X:
if (X == 0)
return 0;
A %= X;
continue;
case BPF_ALU|BPF_AND|BPF_X:
A &= X;
continue;
@ -477,6 +478,10 @@ bpf_filter(pc, p, wirelen, buflen)
A |= X;
continue;
case BPF_ALU|BPF_XOR|BPF_X:
A ^= X;
continue;
case BPF_ALU|BPF_LSH|BPF_X:
A <<= X;
continue;
@ -501,6 +506,10 @@ bpf_filter(pc, p, wirelen, buflen)
A /= pc->k;
continue;
case BPF_ALU|BPF_MOD|BPF_K:
A %= pc->k;
continue;
case BPF_ALU|BPF_AND|BPF_K:
A &= pc->k;
continue;
@ -509,6 +518,10 @@ bpf_filter(pc, p, wirelen, buflen)
A |= pc->k;
continue;
case BPF_ALU|BPF_XOR|BPF_K:
A ^= pc->k;
continue;
case BPF_ALU|BPF_LSH|BPF_K:
A <<= pc->k;
continue;
@ -611,13 +624,16 @@ bpf_validate(f, len)
case BPF_MUL:
case BPF_OR:
case BPF_AND:
case BPF_XOR:
case BPF_LSH:
case BPF_RSH:
case BPF_NEG:
break;
case BPF_DIV:
case BPF_MOD:
/*
* Check for constant division by 0.
* Check for constant division or modulus
* by 0.
*/
if (BPF_SRC(p->code) == BPF_K && p->k == 0)
return 0;

View File

@ -18,10 +18,6 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.15 2008-01-02 04:16:46 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"

View File

@ -19,11 +19,6 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/bpf_image.c,v 1.28 2008-01-02 04:16:46 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -216,6 +211,11 @@ bpf_image(p, n)
fmt = "x";
break;
case BPF_ALU|BPF_MOD|BPF_X:
op = "mod";
fmt = "x";
break;
case BPF_ALU|BPF_AND|BPF_X:
op = "and";
fmt = "x";
@ -226,6 +226,11 @@ bpf_image(p, n)
fmt = "x";
break;
case BPF_ALU|BPF_XOR|BPF_X:
op = "xor";
fmt = "x";
break;
case BPF_ALU|BPF_LSH|BPF_X:
op = "lsh";
fmt = "x";
@ -256,6 +261,11 @@ bpf_image(p, n)
fmt = "#%d";
break;
case BPF_ALU|BPF_MOD|BPF_K:
op = "mod";
fmt = "#%d";
break;
case BPF_ALU|BPF_AND|BPF_K:
op = "and";
fmt = "#0x%x";
@ -266,6 +276,11 @@ bpf_image(p, n)
fmt = "#0x%x";
break;
case BPF_ALU|BPF_XOR|BPF_K:
op = "xor";
fmt = "#0x%x";
break;
case BPF_ALU|BPF_LSH|BPF_K:
op = "lsh";
fmt = "#%d";

View File

@ -1,10 +1,10 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
timestamp='2009-12-30'
timestamp='2012-02-10'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@ -17,9 +17,7 @@ timestamp='2009-12-30'
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
@ -57,8 +55,8 @@ GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
Software Foundation, Inc.
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -145,7 +143,7 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:NetBSD:*:*)
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
@ -181,7 +179,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
fi
;;
*)
os=netbsd
os=netbsd
;;
esac
# The OS release
@ -224,7 +222,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
@ -270,7 +268,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
exit ;;
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
exitcode=$?
trap '' 0
exit $exitcode ;;
Alpha\ *:Windows_NT*:*)
# How do we know it's Interix rather than the generic POSIX subsystem?
# Should we change UNAME_MACHINE based on the output of uname instead
@ -296,7 +297,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
echo s390-ibm-zvmoe
exit ;;
*:OS400:*:*)
echo powerpc-ibm-os400
echo powerpc-ibm-os400
exit ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
@ -395,23 +396,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# MiNT. But MiNT is downward compatible to TOS, so this should
# be no problem.
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
exit ;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
echo m68k-milan-mint${UNAME_RELEASE}
exit ;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
echo m68k-hades-mint${UNAME_RELEASE}
exit ;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
echo m68k-unknown-mint${UNAME_RELEASE}
exit ;;
m68k:machten:*:*)
echo m68k-apple-machten${UNAME_RELEASE}
exit ;;
@ -481,8 +482,8 @@ EOF
echo m88k-motorola-sysv3
exit ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
@ -495,7 +496,7 @@ EOF
else
echo i586-dg-dgux${UNAME_RELEASE}
fi
exit ;;
exit ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit ;;
@ -552,7 +553,7 @@ EOF
echo rs6000-ibm-aix3.2
fi
exit ;;
*:AIX:*:[456])
*:AIX:*:[4567])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
@ -595,52 +596,52 @@ EOF
9000/[678][0-9][0-9])
if [ -x /usr/bin/getconf ]; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
32) HP_ARCH="hppa2.0n" ;;
64) HP_ARCH="hppa2.0w" ;;
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
esac ;;
esac
esac ;;
esac
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
sed 's/^ //' << EOF >$dummy.c
sed 's/^ //' << EOF >$dummy.c
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
@ -731,22 +732,22 @@ EOF
exit ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit ;;
exit ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit ;;
exit ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit ;;
exit ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit ;;
exit ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
@ -770,14 +771,14 @@ EOF
exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
@ -789,13 +790,12 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
case ${UNAME_MACHINE} in
pc98)
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
UNAME_PROCESSOR=`/usr/bin/uname -p`
case ${UNAME_PROCESSOR} in
amd64)
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
exit ;;
i*:CYGWIN*:*)
@ -804,15 +804,18 @@ EOF
*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:MSYS*:*)
echo ${UNAME_MACHINE}-pc-msys
exit ;;
i*:windows32*:*)
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
# uname -m includes "-pc" on this system.
echo ${UNAME_MACHINE}-mingw32
exit ;;
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
*:Interix*:*)
case ${UNAME_MACHINE} in
case ${UNAME_MACHINE} in
x86)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
@ -858,6 +861,13 @@ EOF
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
exit ;;
aarch64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
aarch64_be:Linux:*:*)
UNAME_MACHINE=aarch64_be
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
EV5) UNAME_MACHINE=alphaev5 ;;
@ -867,7 +877,7 @@ EOF
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
esac
objdump --private-headers /bin/sh | grep -q ld.so.1
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
@ -879,20 +889,29 @@ EOF
then
echo ${UNAME_MACHINE}-unknown-linux-gnu
else
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP
then
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
else
echo ${UNAME_MACHINE}-unknown-linux-gnueabihf
fi
fi
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
cris:Linux:*:*)
echo cris-axis-linux-gnu
echo ${UNAME_MACHINE}-axis-linux-gnu
exit ;;
crisv32:Linux:*:*)
echo crisv32-axis-linux-gnu
echo ${UNAME_MACHINE}-axis-linux-gnu
exit ;;
frv:Linux:*:*)
echo frv-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
hexagon:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
LIBC=gnu
@ -934,7 +953,7 @@ EOF
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
or32:Linux:*:*)
echo or32-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
padre:Linux:*:*)
echo sparc-unknown-linux-gnu
@ -960,7 +979,7 @@ EOF
echo ${UNAME_MACHINE}-ibm-linux
exit ;;
sh64*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
@ -968,14 +987,17 @@ EOF
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
tile*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
exit ;;
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
xtensa*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
@ -984,11 +1006,11 @@ EOF
echo i386-sequent-sysv4
exit ;;
i*86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit ;;
i*86:OS/2:*:*)
@ -1020,7 +1042,7 @@ EOF
fi
exit ;;
i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6.
# UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
@ -1048,13 +1070,13 @@ EOF
exit ;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# Note: whatever this is, it MUST be the same as what config.sub
# prints for the "djgpp" host, or else GDB configury will decide that
# this is a cross-build.
echo i586-pc-msdosdjgpp
exit ;;
exit ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit ;;
@ -1089,8 +1111,8 @@ EOF
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4; exit; } ;;
NCR*:*:4.2:* | MPRAS*:*:4.2:*)
OS_REL='.3'
test -r /etc/.relid \
@ -1133,10 +1155,10 @@ EOF
echo ns32k-sni-sysv
fi
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
@ -1162,11 +1184,11 @@ EOF
exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit ;;
exit ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit ;;
@ -1231,6 +1253,9 @@ EOF
*:QNX:*:4*)
echo i386-pc-qnx
exit ;;
NEO-?:NONSTOP_KERNEL:*:*)
echo neo-tandem-nsk${UNAME_RELEASE}
exit ;;
NSE-?:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
@ -1276,13 +1301,13 @@ EOF
echo pdp10-unknown-its
exit ;;
SEI:*:*:SEIUX)
echo mips-sei-seiux${UNAME_RELEASE}
echo mips-sei-seiux${UNAME_RELEASE}
exit ;;
*:DragonFly:*:*)
echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
*:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null`
UNAME_MACHINE=`(uname -p) 2>/dev/null`
case "${UNAME_MACHINE}" in
A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;;
@ -1300,6 +1325,9 @@ EOF
i*86:AROS:*:*)
echo ${UNAME_MACHINE}-pc-aros
exit ;;
x86_64:VMkernel:*:*)
echo ${UNAME_MACHINE}-unknown-esx
exit ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
@ -1322,11 +1350,11 @@ main ()
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
"4"
#else
""
""
#endif
); exit (0);
); exit (0);
#endif
#endif

View File

@ -244,6 +244,9 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
@ -253,12 +256,18 @@
/* target host supports Bluetooth sniffing */
#undef PCAP_SUPPORT_BT
/* target host supports Bluetooth Monitor */
#undef PCAP_SUPPORT_BT_MONITOR
/* target host supports CAN sniffing */
#undef PCAP_SUPPORT_CAN
/* target host supports canusb */
#undef PCAP_SUPPORT_CANUSB
/* support D-Bus sniffing */
#undef PCAP_SUPPORT_DBUS
/* target host supports netfilter sniffing */
#undef PCAP_SUPPORT_NETFILTER
@ -277,12 +286,14 @@
/* Enable parser debugging */
#undef YYDEBUG
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* needed on HP-UX */
#undef _HPUX_SOURCE
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
#undef _LARGEFILE_SOURCE
@ -292,6 +303,9 @@
/* define on AIX to get certain functions */
#undef _SUN
/* define if your compiler allows __attribute__((format)) without a warning */
#undef __ATTRIBUTE___FORMAT_OK
/* to handle Ultrix compilers that don't support const in prototypes */
#undef const

View File

@ -1,10 +1,10 @@
#! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
timestamp='2009-12-31'
timestamp='2012-04-18'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@ -21,9 +21,7 @@ timestamp='2009-12-31'
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
@ -76,8 +74,8 @@ version="\
GNU config.sub ($timestamp)
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
Software Foundation, Inc.
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -124,13 +122,18 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
knetbsd*-gnu* | netbsd*-gnu* | \
kopensolaris*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
android-linux)
os=-linux-android
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
;;
*)
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ]
@ -157,8 +160,8 @@ case $os in
os=
basic_machine=$1
;;
-bluegene*)
os=-cnk
-bluegene*)
os=-cnk
;;
-sim | -cisco | -oki | -wec | -winbond)
os=
@ -174,10 +177,10 @@ case $os in
os=-chorusos
basic_machine=$1
;;
-chorusrdb)
os=-chorusrdb
-chorusrdb)
os=-chorusrdb
basic_machine=$1
;;
;;
-hiux*)
os=-hiuxwe2
;;
@ -222,6 +225,12 @@ case $os in
-isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-lynx*178)
os=-lynxos178
;;
-lynx*5)
os=-lynxos5
;;
-lynx*)
os=-lynxos
;;
@ -246,17 +255,22 @@ case $basic_machine in
# Some are omitted here because they have special meanings below.
1750a | 580 \
| a29k \
| aarch64 | aarch64_be \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
| be32 | be64 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| epiphany \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore | mep | metag \
@ -282,29 +296,39 @@ case $basic_machine in
| moxie \
| mt \
| msp430 \
| nds32 | nds32le | nds32be \
| nios | nios2 \
| ns16k | ns32k \
| open8 \
| or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
| powerpc | powerpc64 | powerpc64le | powerpcle \
| pyramid \
| rx \
| rl78 | rx \
| score \
| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| spu | strongarm \
| tahoe | thumb | tic4x | tic80 | tron \
| spu \
| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| ubicom32 \
| v850 | v850e \
| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
| we32k \
| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
| x86 | xc16x | xstormy16 | xtensa \
| z8k | z80)
basic_machine=$basic_machine-unknown
;;
m6811 | m68hc11 | m6812 | m68hc12 | picochip)
# Motorola 68HC11/12.
c54x)
basic_machine=tic54x-unknown
;;
c55x)
basic_machine=tic55x-unknown
;;
c6x)
basic_machine=tic6x-unknown
;;
m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
basic_machine=$basic_machine-unknown
os=-none
;;
@ -314,6 +338,21 @@ case $basic_machine in
basic_machine=mt-unknown
;;
strongarm | thumb | xscale)
basic_machine=arm-unknown
;;
xgate)
basic_machine=$basic_machine-unknown
os=-none
;;
xscaleeb)
basic_machine=armeb-unknown
;;
xscaleel)
basic_machine=armel-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
@ -328,21 +367,25 @@ case $basic_machine in
# Recognize the basic CPU types with company name.
580-* \
| a29k-* \
| aarch64-* | aarch64_be-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
| be32-* | be64-* \
| bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* \
| clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| hexagon-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
| le32-* | le64-* \
| lm32-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
@ -368,25 +411,29 @@ case $basic_machine in
| mmix-* \
| mt-* \
| msp430-* \
| nds32-* | nds32le-* | nds32be-* \
| nios-* | nios2-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| open8-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
| pyramid-* \
| romp-* | rs6000-* | rx-* \
| rl78-* | romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
| tahoe-* | thumb-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
| tahoe-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tile*-* \
| tron-* \
| ubicom32-* \
| v850-* | v850e-* | vax-* \
| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
| vax-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
| x86-* | x86_64-* | xc16x-* | xps100-* \
| xstormy16-* | xtensa*-* \
| ymp-* \
| z8k-* | z80-*)
@ -411,7 +458,7 @@ case $basic_machine in
basic_machine=a29k-amd
os=-udi
;;
abacus)
abacus)
basic_machine=abacus-unknown
;;
adobe68k)
@ -481,11 +528,20 @@ case $basic_machine in
basic_machine=powerpc-ibm
os=-cnk
;;
c54x-*)
basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c55x-*)
basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c6x-*)
basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c90)
basic_machine=c90-cray
os=-unicos
;;
cegcc)
cegcc)
basic_machine=arm-unknown
os=-cegcc
;;
@ -517,7 +573,7 @@ case $basic_machine in
basic_machine=craynv-cray
os=-unicosmp
;;
cr16)
cr16 | cr16-*)
basic_machine=cr16-unknown
os=-elf
;;
@ -675,7 +731,6 @@ case $basic_machine in
i370-ibm* | ibm*)
basic_machine=i370-ibm
;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i*86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
@ -733,7 +788,7 @@ case $basic_machine in
basic_machine=ns32k-utek
os=-sysv
;;
microblaze)
microblaze)
basic_machine=microblaze-xilinx
;;
mingw32)
@ -772,10 +827,18 @@ case $basic_machine in
ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;;
msys)
basic_machine=i386-pc
os=-msys
;;
mvs)
basic_machine=i370-ibm
os=-mvs
;;
nacl)
basic_machine=le32-unknown
os=-nacl
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
@ -840,6 +903,12 @@ case $basic_machine in
np1)
basic_machine=np1-gould
;;
neo-tandem)
basic_machine=neo-tandem
;;
nse-tandem)
basic_machine=nse-tandem
;;
nsr-tandem)
basic_machine=nsr-tandem
;;
@ -922,9 +991,10 @@ case $basic_machine in
;;
power) basic_machine=power-ibm
;;
ppc) basic_machine=powerpc-unknown
ppc | ppcbe) basic_machine=powerpc-unknown
;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
@ -1018,6 +1088,9 @@ case $basic_machine in
basic_machine=i860-stratus
os=-sysv4
;;
strongarm-* | thumb-*)
basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
sun2)
basic_machine=m68000-sun
;;
@ -1074,20 +1147,8 @@ case $basic_machine in
basic_machine=t90-cray
os=-unicos
;;
tic54x | c54x*)
basic_machine=tic54x-unknown
os=-coff
;;
tic55x | c55x*)
basic_machine=tic55x-unknown
os=-coff
;;
tic6x | c6x*)
basic_machine=tic6x-unknown
os=-coff
;;
tile*)
basic_machine=tile-unknown
basic_machine=$basic_machine-unknown
os=-linux-gnu
;;
tx39)
@ -1157,6 +1218,9 @@ case $basic_machine in
xps | xps100)
basic_machine=xps100-honeywell
;;
xscale-* | xscalee[bl]-*)
basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
;;
ymp)
basic_machine=ymp-cray
os=-unicos
@ -1254,11 +1318,11 @@ esac
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-auroraux)
os=-auroraux
-auroraux)
os=-auroraux
;;
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
@ -1294,8 +1358,9 @@ case $os in
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
| -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-android* \
| -linux-newlib* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
@ -1342,7 +1407,7 @@ case $os in
-opened*)
os=-openedition
;;
-os400*)
-os400*)
os=-os400
;;
-wince*)
@ -1391,7 +1456,7 @@ case $os in
-sinix*)
os=-sysv4
;;
-tpf*)
-tpf*)
os=-tpf
;;
-triton*)
@ -1436,8 +1501,8 @@ case $os in
-dicos*)
os=-dicos
;;
-nacl*)
;;
-nacl*)
;;
-none)
;;
*)
@ -1460,10 +1525,10 @@ else
# system, and we'll never get to this point.
case $basic_machine in
score-*)
score-*)
os=-elf
;;
spu-*)
spu-*)
os=-elf
;;
*-acorn)
@ -1475,8 +1540,17 @@ case $basic_machine in
arm*-semi)
os=-aout
;;
c4x-* | tic4x-*)
os=-coff
c4x-* | tic4x-*)
os=-coff
;;
tic54x-*)
os=-coff
;;
tic55x-*)
os=-coff
;;
tic6x-*)
os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
@ -1496,14 +1570,11 @@ case $basic_machine in
;;
m68000-sun)
os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;;
m68*-cisco)
os=-aout
;;
mep-*)
mep-*)
os=-elf
;;
mips*-cisco)
@ -1530,7 +1601,7 @@ case $basic_machine in
*-ibm)
os=-aix
;;
*-knuth)
*-knuth)
os=-mmixware
;;
*-wec)

11755
contrib/libpcap/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.168 2008-12-23 20:49:26 guy Exp $ (LBL)
dnl
dnl Copyright (c) 1994, 1995, 1996, 1997
dnl The Regents of the University of California. All rights reserved.
@ -15,8 +14,7 @@ dnl
# config.sub.
#
AC_REVISION($Revision: 1.168 $)
AC_PREREQ(2.50)
AC_PREREQ(2.61)
AC_INIT(pcap.c)
AC_CANONICAL_SYSTEM
@ -27,6 +25,10 @@ AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_LBL_SHLIBS_INIT
AC_LBL_C_INLINE
AC_C___ATTRIBUTE__
if test "$ac_cv___attribute__" = "yes"; then
AC_C___ATTRIBUTE___UNUSED
AC_C___ATTRIBUTE___FORMAT
fi
AC_CHECK_HEADERS(sys/bitypes.h)
@ -345,6 +347,16 @@ AC_MSG_RESULT($V_PCAP)
#
case "$V_PCAP" in
dlpi)
#
# Needed for common functions used by pcap-[dlpi,libdlpi].c
#
SSRC="dlpisubs.c"
#
# Checks for some header files.
#
AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h)
#
# Checks to see if Solaris has the public libdlpi(3LIB) library.
# Note: The existence of /usr/include/libdlpi.h does not mean it is the
@ -359,9 +371,11 @@ dlpi)
saved_ldflags=$LDFLAGS
LDFLAGS="$LIBS -L/lib"
AC_CHECK_LIB(dlpi, dlpi_walk,
LIBS="-ldlpi $LIBS"
V_PCAP=libdlpi
AC_DEFINE(HAVE_LIBDLPI,1,[if libdlpi exists]),
[
LIBS="-ldlpi $LIBS"
V_PCAP=libdlpi
AC_DEFINE(HAVE_LIBDLPI,1,[if libdlpi exists])
],
V_PCAP=dlpi)
LDFLAGS=$saved_ldflags
@ -600,7 +614,6 @@ else
case "$V_PCAP" in
dlpi|libdlpi)
AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h)
#
# This might be Solaris 8 or later, with
# SIOCGLIFCONF, or it might be some other OS
@ -624,10 +637,6 @@ else
else
V_FINDALLDEVS=gifc
fi
#
# Needed for common functions used by pcap-[dlpi,libdlpi].c
#
SSRC="dlpisubs.c"
;;
*)
@ -1103,6 +1112,45 @@ darwin*)
if test "$enable_universal" != "no"; then
case "$host_os" in
darwin[0-7].*)
#
# Pre-Tiger. Build only for 32-bit PowerPC; no
# need for any special compiler or linker flags.
#
;;
darwin8.[0123]*)
#
# Tiger, prior to Intel support. Build for 32-bit
# PowerPC and 64-bit PowerPC, with 32-bit PowerPC
# first. (I'm guessing that's what Apple does.)
#
V_CCOPT="$V_CCOPT -arch ppc -arch ppc64"
LDFLAGS="$LDFLAGS -arch ppc -arch ppc64"
;;
darwin8.[456]*)
#
# Tiger, subsequent to Intel support but prior to
# x86-64 support. Build for 32-bit PowerPC, 64-bit
# PowerPC, and x86, with 32-bit PowerPC first.
# (I'm guessing that's what Apple does.)
#
V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386"
LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386"
;;
darwin8.*)
#
# All other Tiger, so subsequent to x86-64
# support. Build for 32-bit PowerPC, 64-bit
# PowerPC, x86, and x86-64, and with 32-bit PowerPC
# first. (I'm guessing that's what Apple does.)
#
V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64"
LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64"
;;
darwin9.*)
#
# Leopard. Build for 32-bit PowerPC, 64-bit
@ -1127,11 +1175,13 @@ darwin*)
LDFLAGS="$LDFLAGS -arch x86_64 -arch i386 -arch ppc"
;;
darwin11.*)
darwin*)
#
# Lion. Build for x86-64 and x86, with x86-64
# first. (That's probably what Apple does,
# given that Rosetta is gone.)
# Post-Snow Leopard. Build for x86-64 and
# x86, with x86-64 first. (That's probably what
# Apple does, given that Rosetta is gone.)
# XXX - update if and when Apple drops support
# for 32-bit x86 code.
#
V_CCOPT="$V_CCOPT -arch x86_64 -arch i386"
LDFLAGS="$LDFLAGS -arch x86_64 -arch i386"
@ -1258,6 +1308,9 @@ test "x$enable_shared" = "xno" && DYEXT="none"
AC_PROG_RANLIB
AC_CHECK_TOOL([AR], [ar])
AC_PROG_LN_S
AC_SUBST(LN_S)
AC_LBL_DEVEL(V_CCOPT)
AC_LBL_SOCKADDR_SA_LEN
@ -1402,7 +1455,7 @@ AC_SUBST(NETFILTER_SRC)
AC_ARG_ENABLE([bluetooth],
[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])],
[],
[enable_bluetooth=yes])
[enable_bluetooth=ifsupportavailable])
if test "x$enable_bluetooth" != "xno" ; then
dnl check for Bluetooth sniffing support
@ -1432,23 +1485,56 @@ if test "x$enable_bluetooth" != "xno" ; then
if test $ac_cv_lbl_sockaddr_hci_has_hci_channel = yes ; then
AC_DEFINE(SOCKADDR_HCI_HAS_HCI_CHANNEL,,
[if struct sockaddr_hci has hci_channel member])
#
# OK, is HCI_CHANNEL_MONITOR defined?
#
AC_MSG_CHECKING(if HCI_CHANNEL_MONITOR is defined)
AC_CACHE_VAL(ac_cv_lbl_hci_channel_monitor_is_defined,
AC_TRY_COMPILE(
[
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
],
[u_int i = HCI_CHANNEL_MONITOR],
ac_cv_lbl_hci_channel_monitor_is_defined=yes,
ac_cv_lbl_hci_channel_monitor_is_defined=no))
AC_MSG_RESULT($ac_cv_lbl_hci_channel_monitor_is_defined)
if test $ac_cv_lbl_hci_channel_monitor_is_defined = yes ; then
AC_DEFINE(PCAP_SUPPORT_BT_MONITOR,,
[target host supports Bluetooth Monitor])
BT_MONITOR_SRC=pcap-bt-monitor-linux.c
fi
fi
ac_lbl_bluetooth_available=yes
],
AC_MSG_NOTICE(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
ac_lbl_bluetooth_available=no
)
if test "x$ac_lbl_bluetooth_available" == "xno" ; then
if test "x$enable_bluetooth" = "xyes" ; then
AC_MSG_ERROR(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
else
AC_MSG_NOTICE(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
fi
fi
;;
*)
AC_MSG_NOTICE(no Bluetooth sniffing support implemented for $host_os)
if test "x$enable_bluetooth" = "xyes" ; then
AC_MSG_ERROR(no Bluetooth sniffing support implemented for $host_os)
else
AC_MSG_NOTICE(no Bluetooth sniffing support implemented for $host_os)
fi
;;
esac
AC_SUBST(PCAP_SUPPORT_BT)
AC_SUBST(BT_SRC)
AC_SUBST(BT_MONITOR_SRC)
fi
AC_ARG_ENABLE([canusb],
[AC_HELP_STRING([--enable-canusb],[enable canusb support @<:@default=yes, if support available@:>@])],
[],
[enable_canusb=yes])
[enable_canusb=ifsupportavailable])
if test "x$enable_canusb" != "xno" ; then
dnl check for canusb support
@ -1456,16 +1542,34 @@ if test "x$enable_canusb" != "xno" ; then
linux*)
AC_CHECK_HEADER(libusb-1.0/libusb.h,
[
AC_DEFINE(PCAP_SUPPORT_CANUSB, 1, [target host supports canusb])
CANUSB_SRC=pcap-canusb-linux.c
LIBS="-lusb-1.0 -lpthread $LIBS"
AC_MSG_NOTICE(canusb sniffing is supported)
AC_CHECK_LIB(usb-1.0, libusb_init,
[
AC_DEFINE(PCAP_SUPPORT_CANUSB, 1, [target host supports canusb])
CANUSB_SRC=pcap-canusb-linux.c
LIBS="-lusb-1.0 -lpthread $LIBS"
ac_lbl_has_libusb=yes
],
ac_lbl_has_libusb=no
)
],
AC_MSG_NOTICE(canusb sniffing is not supported; install libusb1.0 lib devel to enable it)
ac_lbl_has_libusb=no
)
if test "x$ac_lbl_has_libusb" = "xyes" ; then
AC_MSG_NOTICE(canusb sniffing is supported)
else
if test "x$enable_canusb" = "xyes" ; then
AC_MSG_ERROR(canusb sniffing is not supported; install libusb1.0 lib devel to enable it)
else
AC_MSG_NOTICE(canusb sniffing is not supported; install libusb1.0 lib devel to enable it)
fi
fi
;;
*)
AC_MSG_NOTICE(no canusb support implemented for $host_os)
if test "x$enable_canusb" = "xyes" ; then
AC_MSG_ERROR(no canusb support implemented for $host_os)
else
AC_MSG_NOTICE(no canusb support implemented for $host_os)
fi
;;
esac
AC_SUBST(PCAP_SUPPORT_CANUSB)
@ -1475,28 +1579,114 @@ fi
AC_ARG_ENABLE([can],
[AC_HELP_STRING([--enable-can],[enable CAN support @<:@default=yes, if support available@:>@])],
[],
[enable_can=yes])
[enable_can=ifsupportavailable])
if test "x$enable_can" != "xno" ; then
dnl check for CAN sniffing support
case "$host_os" in
linux*)
AC_CHECK_HEADER(linux/can.h,
[ AC_DEFINE(PCAP_SUPPORT_CAN, 1, [target host supports CAN sniffing])
CAN_SRC=pcap-can-linux.c
AC_MSG_NOTICE(CAN sniffing is supported)],
AC_MSG_NOTICE(CAN sniffing is not supported),
[
AC_DEFINE(PCAP_SUPPORT_CAN, 1, [target host supports CAN sniffing])
CAN_SRC=pcap-can-linux.c
AC_MSG_NOTICE(CAN sniffing is supported)
],
[
if test "x$enable_can" = "xyes" ; then
AC_MSG_ERROR(CAN sniffing is not supported)
else
AC_MSG_NOTICE(CAN sniffing is not supported)
fi
],
[#include <sys/socket.h>]
)
;;
*)
AC_MSG_NOTICE(no CAN sniffing support implemented for $host_os)
if test "x$enable_can" = "xyes" ; then
AC_MSG_ERROR(no CAN sniffing support implemented for $host_os)
else
AC_MSG_NOTICE(no CAN sniffing support implemented for $host_os)
fi
;;
esac
AC_SUBST(PCAP_SUPPORT_CAN)
AC_SUBST(CAN_SRC)
fi
AC_ARG_ENABLE([dbus],
[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])],
[],
[enable_dbus=ifavailable])
if test "x$enable_dbus" != "xno"; then
if test "x$enable_dbus" = "xyes"; then
case "$host_os" in
darwin*)
#
# https://bugs.freedesktop.org/show_bug.cgi?id=74029
#
AC_MSG_ERROR([Due to freedesktop.org bug 74029, D-Bus capture support is not available on OS X])
;;
esac
else
case "$host_os" in
darwin*)
#
# https://bugs.freedesktop.org/show_bug.cgi?id=74029
#
;;
*)
AC_CHECK_PROG([PKGCONFIG], [pkg-config], [pkg-config], [no])
if test "x$PKGCONFIG" != "xno"; then
AC_MSG_CHECKING([for D-Bus])
if "$PKGCONFIG" dbus-1; then
AC_MSG_RESULT([yes])
DBUS_CFLAGS=`"$PKGCONFIG" --cflags dbus-1`
DBUS_LIBS=`"$PKGCONFIG" --libs dbus-1`
save_CFLAGS="$CFLAGS"
save_LIBS="$LIBS"
CFLAGS="$CFLAGS $DBUS_CFLAGS"
LIBS="$LIBS $DBUS_LIBS"
AC_MSG_CHECKING(whether the D-Bus library defines dbus_connection_read_write)
AC_TRY_LINK(
[#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <dbus/dbus.h>],
[return dbus_connection_read_write(NULL, 0);],
[
AC_MSG_RESULT([yes])
AC_DEFINE(PCAP_SUPPORT_DBUS, 1, [support D-Bus sniffing])
DBUS_SRC=pcap-dbus.c
V_INCLS="$V_INCLS $DBUS_CFLAGS"
],
[
AC_MSG_RESULT([no])
if test "x$enable_dbus" = "xyes"; then
AC_MSG_ERROR([--enable-dbus was given, but the D-Bus library doesn't define dbus_connection_read_write()])
fi
LIBS="$save_LIBS"
])
CFLAGS="$save_CFLAGS"
else
AC_MSG_RESULT([no])
if test "x$enable_dbus" = "xyes"; then
AC_MSG_ERROR([--enable-dbus was given, but the dbus-1 package is not installed])
fi
fi
fi
;;
esac
fi
AC_SUBST(PCAP_SUPPORT_DBUS)
AC_SUBST(DBUS_SRC)
fi
dnl check for hardware timestamp support
case "$host_os" in
linux*)
@ -1511,14 +1701,16 @@ AC_PROG_INSTALL
AC_CONFIG_HEADER(config.h)
AC_OUTPUT_COMMANDS([if test -f .devel; then
echo timestamp > stamp-h
cat Makefile-devel-adds >> Makefile
make depend
fi])
AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc
pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap
pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap
pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap
pcap_open_dead.3pcap pcap_open_offline.3pcap
pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap
pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap
pcap_open_offline.3pcap pcap_set_tstamp_precision.3pcap
pcap_set_tstamp_type.3pcap)
if test -f .devel ; then
make depend
fi
exit 0

View File

@ -10,10 +10,6 @@
* This file contains dlpi/libdlpi related common functions used
* by pcap-[dlpi,libdlpi].c.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/dlpisubs.c,v 1.3 2008-12-02 16:40:19 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -66,6 +62,10 @@ static const char rcsid[] _U_ =
#include <stropts.h>
#include <unistd.h>
#ifdef HAVE_LIBDLPI
#include <libdlpi.h>
#endif
#include "pcap-int.h"
#include "dlpisubs.h"
@ -79,6 +79,7 @@ static void pcap_stream_err(const char *, int, char *);
int
pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
{
struct pcap_dlpi *pd = p->priv;
/*
* "ps_recv" counts packets handed to the filter, not packets
@ -103,7 +104,7 @@ pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
* the kernel by libpcap, but they may include packets not
* yet read from libpcap by the application.
*/
*ps = p->md.stat;
*ps = pd->stat;
/*
* Add in the drop count, as per the above comment.
@ -120,6 +121,7 @@ int
pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
int count, u_char *bufp, int len)
{
struct pcap_dlpi *pd = p->priv;
int n, caplen, origlen;
u_char *ep, *pk;
struct pcap_pkthdr pkthdr;
@ -162,7 +164,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
} else
#endif
sbp = (struct sb_hdr *)bufp;
p->md.stat.ps_drop = sbp->sbh_drops;
pd->stat.ps_drop = sbp->sbh_drops;
pk = bufp + sizeof(*sbp);
bufp += sbp->sbh_totlen;
origlen = sbp->sbh_origlen;
@ -173,7 +175,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
pk = bufp;
bufp += caplen;
#endif
++p->md.stat.ps_recv;
++pd->stat.ps_recv;
if (bpf_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
#ifdef HAVE_SYS_BUFMOD_H
pkthdr.ts.tv_sec = sbp->sbh_timestamp.tv_sec;
@ -187,7 +189,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
if (pkthdr.caplen > p->snapshot)
pkthdr.caplen = p->snapshot;
(*callback)(user, &pkthdr, pk);
if (++n >= count && count >= 0) {
if (++n >= count && !PACKET_COUNT_IS_UNLIMITED(count)) {
p->cc = ep - bufp;
p->bp = bufp;
return (n);
@ -267,46 +269,53 @@ pcap_process_mactype(pcap_t *p, u_int mactype)
* Push and configure the buffer module. Returns -1 for error, otherwise 0.
*/
int
pcap_conf_bufmod(pcap_t *p, int snaplen, int timeout)
pcap_conf_bufmod(pcap_t *p, int snaplen)
{
int retv = 0;
struct timeval to;
bpf_u_int32 ss, chunksize;
/* Non-standard call to get the data nicely buffered. */
if (ioctl(p->fd, I_PUSH, "bufmod") != 0) {
pcap_stream_err("I_PUSH bufmod", errno, p->errbuf);
retv = -1;
return (-1);
}
ss = snaplen;
if (ss > 0 &&
strioctl(p->fd, SBIOCSSNAP, sizeof(ss), (char *)&ss) != 0) {
pcap_stream_err("SBIOCSSNAP", errno, p->errbuf);
retv = -1;
return (-1);
}
/* Set up the bufmod timeout. */
if (timeout != 0) {
struct timeval to;
to.tv_sec = timeout / 1000;
to.tv_usec = (timeout * 1000) % 1000000;
if (p->opt.immediate) {
/* Set the timeout to zero, for immediate delivery. */
to.tv_sec = 0;
to.tv_usec = 0;
if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
pcap_stream_err("SBIOCSTIME", errno, p->errbuf);
retv = -1;
return (-1);
}
} else {
/* Set up the bufmod timeout. */
if (p->opt.timeout != 0) {
to.tv_sec = p->opt.timeout / 1000;
to.tv_usec = (p->opt.timeout * 1000) % 1000000;
if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
pcap_stream_err("SBIOCSTIME", errno, p->errbuf);
return (-1);
}
}
/* Set the chunk length. */
chunksize = CHUNKSIZE;
if (strioctl(p->fd, SBIOCSCHUNK, sizeof(chunksize), (char *)&chunksize)
!= 0) {
pcap_stream_err("SBIOCSCHUNKP", errno, p->errbuf);
return (-1);
}
}
/* Set the chunk length. */
chunksize = CHUNKSIZE;
if (strioctl(p->fd, SBIOCSCHUNK, sizeof(chunksize), (char *)&chunksize)
!= 0) {
pcap_stream_err("SBIOCSCHUNKP", errno, p->errbuf);
retv = -1;
}
return (retv);
return (0);
}
#endif /* HAVE_SYS_BUFMOD_H */

View File

@ -1,7 +1,3 @@
/*
* @(#) $Header: /tcpdump/master/libpcap/dlpisubs.h,v 1.2 2008-04-04 19:37:45 guy Exp $
*/
#ifndef dlpisubs_h
#define dlpisubs_h
@ -10,13 +6,27 @@ extern "C" {
#endif
/*
* Functions used by dlpisubs.c.
* Private data for capturing on DLPI devices.
*/
struct pcap_dlpi {
#ifdef HAVE_LIBDLPI
dlpi_handle_t dlpi_hd;
#endif /* HAVE_LIBDLPI */
#ifdef DL_HP_RAWDLS
int send_fd;
#endif /* DL_HP_RAWDLS */
struct pcap_stat stat;
};
/*
* Functions defined by dlpisubs.c.
*/
int pcap_stats_dlpi(pcap_t *, struct pcap_stat *);
int pcap_process_pkts(pcap_t *, pcap_handler, u_char *, int, u_char *, int);
int pcap_process_mactype(pcap_t *, u_int);
#ifdef HAVE_SYS_BUFMOD_H
int pcap_conf_bufmod(pcap_t *, int, int);
int pcap_conf_bufmod(pcap_t *, int);
#endif
int pcap_alloc_databuf(pcap_t *);
int strioctl(int, int, int, char *);

View File

@ -19,11 +19,6 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/etherent.c,v 1.23 2006-10-04 18:09:22 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/ethertype.h,v 1.14 2005-09-05 09:06:58 guy Exp $ (LBL)
*/
/*

View File

@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/fad-getad.c,v 1.12 2007-09-14 00:44:55 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -60,9 +55,15 @@ static const char rcsid[] _U_ =
#include "os-proto.h"
#endif
#ifdef AF_PACKET
/*
* We don't do this on Solaris 11 and later, as it appears there aren't
* any AF_PACKET addresses on interfaces, so we don't need this, and
* we end up including both the OS's <net/bpf.h> and our <pcap/bpf.h>,
* and their definitions of some data structures collide.
*/
#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
# ifdef HAVE_NETPACKET_PACKET_H
/* Solaris 11 and later, Linux distributions with newer glibc */
/* Linux distributions with newer glibc */
# include <netpacket/packet.h>
# else /* HAVE_NETPACKET_PACKET_H */
/* LynxOS, Linux distributions with older glibc */
@ -75,7 +76,7 @@ static const char rcsid[] _U_ =
# include <linux/if_packet.h>
# endif /* __Lynx__ */
# endif /* HAVE_NETPACKET_PACKET_H */
#endif /* AF_PACKET */
#endif /* (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET) */
/*
* This is fun.
@ -120,7 +121,7 @@ get_sa_len(struct sockaddr *addr)
return (sizeof (struct sockaddr_in6));
#endif
#ifdef AF_PACKET
#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
case AF_PACKET:
return (sizeof (struct sockaddr_ll));
#endif
@ -140,7 +141,7 @@ get_sa_len(struct sockaddr *addr)
* Get a list of all interfaces that are up and that we can open.
* Returns -1 on error, 0 otherwise.
* The list, as returned through "alldevsp", may be null if no interfaces
* were up and could be opened.
* could be opened.
*/
int
pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
@ -156,10 +157,10 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
* Get the list of interface addresses.
*
* Note: this won't return information about interfaces
* with no addresses; are there any such interfaces
* that would be capable of receiving packets?
* (Interfaces incapable of receiving packets aren't
* very interesting from libpcap's point of view.)
* with no addresses, so, if a platform has interfaces
* with no interfaces on which traffic can be captured,
* we must check for those interfaces as well (see, for
* example, what's done on Linux).
*
* LAN interfaces will probably have link-layer
* addresses; I don't know whether all implementations
@ -172,35 +173,12 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
return (-1);
}
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
/*
* Is this interface up?
*/
if (!(ifa->ifa_flags & IFF_UP)) {
/*
* No, so don't add it to the list.
*/
continue;
}
/*
* "ifa_addr" was apparently null on at least one
* interface on some system.
*
* "ifa_broadaddr" may be non-null even on
* non-broadcast interfaces, and was null on
* at least one OpenBSD 3.4 system on at least
* one interface with IFF_BROADCAST set.
*
* "ifa_dstaddr" was, on at least one FreeBSD 4.1
* system, non-null on a non-point-to-point
* interface.
*
* Therefore, we supply the address and netmask only
* if "ifa_addr" is non-null (if there's no address,
* there's obviously no netmask), and supply the
* broadcast and destination addresses if the appropriate
* flag is set *and* the appropriate "ifa_" entry doesn't
* evaluate to a null pointer.
* interface on some system. Therefore, we supply
* the address and netmask only if "ifa_addr" is
* non-null (if there's no address, there's obviously
* no netmask).
*/
if (ifa->ifa_addr != NULL) {
addr = ifa->ifa_addr;
@ -211,6 +189,22 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
addr_size = 0;
netmask = NULL;
}
/*
* Note that, on some platforms, ifa_broadaddr and
* ifa_dstaddr could be the same field (true on at
* least some versions of *BSD and OS X), so we
* can't just check whether the broadcast address
* is null and add it if so and check whether the
* destination address is null and add it if so.
*
* Therefore, we must also check the IFF_BROADCAST
* flag, and only add a broadcast address if it's
* set, and check the IFF_POINTTOPOINT flag, and
* only add a destination address if it's set (as
* per man page recommendations on some of those
* platforms).
*/
if (ifa->ifa_flags & IFF_BROADCAST &&
ifa->ifa_broadaddr != NULL) {
broadaddr = ifa->ifa_broadaddr;

View File

@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/fad-gifc.c,v 1.12 2008-08-06 07:34:09 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -242,8 +237,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
continue;
/*
* Get the flags for this interface, and skip it if it's
* not up.
* Get the flags for this interface.
*/
strncpy(ifrflags.ifr_name, ifrp->ifr_name,
sizeof(ifrflags.ifr_name));
@ -258,8 +252,6 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
ret = -1;
break;
}
if (!(ifrflags.ifr_flags & IFF_UP))
continue;
/*
* Get the netmask for this address on this interface.

View File

@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/fad-glifc.c,v 1.7 2008-01-30 09:35:48 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -208,8 +203,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
#endif
/*
* Get the flags for this interface, and skip it if it's
* not up.
* Get the flags for this interface.
*/
strncpy(ifrflags.lifr_name, ifrp->lifr_name,
sizeof(ifrflags.lifr_name));
@ -224,8 +218,6 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
ret = -1;
break;
}
if (!(ifrflags.lifr_flags & IFF_UP))
continue;
/*
* Get the netmask for this address on this interface.

View File

@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/fad-null.c,v 1.2 2003-11-15 23:23:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -53,7 +48,7 @@ static const char rcsid[] _U_ =
* packet capture.
*/
int
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
/*
* Succeed, but don't return any interfaces; we return only those

View File

@ -24,8 +24,6 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* $Id: fad-sita.c */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

View File

@ -31,11 +31,6 @@
*
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/fad-win32.c,v 1.15 2007-09-25 20:34:36 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -45,102 +40,6 @@ static const char rcsid[] _U_ =
#include <Packet32.h>
#include <errno.h>
/*
* Add an entry to the list of addresses for an interface.
* "curdev" is the entry for that interface.
*/
static int
add_addr_to_list(pcap_if_t *curdev, struct sockaddr *addr,
struct sockaddr *netmask, struct sockaddr *broadaddr,
struct sockaddr *dstaddr, char *errbuf)
{
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
/*
* Allocate the new entry and fill it in.
*/
curaddr = (pcap_addr_t*)malloc(sizeof(pcap_addr_t));
if (curaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
return (-1);
}
curaddr->next = NULL;
if (addr != NULL) {
curaddr->addr = (struct sockaddr*)dup_sockaddr(addr, sizeof(struct sockaddr_storage));
if (curaddr->addr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
free(curaddr);
return (-1);
}
} else
curaddr->addr = NULL;
if (netmask != NULL) {
curaddr->netmask = (struct sockaddr*)dup_sockaddr(netmask, sizeof(struct sockaddr_storage));
if (curaddr->netmask == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
free(curaddr);
return (-1);
}
} else
curaddr->netmask = NULL;
if (broadaddr != NULL) {
curaddr->broadaddr = (struct sockaddr*)dup_sockaddr(broadaddr, sizeof(struct sockaddr_storage));
if (curaddr->broadaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
free(curaddr);
return (-1);
}
} else
curaddr->broadaddr = NULL;
if (dstaddr != NULL) {
curaddr->dstaddr = (struct sockaddr*)dup_sockaddr(dstaddr, sizeof(struct sockaddr_storage));
if (curaddr->dstaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
free(curaddr);
return (-1);
}
} else
curaddr->dstaddr = NULL;
/*
* Find the end of the list of addresses.
*/
for (prevaddr = curdev->addresses; prevaddr != NULL; prevaddr = nextaddr) {
nextaddr = prevaddr->next;
if (nextaddr == NULL) {
/*
* This is the end of the list.
*/
break;
}
}
if (prevaddr == NULL) {
/*
* The list was empty; this is the first member.
*/
curdev->addresses = curaddr;
} else {
/*
* "prevaddr" is the last member of the list; append
* this member to it.
*/
prevaddr->next = curaddr;
}
return (0);
}
static int
pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
@ -189,12 +88,16 @@ pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
*/
if(curdev == NULL)
break;
res = add_addr_to_list(curdev,
res = add_addr_to_dev(curdev,
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
sizeof (struct sockaddr_storage),
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
sizeof (struct sockaddr_storage),
(struct sockaddr *)&if_addrs[if_addr_size].Broadcast,
sizeof (struct sockaddr_storage),
NULL,
errbuf);
0,
errbuf);
if (res == -1) {
/*
* Failure.
@ -216,7 +119,7 @@ pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
* Win32 implementation, based on WinPcap
*/
int
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
pcap_if_t *devlist = NULL;
int ret = 0;
@ -225,6 +128,24 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
ULONG NameLength;
char *name;
/*
* Find out how big a buffer we need.
*
* This call should always return FALSE; if the error is
* ERROR_INSUFFICIENT_BUFFER, NameLength will be set to
* the size of the buffer we need, otherwise there's a
* problem, and NameLength should be set to 0.
*
* It shouldn't require NameLength to be set, but,
* at least as of WinPcap 4.1.3, it checks whether
* NameLength is big enough before it checks for a
* NULL buffer argument, so, while it'll still do
* the right thing if NameLength is uninitialized and
* whatever junk happens to be there is big enough
* (because the pointer argument will be null), it's
* still reading an uninitialized variable.
*/
NameLength = 0;
if (!PacketGetAdapterNames(NULL, &NameLength))
{
DWORD last_error = GetLastError();

View File

@ -21,10 +21,6 @@
*
* $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.309 2008-12-23 20:13:29 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -86,7 +82,7 @@ static const char rcsid[] _U_ =
#include "pcap/sll.h"
#include "pcap/ipnet.h"
#include "arcnet.h"
#if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
#if defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
#include <linux/types.h>
#include <linux/if_packet.h>
#include <linux/filter.h>
@ -143,9 +139,7 @@ static u_int orig_linktype = -1U, orig_nl = -1U, label_stack_depth = -1U;
#endif
/* XXX */
#ifdef PCAP_FDDIPAD
static int pcap_fddipad;
#endif
/* VARARGS */
void
@ -402,38 +396,30 @@ syntax()
static bpf_u_int32 netmask;
static int snaplen;
int no_optimize;
#ifdef WIN32
static int
pcap_compile_unsafe(pcap_t *p, struct bpf_program *program,
const char *buf, int optimize, bpf_u_int32 mask);
int
pcap_compile(pcap_t *p, struct bpf_program *program,
const char *buf, int optimize, bpf_u_int32 mask)
{
int result;
EnterCriticalSection(&g_PcapCompileCriticalSection);
result = pcap_compile_unsafe(p, program, buf, optimize, mask);
LeaveCriticalSection(&g_PcapCompileCriticalSection);
return result;
}
static int
pcap_compile_unsafe(pcap_t *p, struct bpf_program *program,
const char *buf, int optimize, bpf_u_int32 mask)
#else /* WIN32 */
int
pcap_compile(pcap_t *p, struct bpf_program *program,
const char *buf, int optimize, bpf_u_int32 mask)
#endif /* WIN32 */
{
extern int n_errors;
const char * volatile xbuf = buf;
u_int len;
int rc;
/*
* XXX - single-thread this code path with pthread calls on
* UN*X, if the platform supports pthreads? If that requires
* a separate -lpthread, we might not want to do that.
*/
#ifdef WIN32
extern int wsockinit (void);
static int done = 0;
if (!done)
wsockinit();
done = 1;
EnterCriticalSection(&g_PcapCompileCriticalSection);
#endif
/*
* If this pcap_t hasn't been activated, it doesn't have a
@ -442,13 +428,15 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
if (!p->activated) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"not-yet-activated pcap_t passed to pcap_compile");
return (-1);
rc = -1;
goto quit;
}
no_optimize = 0;
n_errors = 0;
root = NULL;
bpf_pcap = p;
init_regs();
if (setjmp(top_ctx)) {
#ifdef INET6
if (ai != NULL) {
@ -458,7 +446,8 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
#endif
lex_cleanup();
freechunks();
return (-1);
rc = -1;
goto quit;
}
netmask = mask;
@ -467,7 +456,8 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
if (snaplen == 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snaplen of 0 rejects all packets");
return -1;
rc = -1;
goto quit;
}
lex_init(xbuf ? xbuf : "");
@ -491,7 +481,16 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
lex_cleanup();
freechunks();
return (0);
rc = 0; /* We're all okay */
quit:
#ifdef WIN32
LeaveCriticalSection(&g_PcapCompileCriticalSection);
#endif
return (rc);
}
/*
@ -596,7 +595,7 @@ finish_parse(p)
* worth the effort.
*/
insert_compute_vloffsets(p->head);
/*
* For DLT_PPI captures, generate a check of the per-packet
* DLT value to make sure it's DLT_IEEE802_11.
@ -878,6 +877,7 @@ static u_int off_proto;
* These are offsets for the MTP2 fields.
*/
static u_int off_li;
static u_int off_li_hsl;
/*
* These are offsets for the MTP3 fields.
@ -927,9 +927,7 @@ init_linktype(p)
pcap_t *p;
{
linktype = pcap_datalink(p);
#ifdef PCAP_FDDIPAD
pcap_fddipad = p->fddipad;
#endif
/*
* Assume it's not raw ATM with a pseudo-header, for now.
@ -951,6 +949,7 @@ init_linktype(p)
* And assume we're not doing SS7.
*/
off_li = -1;
off_li_hsl = -1;
off_sio = -1;
off_opc = -1;
off_dpc = -1;
@ -1066,13 +1065,9 @@ init_linktype(p)
* XXX - should we generate code to check for SNAP?
*/
off_linktype = 13;
#ifdef PCAP_FDDIPAD
off_linktype += pcap_fddipad;
#endif
off_macpl = 13; /* FDDI MAC header length */
#ifdef PCAP_FDDIPAD
off_macpl += pcap_fddipad;
#endif
off_nl = 8; /* 802.2+SNAP */
off_nl_nosnap = 3; /* 802.2 */
return;
@ -1136,7 +1131,7 @@ init_linktype(p)
return;
case DLT_PPI:
/*
/*
* At the moment we treat PPI the same way that we treat
* normal Radiotap encoded packets. The difference is in
* the function that generates the code at the beginning
@ -1343,6 +1338,13 @@ init_linktype(p)
off_nl_nosnap = -1; /* no 802.2 LLC */
return;
case DLT_BACNET_MS_TP:
off_linktype = -1;
off_macpl = -1;
off_nl = -1;
off_nl_nosnap = -1;
return;
case DLT_JUNIPER_SERVICES:
off_linktype = 12;
off_macpl = -1; /* L3 proto location dep. on cookie type */
@ -1383,6 +1385,7 @@ init_linktype(p)
case DLT_MTP2:
off_li = 2;
off_li_hsl = 4;
off_sio = 3;
off_opc = 4;
off_dpc = 4;
@ -1395,6 +1398,7 @@ init_linktype(p)
case DLT_MTP2_WITH_PHDR:
off_li = 6;
off_li_hsl = 8;
off_sio = 7;
off_opc = 8;
off_dpc = 8;
@ -1407,6 +1411,7 @@ init_linktype(p)
case DLT_ERF:
off_li = 22;
off_li_hsl = 24;
off_sio = 23;
off_opc = 24;
off_dpc = 24;
@ -2301,7 +2306,7 @@ gen_load_radiotap_llprefixlen()
return (NULL);
}
/*
/*
* At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates
* the code at the beginning to compute the header length.
@ -2314,7 +2319,7 @@ static struct slist *
gen_load_ppi_llprefixlen()
{
struct slist *s1, *s2;
/*
* Generate code to load the length of the radiotap header
* into the register assigned to hold that length, if one has
@ -2404,7 +2409,7 @@ gen_load_802_11_header_len(struct slist *s, struct slist *snext)
* slist of instructions
*/
no_optimize = 1;
/*
* If "s" is non-null, it has code to arrange that the X register
* contains the length of the prefix preceding the link-layer
@ -2455,7 +2460,7 @@ gen_load_802_11_header_len(struct slist *s, struct slist *snext)
sjset_data_frame_1 = new_stmt(JMP(BPF_JSET));
sjset_data_frame_1->s.k = 0x08;
sappend(s, sjset_data_frame_1);
/*
* If b3 is set, test b2, otherwise go to the first statement of
* the rest of the program.
@ -2474,7 +2479,7 @@ gen_load_802_11_header_len(struct slist *s, struct slist *snext)
sjset_data_frame_2->s.jf = sjset_qos = new_stmt(JMP(BPF_JSET));
sjset_qos->s.k = 0x80; /* QoS bit */
sappend(s, sjset_qos);
/*
* If it's set, add 2 to reg_off_macpl, to skip the QoS
* field.
@ -2745,7 +2750,7 @@ gen_radiotap_llprefixlen(void)
return s;
}
/*
/*
* At the moment we treat PPI as normal Radiotap encoded
* packets. The difference is in the function that generates
* the code at the beginning to compute the header length.
@ -2899,6 +2904,7 @@ gen_linktype(proto)
register int proto;
{
struct block *b0, *b1, *b2;
const char *description;
/* are we checking MPLS-encapsulated packets? */
if (label_stack_depth > 0) {
@ -2906,12 +2912,12 @@ gen_linktype(proto)
case ETHERTYPE_IP:
case PPP_IP:
/* FIXME add other L3 proto IDs */
return gen_mpls_linktype(Q_IP);
return gen_mpls_linktype(Q_IP);
case ETHERTYPE_IPV6:
case PPP_IPV6:
/* FIXME add other L3 proto IDs */
return gen_mpls_linktype(Q_IPV6);
return gen_mpls_linktype(Q_IPV6);
default:
bpf_error("unsupported protocol over mpls");
@ -2983,7 +2989,7 @@ gen_linktype(proto)
case DLT_FDDI:
/*
* XXX - check for asynchronous frames, as per RFC 1103.
* XXX - check for LLC frames.
*/
return gen_llc_linktype(proto);
/*NOTREACHED*/
@ -3195,8 +3201,7 @@ gen_linktype(proto)
* Then we run it through "htonl()", and
* generate code to compare against the result.
*/
if (bpf_pcap->sf.rfile != NULL &&
bpf_pcap->sf.swapped)
if (bpf_pcap->rfile != NULL && bpf_pcap->swapped)
proto = SWAPLONG(proto);
proto = htonl(proto);
}
@ -3351,6 +3356,9 @@ gen_linktype(proto)
*/
return gen_mcmp(OR_LINK, 0, BPF_W, 0x4d474300, 0xffffff00); /* compare the magic number */
case DLT_BACNET_MS_TP:
return gen_mcmp(OR_LINK, 0, BPF_W, 0x55FF0000, 0xffff0000);
case DLT_IPNET:
return gen_ipnet_linktype(proto);
@ -3406,26 +3414,43 @@ gen_linktype(proto)
case DLT_AX25_KISS:
bpf_error("AX.25 link-layer type filtering not implemented");
case DLT_NFLOG:
/* Using the fixed-size NFLOG header it is possible to tell only
* the address family of the packet, other meaningful data is
* either missing or behind TLVs.
*/
bpf_error("NFLOG link-layer type filtering not implemented");
default:
/*
* Does this link-layer header type have a field
* indicating the type of the next protocol? If
* so, off_linktype will be the offset of that
* field in the packet; if not, it will be -1.
*/
if (off_linktype != (u_int)-1) {
/*
* Yes; assume it's an Ethernet type. (If
* it's not, it needs to be handled specially
* above.)
*/
return gen_cmp(OR_LINK, off_linktype, BPF_H, (bpf_int32)proto);
} else {
/*
* No; report an error.
*/
description = pcap_datalink_val_to_description(linktype);
if (description != NULL) {
bpf_error("%s link-layer type filtering not implemented",
description);
} else {
bpf_error("DLT %u link-layer type filtering not implemented",
linktype);
}
}
break;
}
/*
* All the types that have no encapsulation should either be
* handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
* all packets are IP packets, or should be handled in some
* special case, if none of them are (if some are and some
* aren't, the lack of encapsulation is a problem, as we'd
* have to find some other way of determining the packet type).
*
* Therefore, if "off_linktype" is -1, there's an error.
*/
if (off_linktype == (u_int)-1)
abort();
/*
* Any type not handled above should always have an Ethernet
* type at an offset of "off_linktype".
*/
return gen_cmp(OR_LINK, off_linktype, BPF_H, (bpf_int32)proto);
}
/*
@ -3453,6 +3478,178 @@ gen_snap(orgcode, ptype)
return gen_bcmp(OR_MACPL, 0, 8, snapblock);
}
/*
* Generate code to match frames with an LLC header.
*/
struct block *
gen_llc(void)
{
struct block *b0, *b1;
switch (linktype) {
case DLT_EN10MB:
/*
* We check for an Ethernet type field less than
* 1500, which means it's an 802.3 length field.
*/
b0 = gen_cmp_gt(OR_LINK, off_linktype, BPF_H, ETHERMTU);
gen_not(b0);
/*
* Now check for the purported DSAP and SSAP not being
* 0xFF, to rule out NetWare-over-802.3.
*/
b1 = gen_cmp(OR_MACPL, 0, BPF_H, (bpf_int32)0xFFFF);
gen_not(b1);
gen_and(b0, b1);
return b1;
case DLT_SUNATM:
/*
* We check for LLC traffic.
*/
b0 = gen_atmtype_abbrev(A_LLC);
return b0;
case DLT_IEEE802: /* Token Ring */
/*
* XXX - check for LLC frames.
*/
return gen_true();
case DLT_FDDI:
/*
* XXX - check for LLC frames.
*/
return gen_true();
case DLT_ATM_RFC1483:
/*
* For LLC encapsulation, these are defined to have an
* 802.2 LLC header.
*
* For VC encapsulation, they don't, but there's no
* way to check for that; the protocol used on the VC
* is negotiated out of band.
*/
return gen_true();
case DLT_IEEE802_11:
case DLT_PRISM_HEADER:
case DLT_IEEE802_11_RADIO:
case DLT_IEEE802_11_RADIO_AVS:
case DLT_PPI:
/*
* Check that we have a data frame.
*/
b0 = gen_check_802_11_data_frame();
return b0;
default:
bpf_error("'llc' not supported for linktype %d", linktype);
/* NOTREACHED */
}
}
struct block *
gen_llc_i(void)
{
struct block *b0, *b1;
struct slist *s;
/*
* Check whether this is an LLC frame.
*/
b0 = gen_llc();
/*
* Load the control byte and test the low-order bit; it must
* be clear for I frames.
*/
s = gen_load_a(OR_MACPL, 2, BPF_B);
b1 = new_block(JMP(BPF_JSET));
b1->s.k = 0x01;
b1->stmts = s;
gen_not(b1);
gen_and(b0, b1);
return b1;
}
struct block *
gen_llc_s(void)
{
struct block *b0, *b1;
/*
* Check whether this is an LLC frame.
*/
b0 = gen_llc();
/*
* Now compare the low-order 2 bit of the control byte against
* the appropriate value for S frames.
*/
b1 = gen_mcmp(OR_MACPL, 2, BPF_B, LLC_S_FMT, 0x03);
gen_and(b0, b1);
return b1;
}
struct block *
gen_llc_u(void)
{
struct block *b0, *b1;
/*
* Check whether this is an LLC frame.
*/
b0 = gen_llc();
/*
* Now compare the low-order 2 bit of the control byte against
* the appropriate value for U frames.
*/
b1 = gen_mcmp(OR_MACPL, 2, BPF_B, LLC_U_FMT, 0x03);
gen_and(b0, b1);
return b1;
}
struct block *
gen_llc_s_subtype(bpf_u_int32 subtype)
{
struct block *b0, *b1;
/*
* Check whether this is an LLC frame.
*/
b0 = gen_llc();
/*
* Now check for an S frame with the appropriate type.
*/
b1 = gen_mcmp(OR_MACPL, 2, BPF_B, subtype, LLC_S_CMD_MASK);
gen_and(b0, b1);
return b1;
}
struct block *
gen_llc_u_subtype(bpf_u_int32 subtype)
{
struct block *b0, *b1;
/*
* Check whether this is an LLC frame.
*/
b0 = gen_llc();
/*
* Now check for a U frame with the appropriate type.
*/
b1 = gen_mcmp(OR_MACPL, 2, BPF_B, subtype, LLC_U_CMD_MASK);
gen_and(b0, b1);
return b1;
}
/*
* Generate code to match a particular packet type, for link-layer types
* using 802.2 LLC headers.
@ -3705,18 +3902,10 @@ gen_fhostop(eaddr, dir)
switch (dir) {
case Q_SRC:
#ifdef PCAP_FDDIPAD
return gen_bcmp(OR_LINK, 6 + 1 + pcap_fddipad, 6, eaddr);
#else
return gen_bcmp(OR_LINK, 6 + 1, 6, eaddr);
#endif
case Q_DST:
#ifdef PCAP_FDDIPAD
return gen_bcmp(OR_LINK, 0 + 1 + pcap_fddipad, 6, eaddr);
#else
return gen_bcmp(OR_LINK, 0 + 1, 6, eaddr);
#endif
case Q_AND:
b0 = gen_fhostop(eaddr, Q_SRC);
@ -4411,7 +4600,7 @@ gen_mpls_linktype(proto)
b1 = gen_mcmp(OR_NET, 0, BPF_B, 0x40, 0xf0);
gen_and(b0, b1);
return b1;
case Q_IPV6:
/* match the bottom-of-stack bit */
b0 = gen_mcmp(OR_NET, -2, BPF_B, 0x01, 0x01);
@ -4419,7 +4608,7 @@ gen_mpls_linktype(proto)
b1 = gen_mcmp(OR_NET, 0, BPF_B, 0x60, 0xf0);
gen_and(b0, b1);
return b1;
default:
abort();
}
@ -4577,6 +4766,9 @@ gen_host6(addr, mask, proto, dir, type)
case Q_DEFAULT:
return gen_host6(addr, mask, Q_IPV6, dir, type);
case Q_LINK:
bpf_error("link-layer modifier applied to ip6 %s", typestr);
case Q_IP:
bpf_error("'ip' modifier applied to ip6 %s", typestr);
@ -5223,7 +5415,7 @@ gen_portrangeatom(off, v1, v2)
b1 = gen_cmp_ge(OR_TRAN_IPV4, off, BPF_H, v1);
b2 = gen_cmp_le(OR_TRAN_IPV4, off, BPF_H, v2);
gen_and(b1, b2);
gen_and(b1, b2);
return b2;
}
@ -5325,7 +5517,7 @@ gen_portrangeatom6(off, v1, v2)
b1 = gen_cmp_ge(OR_TRAN_IPV6, off, BPF_H, v1);
b2 = gen_cmp_le(OR_TRAN_IPV6, off, BPF_H, v2);
gen_and(b1, b2);
gen_and(b1, b2);
return b2;
}
@ -5775,7 +5967,7 @@ gen_check_802_11_data_frame()
b0 = new_block(JMP(BPF_JSET));
b0->s.k = 0x08;
b0->stmts = s;
s = gen_load_a(OR_LINK, 0, BPF_B);
b1 = new_block(JMP(BPF_JSET));
b1->s.k = 0x04;
@ -6251,7 +6443,7 @@ gen_scode(name, q)
if (proto != Q_DEFAULT &&
proto != Q_UDP && proto != Q_TCP && proto != Q_SCTP)
bpf_error("illegal qualifier of 'portrange'");
if (pcap_nametoportrange(name, &port1, &port2, &real_proto) == 0)
if (pcap_nametoportrange(name, &port1, &port2, &real_proto) == 0)
bpf_error("unknown port in range '%s'", name);
if (proto == Q_UDP) {
if (real_proto == IPPROTO_TCP)
@ -6278,7 +6470,7 @@ gen_scode(name, q)
bpf_error("port in range '%s' is tcp", name);
else
/* override PROTO_UNDEF */
real_proto = IPPROTO_SCTP;
real_proto = IPPROTO_SCTP;
}
if (port1 < 0)
bpf_error("illegal port number %d < 0", port1);
@ -7535,14 +7727,14 @@ gen_inbound(dir)
* check it, otherwise give up as this link-layer type
* has nothing in the packet data.
*/
#if defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
#if defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
/*
* We infer that this is Linux with PF_PACKET support.
* This is Linux with PF_PACKET support.
* If this is a *live* capture, we can look at
* special meta-data in the filter expression;
* if it's a savefile, we can't.
*/
if (bpf_pcap->sf.rfile != NULL) {
if (bpf_pcap->rfile != NULL) {
/* We have a FILE *, so this is a savefile */
bpf_error("inbound/outbound not supported on linktype %d when reading savefiles",
linktype);
@ -7556,12 +7748,12 @@ gen_inbound(dir)
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
#else /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
#else /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
bpf_error("inbound/outbound not supported on linktype %d",
linktype);
b0 = NULL;
/* NOTREACHED */
#endif /* defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
#endif /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
}
return (b0);
}
@ -7970,22 +8162,22 @@ gen_mpls(label_num)
* etc.
*/
switch (linktype) {
case DLT_C_HDLC: /* fall through */
case DLT_EN10MB:
case DLT_NETANALYZER:
case DLT_NETANALYZER_TRANSPARENT:
b0 = gen_linktype(ETHERTYPE_MPLS);
break;
case DLT_PPP:
b0 = gen_linktype(PPP_MPLS_UCAST);
break;
/* FIXME add other DLT_s ...
* for Frame-Relay/and ATM this may get messy due to SNAP headers
* leave it for now */
default:
bpf_error("no MPLS support for data link type %d",
linktype);
@ -8021,9 +8213,10 @@ gen_pppoed()
}
struct block *
gen_pppoes()
gen_pppoes(sess_num)
int sess_num;
{
struct block *b0;
struct block *b0, *b1;
/*
* Test against the PPPoE session link-layer type.
@ -8063,6 +8256,14 @@ gen_pppoes()
orig_nl = off_nl;
is_pppoes = 1;
/* If a specific session is requested, check PPPoE session id */
if (sess_num >= 0) {
b1 = gen_mcmp(OR_MACPL, orig_nl, BPF_W,
(bpf_int32)sess_num, 0x0000ffff);
gen_and(b0, b1);
b0 = b1;
}
/*
* The "network-layer" protocol is PPPoE, which has a 6-byte
* PPPoE header, followed by a PPP packet.
@ -8247,11 +8448,12 @@ gen_atmtype_abbrev(type)
return b1;
}
/*
/*
* Filtering for MTP2 messages based on li value
* FISU, length is null
* LSSU, length is 1 or 2
* MSU, length is 3 or more
* For MTP2_HSL, sequences are on 2 bytes, and length on 9 bits
*/
struct block *
gen_mtp2type_abbrev(type)
@ -8288,6 +8490,33 @@ gen_mtp2type_abbrev(type)
b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 0, 2);
break;
case MH_FISU:
if ( (linktype != DLT_MTP2) &&
(linktype != DLT_ERF) &&
(linktype != DLT_MTP2_WITH_PHDR) )
bpf_error("'hfisu' supported only on MTP2_HSL");
/* gen_ncmp(offrel, offset, size, mask, jtype, reverse, value) */
b0 = gen_ncmp(OR_PACKET, off_li_hsl, BPF_H, 0xff80, BPF_JEQ, 0, 0);
break;
case MH_LSSU:
if ( (linktype != DLT_MTP2) &&
(linktype != DLT_ERF) &&
(linktype != DLT_MTP2_WITH_PHDR) )
bpf_error("'hlssu' supported only on MTP2_HSL");
b0 = gen_ncmp(OR_PACKET, off_li_hsl, BPF_H, 0xff80, BPF_JGT, 1, 0x0100);
b1 = gen_ncmp(OR_PACKET, off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0);
gen_and(b1, b0);
break;
case MH_MSU:
if ( (linktype != DLT_MTP2) &&
(linktype != DLT_ERF) &&
(linktype != DLT_MTP2_WITH_PHDR) )
bpf_error("'hmsu' supported only on MTP2_HSL");
b0 = gen_ncmp(OR_PACKET, off_li_hsl, BPF_H, 0xff80, BPF_JGT, 0, 0x0100);
break;
default:
abort();
}
@ -8303,9 +8532,17 @@ gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
{
struct block *b0;
bpf_u_int32 val1 , val2 , val3;
u_int newoff_sio=off_sio;
u_int newoff_opc=off_opc;
u_int newoff_dpc=off_dpc;
u_int newoff_sls=off_sls;
switch (mtp3field) {
case MH_SIO:
newoff_sio += 3; /* offset for MTP2_HSL */
/* FALLTHROUGH */
case M_SIO:
if (off_sio == (u_int)-1)
bpf_error("'sio' supported only on SS7");
@ -8313,10 +8550,12 @@ gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
if(jvalue > 255)
bpf_error("sio value %u too big; max value = 255",
jvalue);
b0 = gen_ncmp(OR_PACKET, off_sio, BPF_B, 0xffffffff,
b0 = gen_ncmp(OR_PACKET, newoff_sio, BPF_B, 0xffffffff,
(u_int)jtype, reverse, (u_int)jvalue);
break;
case MH_OPC:
newoff_opc+=3;
case M_OPC:
if (off_opc == (u_int)-1)
bpf_error("'opc' supported only on SS7");
@ -8333,10 +8572,14 @@ gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
val3 = jvalue & 0x00000003;
val3 = val3 <<22;
jvalue = val1 + val2 + val3;
b0 = gen_ncmp(OR_PACKET, off_opc, BPF_W, 0x00c0ff0f,
b0 = gen_ncmp(OR_PACKET, newoff_opc, BPF_W, 0x00c0ff0f,
(u_int)jtype, reverse, (u_int)jvalue);
break;
case MH_DPC:
newoff_dpc += 3;
/* FALLTHROUGH */
case M_DPC:
if (off_dpc == (u_int)-1)
bpf_error("'dpc' supported only on SS7");
@ -8351,10 +8594,12 @@ gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
val2 = jvalue & 0x00003f00;
val2 = val2 << 8;
jvalue = val1 + val2;
b0 = gen_ncmp(OR_PACKET, off_dpc, BPF_W, 0xff3f0000,
b0 = gen_ncmp(OR_PACKET, newoff_dpc, BPF_W, 0xff3f0000,
(u_int)jtype, reverse, (u_int)jvalue);
break;
case MH_SLS:
newoff_sls+=3;
case M_SLS:
if (off_sls == (u_int)-1)
bpf_error("'sls' supported only on SS7");
@ -8365,7 +8610,7 @@ gen_mtp3field_code(mtp3field, jvalue, jtype, reverse)
/* the following instruction is made to convert jvalue
* to the forme used to write sls in an ss7 message*/
jvalue = jvalue << 4;
b0 = gen_ncmp(OR_PACKET, off_sls, BPF_B, 0xf0,
b0 = gen_ncmp(OR_PACKET, newoff_sls, BPF_B, 0xf0,
(u_int)jtype,reverse, (u_int)jvalue);
break;

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.71 2007-11-18 02:03:52 guy Exp $ (LBL)
*/
/*
@ -186,12 +184,23 @@
#define M_LSSU 23 /* LSSU */
#define M_MSU 24 /* MSU */
/* MTP2 HSL types */
#define MH_FISU 25 /* FISU for HSL */
#define MH_LSSU 26 /* LSSU */
#define MH_MSU 27 /* MSU */
/* MTP3 field types */
#define M_SIO 1
#define M_OPC 2
#define M_DPC 3
#define M_SLS 4
/* MTP3 field types in case of MTP2 HSL */
#define MH_SIO 5
#define MH_OPC 6
#define MH_DPC 7
#define MH_SLS 8
struct slist;
@ -299,11 +308,18 @@ struct block *gen_broadcast(int);
struct block *gen_multicast(int);
struct block *gen_inbound(int);
struct block *gen_llc(void);
struct block *gen_llc_i(void);
struct block *gen_llc_s(void);
struct block *gen_llc_u(void);
struct block *gen_llc_s_subtype(bpf_u_int32);
struct block *gen_llc_u_subtype(bpf_u_int32);
struct block *gen_vlan(int);
struct block *gen_mpls(int);
struct block *gen_pppoed(void);
struct block *gen_pppoes(void);
struct block *gen_pppoes(int);
struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse);
struct block *gen_atmtype_abbrev(int type);
@ -325,7 +341,11 @@ struct block *gen_p80211_fcdir(int);
void bpf_optimize(struct block **);
void bpf_error(const char *, ...)
__attribute__((noreturn, format (printf, 1, 2)));
__attribute__((noreturn))
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format (printf, 1, 2)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
void finish_parse(struct block *);
char *sdup(const char *);

View File

@ -21,10 +21,6 @@
*
* $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.101 2007-11-18 02:03:52 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -59,6 +55,7 @@ struct rtentry;
#include <netpfil/pf/pf.h>
#include <net/if_pflog.h>
#endif
#include "llc.h"
#include "ieee80211.h"
#include <pcap/namedb.h>
@ -133,6 +130,23 @@ static const struct tok ieee80211_data_subtypes[] = {
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
{ 0, NULL }
};
static const struct tok llc_s_subtypes[] = {
{ LLC_RR, "rr" },
{ LLC_RNR, "rnr" },
{ LLC_REJ, "rej" },
{ 0, NULL }
};
static const struct tok llc_u_subtypes[] = {
{ LLC_UI, "ui" },
{ LLC_UA, "ua" },
{ LLC_DISC, "disc" },
{ LLC_DM, "dm" },
{ LLC_SABME, "sabme" },
{ LLC_TEST, "test" },
{ LLC_XID, "xid" },
{ LLC_FRMR, "frmr" },
{ 0, NULL }
};
struct type2tok {
int type;
const struct tok *tok;
@ -262,7 +276,7 @@ pfaction_to_num(const char *action)
%type <a> arth narth
%type <i> byteop pname pnum relop irelop
%type <blk> and or paren not null prog
%type <rblk> other pfvar p80211
%type <rblk> other pfvar p80211 pllc
%type <i> atmtype atmmultitype
%type <blk> atmfield
%type <blk> atmfieldvalue atmvalue atmlistvalue
@ -295,8 +309,9 @@ pfaction_to_num(const char *action)
%token OAM OAMF4 CONNECTMSG METACONNECT
%token VPI VCI
%token RADIO
%token FISU LSSU MSU
%token SIO OPC DPC SLS
%token FISU LSSU MSU HFISU HLSSU HMSU
%token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
%type <s> ID
%type <e> EID
@ -507,9 +522,11 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
| MPLS pnum { $$ = gen_mpls($2); }
| MPLS { $$ = gen_mpls(-1); }
| PPPOED { $$ = gen_pppoed(); }
| PPPOES { $$ = gen_pppoes(); }
| PPPOES pnum { $$ = gen_pppoes($2); }
| PPPOES { $$ = gen_pppoes(-1); }
| pfvar { $$ = $1; }
| pqual p80211 { $$ = $2; }
| pllc { $$ = $1; }
;
pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
@ -579,6 +596,31 @@ type_subtype: ID { int i;
}
;
pllc: LLC { $$ = gen_llc(); }
| LLC ID { if (pcap_strcasecmp($2, "i") == 0)
$$ = gen_llc_i();
else if (pcap_strcasecmp($2, "s") == 0)
$$ = gen_llc_s();
else if (pcap_strcasecmp($2, "u") == 0)
$$ = gen_llc_u();
else {
u_int subtype;
subtype = str2tok($2, llc_s_subtypes);
if (subtype != -1)
$$ = gen_llc_s_subtype(subtype);
else {
subtype = str2tok($2, llc_u_subtypes);
if (subtype == -1)
bpf_error("unknown LLC type name \"%s\"", $2);
$$ = gen_llc_u_subtype(subtype);
}
}
}
/* sigh, "rnr" is already a keyword for PF */
| LLC PF_RNR { $$ = gen_llc_s_subtype(LLC_RNR); }
;
dir: NUM
| ID { if (pcap_strcasecmp($1, "nods") == 0)
$$ = IEEE80211_FC1_DIR_NODS;
@ -617,8 +659,10 @@ narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
| arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
| arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
| arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
| arth '%' arth { $$ = gen_arth(BPF_MOD, $1, $3); }
| arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
| arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
| arth '^' arth { $$ = gen_arth(BPF_XOR, $1, $3); }
| arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
| arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
| '-' arth %prec UMINUS { $$ = gen_neg($2); }
@ -635,7 +679,6 @@ pnum: NUM
| paren pnum ')' { $$ = $2; }
;
atmtype: LANE { $$ = A_LANE; }
| LLC { $$ = A_LLC; }
| METAC { $$ = A_METAC; }
| BCC { $$ = A_BCC; }
| OAMF4EC { $$ = A_OAMF4EC; }
@ -671,12 +714,19 @@ atmlistvalue: atmfieldvalue
mtp2type: FISU { $$ = M_FISU; }
| LSSU { $$ = M_LSSU; }
| MSU { $$ = M_MSU; }
| HFISU { $$ = MH_FISU; }
| HLSSU { $$ = MH_LSSU; }
| HMSU { $$ = MH_MSU; }
;
/* MTP3 field types quantifier */
mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
| OPC { $$.mtp3fieldtype = M_OPC; }
| DPC { $$.mtp3fieldtype = M_DPC; }
| SLS { $$.mtp3fieldtype = M_SLS; }
| HSIO { $$.mtp3fieldtype = MH_SIO; }
| HOPC { $$.mtp3fieldtype = MH_OPC; }
| HDPC { $$.mtp3fieldtype = MH_DPC; }
| HSLS { $$.mtp3fieldtype = MH_SLS; }
;
mtp3value: mtp3fieldvalue
| relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
@ -688,7 +738,11 @@ mtp3fieldvalue: NUM {
if ($$.mtp3fieldtype == M_SIO ||
$$.mtp3fieldtype == M_OPC ||
$$.mtp3fieldtype == M_DPC ||
$$.mtp3fieldtype == M_SLS )
$$.mtp3fieldtype == M_SLS ||
$$.mtp3fieldtype == MH_SIO ||
$$.mtp3fieldtype == MH_OPC ||
$$.mtp3fieldtype == MH_DPC ||
$$.mtp3fieldtype == MH_SLS)
$$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
}
;

View File

@ -32,11 +32,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.79 2008-04-20 18:19:02 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -90,6 +85,18 @@ struct rtentry; /* declarations in <net/if.h> */
(isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
#endif
#ifdef IFF_UP
#define ISUP(flags) ((flags) & IFF_UP)
#else
#define ISUP(flags) 0
#endif
#ifdef IFF_RUNNING
#define ISRUNNING(flags) ((flags) & IFF_RUNNING)
#else
#define ISRUNNING(flags) 0
#endif
struct sockaddr *
dup_sockaddr(struct sockaddr *sa, size_t sa_length)
{
@ -100,40 +107,85 @@ dup_sockaddr(struct sockaddr *sa, size_t sa_length)
return (memcpy(newsa, sa, sa_length));
}
static int
get_instance(const char *name)
/*
* Construct a "figure of merit" for an interface, for use when sorting
* the list of interfaces, in which interfaces that are up are superior
* to interfaces that aren't up, interfaces that are up and running are
* superior to interfaces that are up but not running, and non-loopback
* interfaces that are up and running are superior to loopback interfaces,
* and interfaces with the same flags have a figure of merit that's higher
* the lower the instance number.
*
* The goal is to try to put the interfaces most likely to be useful for
* capture at the beginning of the list.
*
* The figure of merit, which is lower the "better" the interface is,
* has the uppermost bit set if the interface isn't running, the bit
* below that set if the interface isn't up, the bit below that set
* if the interface is a loopback interface, and the interface index
* in the 29 bits below that. (Yes, we assume u_int is 32 bits.)
*/
static u_int
get_figure_of_merit(pcap_if_t *dev)
{
const char *cp, *endcp;
int n;
const char *cp;
u_int n;
if (strcmp(name, "any") == 0) {
if (strcmp(dev->name, "any") == 0) {
/*
* Give the "any" device an artificially high instance
* number, so it shows up after all other non-loopback
* interfaces.
*/
return INT_MAX;
n = 0x1FFFFFFF; /* 29 all-1 bits */
} else {
/*
* A number at the end of the device name string is
* assumed to be a unit number.
*/
cp = dev->name + strlen(dev->name) - 1;
while (cp-1 >= dev->name && *(cp-1) >= '0' && *(cp-1) <= '9')
cp--;
if (*cp >= '0' && *cp <= '9')
n = atoi(cp);
else
n = 0;
}
endcp = name + strlen(name);
for (cp = name; cp < endcp && !isdigit((unsigned char)*cp); ++cp)
continue;
if (isdigit((unsigned char)*cp))
n = atoi(cp);
else
n = 0;
if (!(dev->flags & PCAP_IF_RUNNING))
n |= 0x80000000;
if (!(dev->flags & PCAP_IF_UP))
n |= 0x40000000;
if (dev->flags & PCAP_IF_LOOPBACK)
n |= 0x20000000;
return (n);
}
/*
* Look for a given device in the specified list of devices.
*
* If we find it, return 0 and set *curdev_ret to point to it.
*
* If we don't find it, check whether we can open it:
*
* If that fails with PCAP_ERROR_NO_SUCH_DEVICE or
* PCAP_ERROR_IFACE_NOT_UP, don't attempt to add an entry for
* it, as that probably means it exists but doesn't support
* packet capture.
*
* Otherwise, attempt to add an entry for it, with the specified
* ifnet flags and description, and, if that succeeds, return 0
* and set *curdev_ret to point to the new entry, otherwise
* return PCAP_ERROR and set errbuf to an error message.
*/
int
add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
u_int flags, const char *description, char *errbuf)
{
pcap_t *p;
pcap_if_t *curdev, *prevdev, *nextdev;
int this_instance;
u_int this_figure_of_merit, nextdev_figure_of_merit;
char open_errbuf[PCAP_ERRBUF_SIZE];
int ret;
/*
* Is there already an entry in the list for this interface?
@ -193,23 +245,72 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
}
strcpy(en_name, "en");
strcat(en_name, name + 3);
p = pcap_open_live(en_name, 68, 0, 0, open_errbuf);
p = pcap_create(en_name, open_errbuf);
free(en_name);
} else
#endif /* __APPLE */
p = pcap_open_live(name, 68, 0, 0, open_errbuf);
p = pcap_create(name, open_errbuf);
if (p == NULL) {
/*
* No. Don't bother including it.
* Don't treat this as an error, though.
* The attempt to create the pcap_t failed;
* that's probably an indication that we're
* out of memory.
*
* Don't bother including this interface,
* but don't treat it as an error.
*/
*curdev_ret = NULL;
return (0);
}
/* Small snaplen, so we don't try to allocate much memory. */
pcap_set_snaplen(p, 68);
ret = pcap_activate(p);
pcap_close(p);
switch (ret) {
case PCAP_ERROR_NO_SUCH_DEVICE:
case PCAP_ERROR_IFACE_NOT_UP:
/*
* We expect these two errors - they're the
* reason we try to open the device.
*
* PCAP_ERROR_NO_SUCH_DEVICE typically means
* "there's no such device *known to the
* OS's capture mechanism*", so, even though
* it might be a valid network interface, you
* can't capture on it (e.g., the loopback
* device in Solaris up to Solaris 10, or
* the vmnet devices in OS X with VMware
* Fusion). We don't include those devices
* in our list of devices, as there's no
* point in doing so - they're not available
* for capture.
*
* PCAP_ERROR_IFACE_NOT_UP means that the
* OS's capture mechanism doesn't work on
* interfaces not marked as up; some capture
* mechanisms *do* support that, so we no
* longer reject those interfaces out of hand,
* but we *do* want to reject them if they
* can't be opened for capture.
*/
*curdev_ret = NULL;
return (0);
}
/*
* Yes, we can open it.
* Yes, we can open it, or we can't, for some other
* reason.
*
* If we can open it, we want to offer it for
* capture, as you can capture on it. If we can't,
* we want to offer it for capture, so that, if
* the user tries to capture on it, they'll get
* an error and they'll know why they can't
* capture on it (e.g., insufficient permissions)
* or they'll report it as a problem (and then
* have the error message to provide as information).
*
* Allocate a new entry.
*/
curdev = malloc(sizeof(pcap_if_t));
@ -252,20 +353,22 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
curdev->flags = 0;
if (ISLOOPBACK(name, flags))
curdev->flags |= PCAP_IF_LOOPBACK;
if (ISUP(flags))
curdev->flags |= PCAP_IF_UP;
if (ISRUNNING(flags))
curdev->flags |= PCAP_IF_RUNNING;
/*
* Add it to the list, in the appropriate location.
* First, get the instance number of this interface.
* First, get the "figure of merit" for this
* interface.
*/
this_instance = get_instance(name);
this_figure_of_merit = get_figure_of_merit(curdev);
/*
* Now look for the last interface with an instance number
* less than or equal to the new interface's instance
* number - except that non-loopback interfaces are
* arbitrarily treated as having interface numbers less
* than those of loopback interfaces, so the loopback
* interfaces are put at the end of the list.
* Now look for the last interface with an figure of merit
* less than or equal to the new interface's figure of
* merit.
*
* We start with "prevdev" being NULL, meaning we're before
* the first element in the list.
@ -295,34 +398,13 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
}
/*
* Is the new interface a non-loopback interface
* and the next interface a loopback interface?
* Is the new interface's figure of merit less
* than the next interface's figure of merit,
* meaning that the new interface is better
* than the next interface?
*/
if (!(curdev->flags & PCAP_IF_LOOPBACK) &&
(nextdev->flags & PCAP_IF_LOOPBACK)) {
/*
* Yes, we should put the new entry
* before "nextdev", i.e. after "prevdev".
*/
break;
}
/*
* Is the new interface's instance number less
* than the next interface's instance number,
* and is it the case that the new interface is a
* non-loopback interface or the next interface is
* a loopback interface?
*
* (The goal of both loopback tests is to make
* sure that we never put a loopback interface
* before any non-loopback interface and that we
* always put a non-loopback interface before all
* loopback interfaces.)
*/
if (this_instance < get_instance(nextdev->name) &&
(!(curdev->flags & PCAP_IF_LOOPBACK) ||
(nextdev->flags & PCAP_IF_LOOPBACK))) {
nextdev_figure_of_merit = get_figure_of_merit(nextdev);
if (this_figure_of_merit < nextdev_figure_of_merit) {
/*
* Yes - we should put the new entry
* before "nextdev", i.e. after "prevdev".
@ -358,6 +440,9 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
}
/*
* Try to get a description for a given device.
* Returns a mallocated description if it could and NULL if it couldn't.
*
* XXX - on FreeBSDs that support it, should it get the sysctl named
* "dev.{adapter family name}.{adapter unit}.%desc" to get a description
* of the adapter? Note that "dev.an.0.%desc" is "Aironet PC4500/PC4800"
@ -403,18 +488,11 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
* Do any other UN*Xes, or desktop environments support getting a
* description?
*/
int
add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
struct sockaddr *addr, size_t addr_size,
struct sockaddr *netmask, size_t netmask_size,
struct sockaddr *broadaddr, size_t broadaddr_size,
struct sockaddr *dstaddr, size_t dstaddr_size,
char *errbuf)
static char *
get_if_description(const char *name)
{
pcap_if_t *curdev;
char *description = NULL;
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
#ifdef SIOCGIFDESCR
char *description = NULL;
int s;
struct ifreq ifrdesc;
#ifndef IFDESCRSIZE
@ -422,9 +500,7 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
#else
size_t descrlen = IFDESCRSIZE;
#endif /* IFDESCRSIZE */
#endif /* SIOCGIFDESCR */
#ifdef SIOCGIFDESCR
/*
* Get the description for the interface.
*/
@ -485,8 +561,44 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
description = NULL;
}
}
#endif /* SIOCGIFDESCR */
return (description);
#else /* SIOCGIFDESCR */
return (NULL);
#endif /* SIOCGIFDESCR */
}
/*
* Try to get a description for a given device, and then look for that
* device in the specified list of devices.
*
* If we find it, add the specified address to it and return 0.
*
* If we don't find it, check whether we can open it:
*
* If that fails with PCAP_ERROR_NO_SUCH_DEVICE or
* PCAP_ERROR_IFACE_NOT_UP, don't attempt to add an entry for
* it, as that probably means it exists but doesn't support
* packet capture.
*
* Otherwise, attempt to add an entry for it, with the specified
* ifnet flags and description, and, if that succeeds, add the
* specified address to it, set *curdev_ret to point to the new
* entry, and return 0, otherwise return PCAP_ERROR and set errbuf
* to an error message.
*/
int
add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
struct sockaddr *addr, size_t addr_size,
struct sockaddr *netmask, size_t netmask_size,
struct sockaddr *broadaddr, size_t broadaddr_size,
struct sockaddr *dstaddr, size_t dstaddr_size,
char *errbuf)
{
char *description;
pcap_if_t *curdev;
description = get_if_description(name);
if (add_or_find_if(&curdev, alldevs, name, flags, description,
errbuf) == -1) {
free(description);
@ -510,6 +622,26 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
*
* Allocate the new entry and fill it in.
*/
return (add_addr_to_dev(curdev, addr, addr_size, netmask, netmask_size,
broadaddr, broadaddr_size, dstaddr, dstaddr_size, errbuf));
}
/*
* Add an entry to the list of addresses for an interface.
* "curdev" is the entry for that interface.
* If this is the first IP address added to the interface, move it
* in the list as appropriate.
*/
int
add_addr_to_dev(pcap_if_t *curdev,
struct sockaddr *addr, size_t addr_size,
struct sockaddr *netmask, size_t netmask_size,
struct sockaddr *broadaddr, size_t broadaddr_size,
struct sockaddr *dstaddr, size_t dstaddr_size,
char *errbuf)
{
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
curaddr = malloc(sizeof(pcap_addr_t));
if (curaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
@ -603,6 +735,23 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
return (0);
}
/*
* Look for a given device in the specified list of devices.
*
* If we find it, return 0.
*
* If we don't find it, check whether we can open it:
*
* If that fails with PCAP_ERROR_NO_SUCH_DEVICE or
* PCAP_ERROR_IFACE_NOT_UP, don't attempt to add an entry for
* it, as that probably means it exists but doesn't support
* packet capture.
*
* Otherwise, attempt to add an entry for it, with the specified
* ifnet flags and description, and, if that succeeds, return 0
* and set *curdev_ret to point to the new entry, otherwise
* return PCAP_ERROR and set errbuf to an error message.
*/
int
pcap_add_if(pcap_if_t **devlist, const char *name, u_int flags,
const char *description, char *errbuf)
@ -821,14 +970,14 @@ pcap_lookupdev(errbuf)
DWORD dwWindowsMajorVersion;
dwVersion = GetVersion(); /* get the OS version */
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
if (dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4) {
/*
* Windows 95, 98, ME.
*/
ULONG NameLength = 8192;
static char AdaptersName[8192];
if (PacketGetAdapterNames(AdaptersName,&NameLength) )
return (AdaptersName);
else
@ -891,7 +1040,7 @@ pcap_lookupdev(errbuf)
free(TAdaptersName);
return (char *)(AdaptersName);
}
}
}
@ -901,7 +1050,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
register bpf_u_int32 *netp, *maskp;
register char *errbuf;
{
/*
/*
* We need only the first IPv4 address, so we must scan the array returned by PacketGetNetInfo()
* in order to skip non IPv4 (i.e. IPv6 addresses)
*/
@ -927,7 +1076,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
*netp &= *maskp;
return (0);
}
}
*netp = *maskp = 0;

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-aix4.h,v 1.1 2002-06-01 09:37:40 guy Exp $
*/
/* Prototypes missing in AIX 4.x */

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-hpux11.h,v 1.1 2002-06-01 09:37:41 guy Exp $
*/
/* Prototypes missing in HP-UX 11.x */

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-osf4.h,v 1.2 2000-12-22 11:51:33 guy Exp $ (LBL)
*/
/* Prototypes missing in Digital UNIX 4.x */

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-osf5.h,v 1.2 2002-08-02 03:24:15 guy Exp $ (LBL)
*/
/*

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-solaris2.h,v 1.19 2000-10-11 04:02:52 guy Exp $ (LBL)
*/
/* Prototypes missing in SunOS 5 */

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-sunos4.h,v 1.32 1999-10-07 23:46:41 mcr Exp $ (LBL)
*/
/* Prototypes missing in SunOS 4 */

View File

@ -17,8 +17,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/lbl/os-ultrix4.h,v 1.19 1999-10-07 23:46:41 mcr Exp $ (LBL)
*/
/* Prototypes missing in Ultrix 4 */

View File

@ -17,10 +17,39 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/llc.h,v 1.2 2001-01-28 09:44:50 guy Exp $ (LBL)
*/
/*
* Definitions for information in the LLC header.
*/
#define LLC_U_FMT 3
#define LLC_GSAP 1
#define LLC_IG 1 /* Individual / Group */
#define LLC_S_FMT 1
#define LLC_U_POLL 0x10
#define LLC_IS_POLL 0x0100
#define LLC_XID_FI 0x81
#define LLC_U_CMD_MASK 0xef
#define LLC_UI 0x03
#define LLC_UA 0x63
#define LLC_DISC 0x43
#define LLC_DM 0x0f
#define LLC_SABME 0x6f
#define LLC_TEST 0xe3
#define LLC_XID 0xaf
#define LLC_FRMR 0x87
#define LLC_S_CMD_MASK 0x0f
#define LLC_RR 0x0001
#define LLC_RNR 0x0005
#define LLC_REJ 0x0009
#define LLC_IS_NR(is) (((is) >> 9) & 0x7f)
#define LLC_I_NS(is) (((is) >> 1) & 0x7f)
/*
* 802.2 LLC SAP values.
*/
@ -31,10 +60,10 @@
#ifndef LLCSAP_GLOBAL
#define LLCSAP_GLOBAL 0xff
#endif
#ifndef LLCSAP_8021B
#ifndef LLCSAP_8021B_I
#define LLCSAP_8021B_I 0x02
#endif
#ifndef LLCSAP_8021B
#ifndef LLCSAP_8021B_G
#define LLCSAP_8021B_G 0x03
#endif
#ifndef LLCSAP_IP

View File

@ -31,17 +31,10 @@
* SUCH DAMAGE.
*/
/* $Id: snprintf.c,v 1.1 2004-04-05 22:43:51 guy Exp $ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/missing/snprintf.c,v 1.1 2004-04-05 22:43:51 guy Exp $";
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

View File

@ -18,6 +18,7 @@ export PATH
MAKE=Makefile # default makefile name is "Makefile"
CC=cc # default C compiler is "cc"
DEPENDENCY_CFLAG=-M # default dependency-generation flag is -M
while :
do case "$1" in
@ -31,6 +32,11 @@ while :
MAKE=$2
shift; shift ;;
# -m allows you to specify the dependency-generation flag
-m)
DEPENDENCY_CFLAG=$2
shift; shift ;;
# the -p flag produces "program: program.c" style dependencies
# so .o's don't get produced
-p)
@ -42,7 +48,7 @@ while :
done
if [ $# = 0 ] ; then
echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...'
echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
exit 1
fi
@ -74,7 +80,7 @@ _EOF_
# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
$CC -M $* |
$CC $DEPENDENCY_CFLAG $* |
sed "
s; \./; ;g
$SED" |

View File

@ -24,11 +24,6 @@
* $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.83 2008-02-06 10:21:30 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -426,6 +421,8 @@ pcap_ether_aton(const char *s)
register u_int d;
e = ep = (u_char *)malloc(6);
if (e == NULL)
return (NULL);
while (*s) {
if (*s == ':' || *s == '.' || *s == '-')

View File

@ -14,8 +14,6 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/nlpid.h,v 1.2 2002-12-06 00:01:34 hannes Exp $ (Juniper)
*/
/* Types missing from some systems */

View File

@ -20,10 +20,6 @@
*
* Optimization module for tcpdump intermediate representation.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.91 2008-01-02 04:16:46 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -579,6 +575,10 @@ vstore(struct stmt *s, int *valp, int newval, int alter)
*valp = newval;
}
/*
* Do constant-folding on binary operators.
* (Unary operators are handled elsewhere.)
*/
static void
fold_op(struct stmt *s, int v0, int v1)
{
@ -606,6 +606,12 @@ fold_op(struct stmt *s, int v0, int v1)
a /= b;
break;
case BPF_MOD:
if (b == 0)
bpf_error("modulus by zero");
a %= b;
break;
case BPF_AND:
a &= b;
break;
@ -614,6 +620,10 @@ fold_op(struct stmt *s, int v0, int v1)
a |= b;
break;
case BPF_XOR:
a ^= b;
break;
case BPF_LSH:
a <<= b;
break;
@ -622,10 +632,6 @@ fold_op(struct stmt *s, int v0, int v1)
a >>= b;
break;
case BPF_NEG:
a = -a;
break;
default:
abort();
}
@ -978,8 +984,10 @@ opt_stmt(struct stmt *s, int val[], int alter)
case BPF_ALU|BPF_SUB|BPF_K:
case BPF_ALU|BPF_MUL|BPF_K:
case BPF_ALU|BPF_DIV|BPF_K:
case BPF_ALU|BPF_MOD|BPF_K:
case BPF_ALU|BPF_AND|BPF_K:
case BPF_ALU|BPF_OR|BPF_K:
case BPF_ALU|BPF_XOR|BPF_K:
case BPF_ALU|BPF_LSH|BPF_K:
case BPF_ALU|BPF_RSH|BPF_K:
op = BPF_OP(s->code);
@ -990,7 +998,7 @@ opt_stmt(struct stmt *s, int val[], int alter)
* fixup the generated math code */
if (op == BPF_ADD ||
op == BPF_LSH || op == BPF_RSH ||
op == BPF_OR) {
op == BPF_OR || op == BPF_XOR) {
s->code = NOP;
break;
}
@ -1013,8 +1021,10 @@ opt_stmt(struct stmt *s, int val[], int alter)
case BPF_ALU|BPF_SUB|BPF_X:
case BPF_ALU|BPF_MUL|BPF_X:
case BPF_ALU|BPF_DIV|BPF_X:
case BPF_ALU|BPF_MOD|BPF_X:
case BPF_ALU|BPF_AND|BPF_X:
case BPF_ALU|BPF_OR|BPF_X:
case BPF_ALU|BPF_XOR|BPF_X:
case BPF_ALU|BPF_LSH|BPF_X:
case BPF_ALU|BPF_RSH|BPF_X:
op = BPF_OP(s->code);
@ -1041,12 +1051,12 @@ opt_stmt(struct stmt *s, int val[], int alter)
*/
if (alter && vmap[val[A_ATOM]].is_const
&& vmap[val[A_ATOM]].const_val == 0) {
if (op == BPF_ADD || op == BPF_OR) {
if (op == BPF_ADD || op == BPF_OR || op == BPF_XOR) {
s->code = BPF_MISC|BPF_TXA;
vstore(s, &val[A_ATOM], val[X_ATOM], alter);
break;
}
else if (op == BPF_MUL || op == BPF_DIV ||
else if (op == BPF_MUL || op == BPF_DIV || op == BPF_MOD ||
op == BPF_AND || op == BPF_LSH || op == BPF_RSH) {
s->code = BPF_LD|BPF_IMM;
s->k = 0;

View File

@ -20,10 +20,6 @@
*
* $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.116 2008-09-16 18:42:29 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -128,6 +124,56 @@ static int bpf_load(char *errbuf);
#include "os-proto.h"
#endif
/*
* Later versions of NetBSD stick padding in front of FDDI frames
* to align the IP header on a 4-byte boundary.
*/
#if defined(__NetBSD__) && __NetBSD_Version__ > 106000000
#define PCAP_FDDIPAD 3
#endif
/*
* Private data for capturing on BPF devices.
*/
struct pcap_bpf {
#ifdef PCAP_FDDIPAD
int fddipad;
#endif
#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;
int nonblock; /* true if in nonblocking mode */
#endif /* HAVE_ZEROCOPY_BPF */
char *device; /* device name */
int filtering_in_kernel; /* using kernel filter */
int must_do_on_close; /* stuff we must do when we close */
};
/*
* Stuff to do when we close.
*/
#define MUST_CLEAR_RFMON 0x00000001 /* clear rfmon (monitor) mode */
#ifdef BIOCGDLTLIST
# if (defined(HAVE_NET_IF_MEDIA_H) && defined(IFM_IEEE80211)) && !defined(__APPLE__)
#define HAVE_BSD_IEEE80211
@ -186,22 +232,17 @@ static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
/*
* For zerocopy bpf, the setnonblock/getnonblock routines need to modify
* p->md.timeout so we don't call select(2) if the pcap handle is in non-
* blocking mode. We preserve the timeout supplied by pcap_open functions
* to make sure it does not get clobbered if the pcap handle moves between
* blocking and non-blocking mode.
* pb->nonblock so we don't call select(2) if the pcap handle is in non-
* blocking mode.
*/
static int
pcap_getnonblock_bpf(pcap_t *p, char *errbuf)
{
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.zerocopy) {
/*
* Use a negative value for the timeout to represent that the
* pcap handle is in non-blocking mode.
*/
return (p->md.timeout < 0);
}
struct pcap_bpf *pb = p->priv;
if (pb->zerocopy)
return (pb->nonblock);
#endif
return (pcap_getnonblock_fd(p, errbuf));
}
@ -210,25 +251,10 @@ static int
pcap_setnonblock_bpf(pcap_t *p, int nonblock, char *errbuf)
{
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.zerocopy) {
/*
* Map each value to their corresponding negation to
* preserve the timeout value provided with pcap_set_timeout.
* (from pcap-linux.c).
*/
if (nonblock) {
if (p->md.timeout >= 0) {
/*
* Indicate that we're switching to
* non-blocking mode.
*/
p->md.timeout = ~p->md.timeout;
}
} else {
if (p->md.timeout < 0) {
p->md.timeout = ~p->md.timeout;
}
}
struct pcap_bpf *pb = p->priv;
if (pb->zerocopy) {
pb->nonblock = nonblock;
return (0);
}
#endif
@ -248,25 +274,26 @@ pcap_setnonblock_bpf(pcap_t *p, int nonblock, char *errbuf)
static int
pcap_next_zbuf_shm(pcap_t *p, int *cc)
{
struct pcap_bpf *pb = p->priv;
struct bpf_zbuf_header *bzh;
if (p->md.zbuffer == p->md.zbuf2 || p->md.zbuffer == NULL) {
bzh = (struct bpf_zbuf_header *)p->md.zbuf1;
if (pb->zbuffer == pb->zbuf2 || pb->zbuffer == NULL) {
bzh = (struct bpf_zbuf_header *)pb->zbuf1;
if (bzh->bzh_user_gen !=
atomic_load_acq_int(&bzh->bzh_kernel_gen)) {
p->md.bzh = bzh;
p->md.zbuffer = (u_char *)p->md.zbuf1;
p->buffer = p->md.zbuffer + sizeof(*bzh);
pb->bzh = bzh;
pb->zbuffer = (u_char *)pb->zbuf1;
p->buffer = pb->zbuffer + sizeof(*bzh);
*cc = bzh->bzh_kernel_len;
return (1);
}
} else if (p->md.zbuffer == p->md.zbuf1) {
bzh = (struct bpf_zbuf_header *)p->md.zbuf2;
} else if (pb->zbuffer == pb->zbuf1) {
bzh = (struct bpf_zbuf_header *)pb->zbuf2;
if (bzh->bzh_user_gen !=
atomic_load_acq_int(&bzh->bzh_kernel_gen)) {
p->md.bzh = bzh;
p->md.zbuffer = (u_char *)p->md.zbuf2;
p->buffer = p->md.zbuffer + sizeof(*bzh);
pb->bzh = bzh;
pb->zbuffer = (u_char *)pb->zbuf2;
p->buffer = pb->zbuffer + sizeof(*bzh);
*cc = bzh->bzh_kernel_len;
return (1);
}
@ -285,6 +312,7 @@ pcap_next_zbuf_shm(pcap_t *p, int *cc)
static int
pcap_next_zbuf(pcap_t *p, int *cc)
{
struct pcap_bpf *pb = p->priv;
struct bpf_zbuf bz;
struct timeval tv;
struct timespec cur;
@ -308,15 +336,15 @@ pcap_next_zbuf(pcap_t *p, int *cc)
* our timeout is less then or equal to zero, handle it like a
* regular timeout.
*/
tmout = p->md.timeout;
tmout = p->opt.timeout;
if (tmout)
(void) clock_gettime(CLOCK_MONOTONIC, &cur);
if (p->md.interrupted && p->md.timeout) {
expire = TSTOMILLI(&p->md.firstsel) + p->md.timeout;
if (pb->interrupted && p->opt.timeout) {
expire = TSTOMILLI(&pb->firstsel) + p->opt.timeout;
tmout = expire - TSTOMILLI(&cur);
#undef TSTOMILLI
if (tmout <= 0) {
p->md.interrupted = 0;
pb->interrupted = 0;
data = pcap_next_zbuf_shm(p, cc);
if (data)
return (data);
@ -333,7 +361,7 @@ pcap_next_zbuf(pcap_t *p, int *cc)
* the next timeout. Note that we only call select if the handle
* is in blocking mode.
*/
if (p->md.timeout >= 0) {
if (!pb->nonblock) {
FD_ZERO(&r_set);
FD_SET(p->fd, &r_set);
if (tmout != 0) {
@ -341,11 +369,11 @@ pcap_next_zbuf(pcap_t *p, int *cc)
tv.tv_usec = (tmout * 1000) % 1000000;
}
r = select(p->fd + 1, &r_set, NULL, NULL,
p->md.timeout != 0 ? &tv : NULL);
p->opt.timeout != 0 ? &tv : NULL);
if (r < 0 && errno == EINTR) {
if (!p->md.interrupted && p->md.timeout) {
p->md.interrupted = 1;
p->md.firstsel = cur;
if (!pb->interrupted && p->opt.timeout) {
pb->interrupted = 1;
pb->firstsel = cur;
}
return (0);
} else if (r < 0) {
@ -354,7 +382,7 @@ pcap_next_zbuf(pcap_t *p, int *cc)
return (PCAP_ERROR);
}
}
p->md.interrupted = 0;
pb->interrupted = 0;
/*
* Check again for data, which may exist now that we've either been
* woken up as a result of data or timed out. Try the "there's data"
@ -382,10 +410,11 @@ pcap_next_zbuf(pcap_t *p, int *cc)
static int
pcap_ack_zbuf(pcap_t *p)
{
struct pcap_bpf *pb = p->priv;
atomic_store_rel_int(&p->md.bzh->bzh_user_gen,
p->md.bzh->bzh_kernel_gen);
p->md.bzh = NULL;
atomic_store_rel_int(&pb->bzh->bzh_user_gen,
pb->bzh->bzh_kernel_gen);
pb->bzh = NULL;
p->buffer = NULL;
return (0);
}
@ -396,7 +425,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_bpf));
if (p == NULL)
return (NULL);
@ -792,6 +821,7 @@ pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
static int
pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_bpf *pb = p->priv;
int cc;
int n = 0;
register u_char *bp, *ep;
@ -827,7 +857,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* buffer.
*/
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.zerocopy) {
if (pb->zerocopy) {
if (p->buffer != NULL)
pcap_ack_zbuf(p);
i = pcap_next_zbuf(p, &cc);
@ -975,7 +1005,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* skipping that padding.
#endif
*/
if (p->md.use_bpf ||
if (pb->filtering_in_kernel ||
bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
struct pcap_pkthdr pkthdr;
@ -1005,7 +1035,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
#endif
(*callback)(user, &pkthdr, datap);
bp += BPF_WORDALIGN(caplen + hdrlen);
if (++n >= cnt && cnt > 0) {
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
p->bp = bp;
p->cc = ep - bp;
/*
@ -1242,19 +1272,20 @@ bpf_load(char *errbuf)
static void
pcap_cleanup_bpf(pcap_t *p)
{
struct pcap_bpf *pb = p->priv;
#ifdef HAVE_BSD_IEEE80211
int sock;
struct ifmediareq req;
struct ifreq ifr;
#endif
if (p->md.must_do_on_close != 0) {
if (pb->must_do_on_close != 0) {
/*
* There's something we have to do when closing this
* pcap_t.
*/
#ifdef HAVE_BSD_IEEE80211
if (p->md.must_do_on_close & MUST_CLEAR_RFMON) {
if (pb->must_do_on_close & MUST_CLEAR_RFMON) {
/*
* We put the interface into rfmon mode;
* take it out of rfmon mode.
@ -1271,7 +1302,7 @@ pcap_cleanup_bpf(pcap_t *p)
strerror(errno));
} else {
memset(&req, 0, sizeof(req));
strncpy(req.ifm_name, p->md.device,
strncpy(req.ifm_name, pb->device,
sizeof(req.ifm_name));
if (ioctl(sock, SIOCGIFMEDIA, &req) < 0) {
fprintf(stderr,
@ -1286,7 +1317,7 @@ pcap_cleanup_bpf(pcap_t *p)
*/
memset(&ifr, 0, sizeof(ifr));
(void)strncpy(ifr.ifr_name,
p->md.device,
pb->device,
sizeof(ifr.ifr_name));
ifr.ifr_media =
req.ifm_current & ~IFM_IEEE80211_MONITOR;
@ -1309,11 +1340,11 @@ pcap_cleanup_bpf(pcap_t *p)
* have to take the interface out of some mode.
*/
pcap_remove_from_pcaps_to_close(p);
p->md.must_do_on_close = 0;
pb->must_do_on_close = 0;
}
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.zerocopy) {
if (pb->zerocopy) {
/*
* Delete the mappings. Note that p->buffer gets
* initialized to one of the mmapped regions in
@ -1321,17 +1352,17 @@ pcap_cleanup_bpf(pcap_t *p)
* null it out so that pcap_cleanup_live_common()
* doesn't try to free it.
*/
if (p->md.zbuf1 != MAP_FAILED && p->md.zbuf1 != NULL)
(void) munmap(p->md.zbuf1, p->md.zbufsize);
if (p->md.zbuf2 != MAP_FAILED && p->md.zbuf2 != NULL)
(void) munmap(p->md.zbuf2, p->md.zbufsize);
if (pb->zbuf1 != MAP_FAILED && pb->zbuf1 != NULL)
(void) munmap(pb->zbuf1, pb->zbufsize);
if (pb->zbuf2 != MAP_FAILED && pb->zbuf2 != NULL)
(void) munmap(pb->zbuf2, pb->zbufsize);
p->buffer = NULL;
p->buffer = NULL;
}
#endif
if (p->md.device != NULL) {
free(p->md.device);
p->md.device = NULL;
if (pb->device != NULL) {
free(pb->device);
pb->device = NULL;
}
pcap_cleanup_live_common(p);
}
@ -1446,7 +1477,11 @@ check_setif_failure(pcap_t *p, int error)
static int
pcap_activate_bpf(pcap_t *p)
{
struct pcap_bpf *pb = p->priv;
int status = 0;
#ifdef HAVE_BSD_IEEE80211
int retv;
#endif
int fd;
#ifdef LIFNAMSIZ
char *zonesep;
@ -1536,8 +1571,8 @@ pcap_activate_bpf(pcap_t *p)
}
#endif
p->md.device = strdup(p->opt.source);
if (p->md.device == NULL) {
pb->device = strdup(p->opt.source);
if (pb->device == NULL) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "strdup: %s",
pcap_strerror(errno));
status = PCAP_ERROR;
@ -1652,7 +1687,7 @@ pcap_activate_bpf(pcap_t *p)
/*
* We have zerocopy BPF; use it.
*/
p->md.zerocopy = 1;
pb->zerocopy = 1;
/*
* How to pick a buffer size: first, query the maximum buffer
@ -1666,6 +1701,7 @@ pcap_activate_bpf(pcap_t *p)
if (ioctl(fd, BIOCGETZMAX, (caddr_t)&zbufmax) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGETZMAX: %s",
pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
@ -1682,34 +1718,37 @@ pcap_activate_bpf(pcap_t *p)
#ifndef roundup
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
#endif
p->md.zbufsize = roundup(v, getpagesize());
if (p->md.zbufsize > zbufmax)
p->md.zbufsize = zbufmax;
p->md.zbuf1 = mmap(NULL, p->md.zbufsize, PROT_READ | PROT_WRITE,
pb->zbufsize = roundup(v, getpagesize());
if (pb->zbufsize > zbufmax)
pb->zbufsize = zbufmax;
pb->zbuf1 = mmap(NULL, pb->zbufsize, PROT_READ | PROT_WRITE,
MAP_ANON, -1, 0);
p->md.zbuf2 = mmap(NULL, p->md.zbufsize, PROT_READ | PROT_WRITE,
pb->zbuf2 = mmap(NULL, pb->zbufsize, PROT_READ | PROT_WRITE,
MAP_ANON, -1, 0);
if (p->md.zbuf1 == MAP_FAILED || p->md.zbuf2 == MAP_FAILED) {
if (pb->zbuf1 == MAP_FAILED || pb->zbuf2 == MAP_FAILED) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "mmap: %s",
pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
memset(&bz, 0, sizeof(bz)); /* bzero() deprecated, replaced with memset() */
bz.bz_bufa = p->md.zbuf1;
bz.bz_bufb = p->md.zbuf2;
bz.bz_buflen = p->md.zbufsize;
bz.bz_bufa = pb->zbuf1;
bz.bz_bufb = pb->zbuf2;
bz.bz_buflen = pb->zbufsize;
if (ioctl(fd, BIOCSETZBUF, (caddr_t)&bz) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETZBUF: %s",
pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
(void)strncpy(ifrname, p->opt.source, ifnamsiz);
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s",
p->opt.source, pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
v = p->md.zbufsize - sizeof(struct bpf_zbuf_header);
v = pb->zbufsize - sizeof(struct bpf_zbuf_header);
} else
#endif
{
@ -1961,11 +2000,12 @@ pcap_activate_bpf(pcap_t *p)
/*
* Try to put the interface into monitor mode.
*/
status = monitor_mode(p, 1);
if (status != 0) {
retv = monitor_mode(p, 1);
if (retv != 0) {
/*
* We failed.
*/
status = retv;
goto bad;
}
@ -2022,8 +2062,8 @@ pcap_activate_bpf(pcap_t *p)
if (v == DLT_FDDI)
p->fddipad = PCAP_FDDIPAD;
else
p->fddipad = 0;
#endif
p->fddipad = 0;
p->linktype = v;
#if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT)
@ -2045,9 +2085,14 @@ pcap_activate_bpf(pcap_t *p)
#endif
/* set timeout */
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.timeout != 0 && !p->md.zerocopy) {
/*
* In zero-copy mode, we just use the timeout in select().
* XXX - what if we're in non-blocking mode and the *application*
* is using select() or poll() or kqueues or....?
*/
if (p->opt.timeout && !pb->zerocopy) {
#else
if (p->md.timeout) {
if (p->opt.timeout) {
#endif
/*
* XXX - is this seconds/nanoseconds in AIX?
@ -2071,8 +2116,8 @@ pcap_activate_bpf(pcap_t *p)
struct BPF_TIMEVAL bpf_to;
if (IOCPARM_LEN(BIOCSRTIMEOUT) != sizeof(struct timeval)) {
bpf_to.tv_sec = p->md.timeout / 1000;
bpf_to.tv_usec = (p->md.timeout * 1000) % 1000000;
bpf_to.tv_sec = p->opt.timeout / 1000;
bpf_to.tv_usec = (p->opt.timeout * 1000) % 1000000;
if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&bpf_to) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"BIOCSRTIMEOUT: %s", pcap_strerror(errno));
@ -2081,8 +2126,8 @@ pcap_activate_bpf(pcap_t *p)
}
} else {
#endif
to.tv_sec = p->md.timeout / 1000;
to.tv_usec = (p->md.timeout * 1000) % 1000000;
to.tv_sec = p->opt.timeout / 1000;
to.tv_usec = (p->opt.timeout * 1000) % 1000000;
if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"BIOCSRTIMEOUT: %s", pcap_strerror(errno));
@ -2094,7 +2139,6 @@ pcap_activate_bpf(pcap_t *p)
#endif
}
#ifdef _AIX
#ifdef BIOCIMMEDIATE
/*
* Darren Reed notes that
@ -2106,51 +2150,38 @@ pcap_activate_bpf(pcap_t *p)
* is reducing things to only a few packets (i.e. one every
* second or so).
*
* so we turn BIOCIMMEDIATE mode on if this is AIX.
* so we always turn BIOCIMMEDIATE mode on if this is AIX.
*
* We don't turn it on for other platforms, as that means we
* get woken up for every packet, which may not be what we want;
* in the Winter 1993 USENIX paper on BPF, they say:
* For other platforms, we don't turn immediate mode on by default,
* as that would mean we get woken up for every packet, which
* probably isn't what you want for a packet sniffer.
*
* Since a process might want to look at every packet on a
* network and the time between packets can be only a few
* microseconds, it is not possible to do a read system call
* per packet and BPF must collect the data from several
* packets and return it as a unit when the monitoring
* application does a read.
*
* which I infer is the reason for the timeout - it means we
* wait that amount of time, in the hopes that more packets
* will arrive and we'll get them all with one read.
*
* Setting BIOCIMMEDIATE mode on FreeBSD (and probably other
* BSDs) causes the timeout to be ignored.
*
* On the other hand, some platforms (e.g., Linux) don't support
* timeouts, they just hand stuff to you as soon as it arrives;
* if that doesn't cause a problem on those platforms, it may
* be OK to have BIOCIMMEDIATE mode on BSD as well.
*
* (Note, though, that applications may depend on the read
* completing, even if no packets have arrived, when the timeout
* expires, e.g. GUI applications that have to check for input
* while waiting for packets to arrive; a non-zero timeout
* prevents "select()" from working right on FreeBSD and
* possibly other BSDs, as the timer doesn't start until a
* "read()" is done, so the timer isn't in effect if the
* application is blocked on a "select()", and the "select()"
* doesn't get woken up for a BPF device until the buffer
* fills up.)
* We set immediate mode if the caller requested it by calling
* pcap_set_immediate() before calling pcap_activate().
*/
v = 1;
if (ioctl(p->fd, BIOCIMMEDIATE, &v) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCIMMEDIATE: %s",
pcap_strerror(errno));
#ifndef _AIX
if (p->opt.immediate) {
#endif /* _AIX */
v = 1;
if (ioctl(p->fd, BIOCIMMEDIATE, &v) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"BIOCIMMEDIATE: %s", pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
#ifndef _AIX
}
#endif /* _AIX */
#else /* BIOCIMMEDIATE */
if (p->opt.immediate) {
/*
* We don't support immediate mode. Fail.
*/
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Immediate mode not supported");
status = PCAP_ERROR;
goto bad;
}
#endif /* BIOCIMMEDIATE */
#endif /* _AIX */
#endif /* BIOCIMMEDIATE */
if (p->opt.promisc) {
/* set promiscuous mode, just warn if it fails */
@ -2169,7 +2200,7 @@ pcap_activate_bpf(pcap_t *p)
}
p->bufsize = v;
#ifdef HAVE_ZEROCOPY_BPF
if (!p->md.zerocopy) {
if (!pb->zerocopy) {
#endif
p->buffer = (u_char *)malloc(p->bufsize);
if (p->buffer == NULL) {
@ -2270,7 +2301,7 @@ pcap_activate_bpf(pcap_t *p)
return (status);
bad:
pcap_cleanup_bpf(p);
pcap_cleanup_bpf(p);
return (status);
}
@ -2284,6 +2315,7 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
static int
monitor_mode(pcap_t *p, int set)
{
struct pcap_bpf *pb = p->priv;
int sock;
struct ifmediareq req;
int *media_list;
@ -2421,7 +2453,7 @@ monitor_mode(pcap_t *p, int set)
return (PCAP_ERROR);
}
p->md.must_do_on_close |= MUST_CLEAR_RFMON;
pb->must_do_on_close |= MUST_CLEAR_RFMON;
/*
* Add this to the list of pcaps to close when we exit.
@ -2598,6 +2630,8 @@ remove_802_11(pcap_t *p)
static int
pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
{
struct pcap_bpf *pb = p->priv;
/*
* Free any user-mode filter we might happen to have installed.
*/
@ -2610,7 +2644,7 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
/*
* It worked.
*/
p->md.use_bpf = 1; /* filtering in the kernel */
pb->filtering_in_kernel = 1; /* filtering in the kernel */
/*
* Discard any previously-received packets, as they might
@ -2650,7 +2684,7 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
*/
if (install_bpf_program(p, fp) < 0)
return (-1);
p->md.use_bpf = 0; /* filtering in userland */
pb->filtering_in_kernel = 0; /* filtering in userland */
return (0);
}

View File

@ -34,8 +34,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007-04-01 21:43:55 guy Exp $ (LBL)
*/
/*

View File

@ -31,10 +31,6 @@
* By Paolo Abeni <paolo.abeni@email.it>
*
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.15 2008-07-01 07:05:54 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -70,10 +66,16 @@ static int bt_inject_linux(pcap_t *, const void *, size_t);
static int bt_setdirection_linux(pcap_t *, pcap_direction_t);
static int bt_stats_linux(pcap_t *, struct pcap_stat *);
/*
* Private data for capturing on Linux Bluetooth devices.
*/
struct pcap_bt {
int dev_id; /* device ID of device we're bound to */
};
int
bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
pcap_if_t *found_dev = *alldevsp;
struct hci_dev_list_req *dev_list;
struct hci_dev_req *dev_req;
int i, sock;
@ -117,7 +119,7 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
snprintf(dev_name, 20, BT_IFACE"%d", dev_req->dev_id);
snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
if (pcap_add_if(&found_dev, dev_name, 0,
if (pcap_add_if(alldevsp, dev_name, 0,
dev_descr, err_str) < 0)
{
ret = -1;
@ -169,7 +171,7 @@ bt_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_bt));
if (p == NULL)
return (NULL);
@ -180,6 +182,7 @@ bt_create(const char *device, char *ebuf, int *is_ours)
static int
bt_activate(pcap_t* handle)
{
struct pcap_bt *handlep = handle->priv;
struct sockaddr_hci addr;
int opt;
int dev_id;
@ -208,7 +211,7 @@ bt_activate(pcap_t* handle)
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
handle->stats_op = bt_stats_linux;
handle->md.ifindex = dev_id;
handlep->dev_id = dev_id;
/* Create HCI socket */
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
@ -253,13 +256,13 @@ bt_activate(pcap_t* handle)
/* Bind socket to the HCI device */
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = handle->md.ifindex;
addr.hci_dev = handlep->dev_id;
#ifdef SOCKADDR_HCI_HAS_HCI_CHANNEL
addr.hci_channel = HCI_CHANNEL_RAW;
#endif
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't attach to device %d: %s", handle->md.ifindex,
"Can't attach to device %d: %s", handlep->dev_id,
strerror(errno));
goto close_fail;
}
@ -374,10 +377,11 @@ bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
static int
bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_bt *handlep = handle->priv;
int ret;
struct hci_dev_info dev_info;
struct hci_dev_stats * s = &dev_info.stat;
dev_info.dev_id = handle->md.ifindex;
dev_info.dev_id = handlep->dev_id;
/* ignore eintr */
do {

View File

@ -29,8 +29,6 @@
*
* Bluetooth sniffing API implementation for Linux platform
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.h,v 1.5 2008-04-04 19:37:45 guy Exp $ (LBL)
*/
/*

View File

@ -0,0 +1,241 @@
/*
* Copyright (c) 2014 Michal Labedzki for Tieto Corporation
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* OWNER 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.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/mgmt.h>
#include "pcap/bluetooth.h"
#include "pcap-int.h"
#define BT_CONTROL_SIZE 32
#define INTERFACE_NAME "bluetooth-monitor"
int
bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
int ret = 0;
if (pcap_add_if(alldevsp, INTERFACE_NAME, 0,
"Bluetooth Linux Monitor", err_str) < 0)
{
ret = -1;
}
return ret;
}
static int
bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *user)
{
struct cmsghdr *cmsg;
struct msghdr msg;
struct iovec iv[2];
ssize_t ret;
struct pcap_pkthdr pkth;
pcap_bluetooth_linux_monitor_header *bthdr;
struct mgmt_hdr hdr;
int in = 0;
bthdr = (pcap_bluetooth_linux_monitor_header*) &handle->buffer[handle->offset];
iv[0].iov_base = &hdr;
iv[0].iov_len = MGMT_HDR_SIZE;
iv[1].iov_base = &handle->buffer[handle->offset + sizeof(pcap_bluetooth_linux_monitor_header)];
iv[1].iov_len = handle->snapshot;
memset(&pkth.ts, 0, sizeof(pkth.ts));
memset(&msg, 0, sizeof(msg));
msg.msg_iov = iv;
msg.msg_iovlen = 2;
msg.msg_control = handle->buffer;
msg.msg_controllen = handle->offset;
do {
ret = recvmsg(handle->fd, &msg, 0);
if (handle->break_loop)
{
handle->break_loop = 0;
return -2;
}
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't receive packet: %s", strerror(errno));
return -1;
}
pkth.caplen = ret - MGMT_HDR_SIZE + sizeof(pcap_bluetooth_linux_monitor_header);
pkth.len = pkth.caplen;
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != SOL_SOCKET) continue;
if (cmsg->cmsg_type == SCM_TIMESTAMP) {
memcpy(&pkth.ts, CMSG_DATA(cmsg), sizeof(pkth.ts));
}
}
bthdr->adapter_id = htons(hdr.index);
bthdr->opcode = htons(hdr.opcode);
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, &handle->buffer[handle->offset],
pkth.len, pkth.caplen)) {
callback(user, &pkth, &handle->buffer[handle->offset]);
return 1;
}
return 0; /* didn't pass filter */
}
static int
bt_monitor_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet");
return -1;
}
static int
bt_monitor_setdirection(pcap_t *p, pcap_direction_t d)
{
p->direction = d;
return 0;
}
static int
bt_monitor_stats(pcap_t *handle _U_, struct pcap_stat *stats)
{
stats->ps_recv = 0;
stats->ps_drop = 0;
stats->ps_ifdrop = 0;
return 0;
}
static int
bt_monitor_activate(pcap_t* handle)
{
struct sockaddr_hci addr;
int err = PCAP_ERROR;
int opt;
if (handle->opt.rfmon) {
/* monitor mode doesn't apply here */
return PCAP_ERROR_RFMON_NOTSUP;
}
handle->bufsize = handle->snapshot + BT_CONTROL_SIZE + sizeof(pcap_bluetooth_linux_monitor_header);
handle->offset = BT_CONTROL_SIZE;
handle->linktype = DLT_BLUETOOTH_LINUX_MONITOR;
handle->read_op = bt_monitor_read;
handle->inject_op = bt_monitor_inject;
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
handle->setdirection_op = bt_monitor_setdirection;
handle->set_datalink_op = NULL; /* can't change data link type */
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
handle->stats_op = bt_monitor_stats;
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (handle->fd < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't create raw socket: %s", strerror(errno));
return PCAP_ERROR;
}
handle->buffer = malloc(handle->bufsize);
if (!handle->buffer) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s",
pcap_strerror(errno));
goto close_fail;
}
/* Bind socket to the HCI device */
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = HCI_DEV_NONE;
addr.hci_channel = HCI_CHANNEL_MONITOR;
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't attach to interface: %s", strerror(errno));
goto close_fail;
}
opt = 1;
if (setsockopt(handle->fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't enable time stamp: %s", strerror(errno));
goto close_fail;
}
handle->selectable_fd = handle->fd;
return 0;
close_fail:
pcap_cleanup_live_common(handle);
return err;
}
pcap_t *
bt_monitor_create(const char *device, char *ebuf, int *is_ours)
{
pcap_t *p;
const char *cp;
cp = strrchr(device, '/');
if (cp == NULL)
cp = device;
if (strcmp(cp, INTERFACE_NAME) != 0) {
*is_ours = 0;
return NULL;
}
*is_ours = 1;
p = pcap_create_common(device, ebuf, 0);
if (p == NULL)
return NULL;
p->activate_op = bt_monitor_activate;
return p;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2014 Michal Labedzki for Tieto Corporation
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* OWNER 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.
*/
int bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str);
pcap_t *bt_monitor_create(const char *device, char *ebuf, int *is_ours);

View File

@ -72,6 +72,13 @@ static int can_setfilter_linux(pcap_t *, struct bpf_program *);
static int can_setdirection_linux(pcap_t *, pcap_direction_t);
static int can_stats_linux(pcap_t *, struct pcap_stat *);
/*
* Private data for capturing on Linux CANbus devices.
*/
struct pcap_can {
int ifindex; /* interface index of device we're bound to */
};
int
can_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
@ -124,7 +131,7 @@ can_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_can));
if (p == NULL)
return (NULL);
@ -136,6 +143,7 @@ can_create(const char *device, char *ebuf, int *is_ours)
static int
can_activate(pcap_t* handle)
{
struct pcap_can *handlep = handle->priv;
struct sockaddr_can addr;
struct ifreq ifr;
@ -172,7 +180,7 @@ can_activate(pcap_t* handle)
pcap_cleanup_live_common(handle);
return PCAP_ERROR;
}
handle->md.ifindex = ifr.ifr_ifindex;
handlep->ifindex = ifr.ifr_ifindex;
/* allocate butter */
handle->buffer = malloc(handle->bufsize);
@ -186,11 +194,11 @@ can_activate(pcap_t* handle)
/* Bind to the socket */
addr.can_family = AF_CAN;
addr.can_ifindex = handle->md.ifindex;
addr.can_ifindex = handlep->ifindex;
if( bind( handle->fd, (struct sockaddr*)&addr, sizeof(addr) ) < 0 )
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't attach to device %d %d:%s",
handle->md.ifindex, errno, strerror(errno));
handlep->ifindex, errno, strerror(errno));
pcap_cleanup_live_common(handle);
return PCAP_ERROR;
}
@ -199,7 +207,7 @@ can_activate(pcap_t* handle)
{
/* Monitor mode doesn't apply to CAN devices. */
pcap_cleanup_live_common(handle);
return PCAP_ERROR;
return PCAP_ERROR_RFMON_NOTSUP;
}
handle->selectable_fd = handle->fd;
@ -235,7 +243,7 @@ can_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
}
} while ((pkth.caplen == -1) && (errno == EINTR));
if (pkth.caplen < 0)
if (pkth.caplen == -1)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't receive packet %d:%s",
errno, strerror(errno));

View File

@ -38,12 +38,14 @@
#include <libusb-1.0/libusb.h>
#include "pcap-int.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <pthread.h>
#include "pcap-int.h"
#include "pcap-canusb-linux.h"
#define CANUSB_IFACE "canusb"
@ -73,25 +75,22 @@ struct CAN_Msg
uint8_t data[8];
};
struct canusb_t
{
/*
* Private data for capturing on Linux CANbus USB devices.
*/
struct pcap_canusb {
libusb_context *ctx;
libusb_device_handle *dev;
char *serial;
pthread_t worker;
int rdpipe, wrpipe;
volatile int* loop;
volatile int loop;
};
static struct canusb_t canusb;
static volatile int loop;
int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
libusb_context *fdctx;
libusb_device** devs;
unsigned char sernum[65];
unsigned char buf[96];
int cnt, i;
if (libusb_init(&fdctx) != 0) {
@ -118,7 +117,7 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
//It is!
libusb_device_handle *dh = NULL;
if (ret = libusb_open(devs[i],&dh) == 0)
if ((ret = libusb_open(devs[i],&dh)) == 0)
{
char dev_name[30];
char dev_descr[50];
@ -133,6 +132,7 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
if (pcap_add_if(alldevsp, dev_name, 0, dev_descr, err_str) < 0)
{
libusb_free_device_list(devs,1);
libusb_exit(fdctx);
return -1;
}
}
@ -145,7 +145,6 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
static libusb_device_handle* canusb_opendevice(struct libusb_context *ctx, char* devserial)
{
libusb_device_handle* dh;
libusb_device** devs;
unsigned char serial[65];
int cnt,i,n;
@ -169,7 +168,7 @@ static libusb_device_handle* canusb_opendevice(struct libusb_context *ctx, char*
n = libusb_get_string_descriptor_ascii(dh,desc.iSerialNumber,serial,64);
serial[n] = 0;
if ((devserial) && (strcmp(serial,devserial) != 0))
if ((devserial) && (strcmp((char *)serial,devserial) != 0))
{
libusb_close(dh);
continue;
@ -210,8 +209,7 @@ canusb_create(const char *device, char *ebuf, int *is_ours)
char *cpend;
long devnum;
pcap_t* p;
libusb_init(&canusb.ctx);
struct pcap_canusb *canusb;
/* Does this look like a DAG device? */
cp = strrchr(device, '/');
@ -240,11 +238,15 @@ canusb_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_canusb));
if (p == NULL)
return (NULL);
memset(&canusb, 0x00, sizeof(canusb));
canusb = p->priv;
canusb->ctx = NULL;
canusb->dev = NULL;
canusb->rdpipe = -1;
canusb->wrpipe = -1;
p->activate_op = canusb_activate;
@ -252,65 +254,54 @@ canusb_create(const char *device, char *ebuf, int *is_ours)
}
static void* canusb_capture_thread(struct canusb_t *canusb)
static void* canusb_capture_thread(void *arg)
{
struct libusb_context *ctx;
libusb_device_handle *dev;
int i, n;
struct pcap_canusb *canusb = arg;
int i;
struct
{
uint8_t rxsz, txsz;
} status;
char *serial;
libusb_init(&ctx);
serial = canusb->serial;
dev = canusb_opendevice(ctx, serial);
fcntl(canusb->wrpipe, F_SETFL, O_NONBLOCK);
while(*canusb->loop)
while(canusb->loop)
{
int sz, ret;
int sz;
struct CAN_Msg msg;
libusb_interrupt_transfer(dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
libusb_interrupt_transfer(canusb->dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
//HACK!!!!! -> drop buffered data, read new one by reading twice.
ret = libusb_interrupt_transfer(dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
libusb_interrupt_transfer(canusb->dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
for(i = 0; i<status.rxsz; i++)
{
libusb_bulk_transfer(dev, 0x85, (unsigned char*)&msg, sizeof(msg), &sz, 100);
n = write(canusb->wrpipe, &msg, sizeof(msg));
libusb_bulk_transfer(canusb->dev, 0x85, (unsigned char*)&msg, sizeof(msg), &sz, 100);
write(canusb->wrpipe, &msg, sizeof(msg));
}
}
libusb_close(dev);
libusb_exit(ctx);
return NULL;
}
static int canusb_startcapture(struct canusb_t* this)
static int canusb_startcapture(struct pcap_canusb* this)
{
int pipefd[2];
if (pipe(pipefd) == -1)
return -1;
canusb.rdpipe = pipefd[0];
canusb.wrpipe = pipefd[1];
canusb.loop = &loop;
this->rdpipe = pipefd[0];
this->wrpipe = pipefd[1];
loop = 1;
pthread_create(&this->worker, NULL, canusb_capture_thread, &canusb);
this->loop = 1;
pthread_create(&this->worker, NULL, canusb_capture_thread, this);
return canusb.rdpipe;
return this->rdpipe;
}
static void canusb_clearbufs(struct canusb_t* this)
static void canusb_clearbufs(struct pcap_canusb* this)
{
unsigned char cmd[16];
int al;
@ -326,22 +317,38 @@ static void canusb_clearbufs(struct canusb_t* this)
static void canusb_close(pcap_t* handle)
{
loop = 0;
pthread_join(canusb.worker, NULL);
struct pcap_canusb *canusb = handle->priv;
if (canusb.dev)
canusb->loop = 0;
pthread_join(canusb->worker, NULL);
if (canusb->dev)
{
libusb_close(canusb.dev);
canusb.dev = NULL;
libusb_close(canusb->dev);
canusb->dev = NULL;
}
if (canusb->ctx)
{
libusb_exit(canusb->ctx);
canusb->ctx = NULL;
}
}
static int canusb_activate(pcap_t* handle)
{
struct pcap_canusb *canusb = handle->priv;
char *serial;
if (libusb_init(&canusb->ctx) != 0) {
/*
* XXX - what causes this to fail?
*/
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "libusb_init() failed");
return PCAP_ERROR;
}
handle->read_op = canusb_read_linux;
handle->inject_op = canusb_inject_linux;
@ -359,18 +366,18 @@ static int canusb_activate(pcap_t* handle)
handle->set_datalink_op = NULL;
serial = handle->opt.source + strlen(CANUSB_IFACE);
canusb.serial = strdup(serial);
canusb.dev = canusb_opendevice(canusb.ctx,serial);
if (!canusb.dev)
canusb->dev = canusb_opendevice(canusb->ctx, serial);
if (!canusb->dev)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't open USB Device:");
libusb_exit(canusb->ctx);
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't open USB Device");
return PCAP_ERROR;
}
canusb_clearbufs(&canusb);
canusb_clearbufs(canusb);
handle->fd = canusb_startcapture(&canusb);
handle->fd = canusb_startcapture(canusb);
handle->selectable_fd = handle->fd;
return 0;
@ -383,8 +390,6 @@ static int
canusb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
static struct timeval firstpacket = { -1, -1};
int msgsent = 0;
int i = 0;
struct CAN_Msg msg;
struct pcap_pkthdr pkth;

View File

@ -41,6 +41,7 @@
#include "pcap-int.h"
#include "pcap/usb.h"
#include "pcap/nflog.h"
#include "pcap-common.h"
@ -897,7 +898,103 @@
*/
#define LINKTYPE_SCTP 248
#define LINKTYPE_MATCHING_MAX 248 /* highest value in the "matching" range */
/*
* USB packets, beginning with a USBPcap header.
*
* Requested by Tomasz Mon <desowin@gmail.com>
*/
#define LINKTYPE_USBPCAP 249
/*
* Schweitzer Engineering Laboratories "RTAC" product serial-line
* packets.
*
* Requested by Chris Bontje <chris_bontje@selinc.com>.
*/
#define DLT_RTAC_SERIAL 250
/*
* Bluetooth Low Energy air interface link-layer packets.
*
* Requested by Mike Kershaw <dragorn@kismetwireless.net>.
*/
#define LINKTYPE_BLUETOOTH_LE_LL 251
/*
* Link-layer header type for upper-protocol layer PDU saves from wireshark.
*
* the actual contents are determined by two TAGs stored with each
* packet:
* EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
* original packet.
*
* EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector
* that can make sense of the data stored.
*/
#define LINKTYPE_WIRESHARK_UPPER_PDU 252
/*
* Link-layer header type for the netlink protocol (nlmon devices).
*/
#define LINKTYPE_NETLINK 253
/*
* Bluetooth Linux Monitor headers for the BlueZ stack.
*/
#define LINKTYPE_BLUETOOTH_LINUX_MONITOR 254
/*
* Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as
* captured by Ubertooth.
*/
#define LINKTYPE_BLUETOOTH_BREDR_BB 255
/*
* Bluetooth Low Energy link layer packets, as captured by Ubertooth.
*/
#define LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR 256
/*
* PROFIBUS data link layer.
*/
#define LINKTYPE_PROFIBUS_DL 257
/*
* Apple's DLT_PKTAP headers.
*
* Sadly, the folks at Apple either had no clue that the DLT_USERn values
* are for internal use within an organization and partners only, and
* didn't know that the right way to get a link-layer header type is to
* ask tcpdump.org for one, or knew and didn't care, so they just
* used DLT_USER2, which causes problems for everything except for
* their version of tcpdump.
*
* So I'll just give them one; hopefully this will show up in a
* libpcap release in time for them to get this into 10.10 Big Sur
* or whatever Mavericks' successor is called. LINKTYPE_PKTAP
* will be 258 *even on OS X*; that is *intentional*, so that
* PKTAP files look the same on *all* OSes (different OSes can have
* different numerical values for a given DLT_, but *MUST NOT* have
* different values for what goes in a file, as files can be moved
* between OSes!).
*/
#define LINKTYPE_PKTAP 258
/*
* Ethernet packets preceded by a header giving the last 6 octets
* of the preamble specified by 802.3-2012 Clause 65, section
* 65.1.3.2 "Transmit".
*/
#define LINKTYPE_EPON 259
/*
* IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format"
* in the PICMG HPM.2 specification.
*/
#define LINKTYPE_IPMI_HPM_2 260
#define LINKTYPE_MATCHING_MAX 260 /* highest value in the "matching" range */
static struct linktype_map {
int dlt;
@ -970,13 +1067,20 @@ dlt_to_linktype(int dlt)
int i;
/*
* Map DLT_PFSYNC, whatever it might be, to LINKTYPE_PFSYNC.
* DLTs that, on some platforms, have values in the matching range
* but that *don't* have the same value as the corresponding
* LINKTYPE because, for some reason, not all OSes have the
* same value for that DLT (note that the DLT's value might be
* outside the matching range on some of those OSes).
*/
if (dlt == DLT_PFSYNC)
return (LINKTYPE_PFSYNC);
if (dlt == DLT_PKTAP)
return (LINKTYPE_PKTAP);
/*
* Map the values in the matching range.
* For all other values in the matching range, the DLT
* value is the same as the LINKTYPE value.
*/
if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX)
return (dlt);
@ -990,9 +1094,9 @@ dlt_to_linktype(int dlt)
}
/*
* If we don't have a mapping for this DLT_ code, return an
* If we don't have a mapping for this DLT, return an
* error; that means that this is a value with no corresponding
* LINKTYPE_ code, and we need to assign one.
* LINKTYPE, and we need to assign one.
*/
return (-1);
}
@ -1003,16 +1107,19 @@ linktype_to_dlt(int linktype)
int i;
/*
* Map LINKTYPE_PFSYNC to DLT_PFSYNC, whatever it might be.
* LINKTYPE_PFSYNC is in the matching range, to make sure
* it's as safe from reuse as we can arrange, so we do
* this test first.
* LINKTYPEs in the matching range that *don't*
* have the same value as the corresponding DLTs
* because, for some reason, not all OSes have the
* same value for that DLT.
*/
if (linktype == LINKTYPE_PFSYNC)
return (DLT_PFSYNC);
if (linktype == LINKTYPE_PKTAP)
return (DLT_PKTAP);
/*
* Map the values in the matching range.
* For all other values in the matching range, the LINKTYPE
* value is the same as the DLT value.
*/
if (linktype >= LINKTYPE_MATCHING_MIN &&
linktype <= LINKTYPE_MATCHING_MAX)
@ -1027,9 +1134,9 @@ linktype_to_dlt(int linktype)
}
/*
* If we don't have an entry for this link type, return
* the link type value; it may be a DLT_ value from an
* older version of libpcap.
* If we don't have an entry for this LINKTYPE, return
* the link type value; it may be a DLT from an older
* version of libpcap.
*/
return linktype;
}
@ -1040,10 +1147,10 @@ linktype_to_dlt(int linktype)
* memory-mapped buffer shared by the kernel).
*
* When reading a DLT_USB_LINUX or DLT_USB_LINUX_MMAPPED capture file,
* we need to convert it from the capturing host's byte order to
* the reading host's byte order.
* we need to convert it from the byte order of the host that wrote
* the file to this host's byte order.
*/
void
static void
swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
int header_len_64_bytes)
{
@ -1170,3 +1277,93 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
}
}
}
/*
* The DLT_NFLOG "packets" have a mixture of big-endian and host-byte-order
* data. They begin with a fixed-length header with big-endian fields,
* followed by a set of TLVs, where the type and length are in host
* byte order but the values are either big-endian or are a raw byte
* sequence that's the same regardless of the host's byte order.
*
* When reading a DLT_NFLOG capture file, we need to convert the type
* and length values from the byte order of the host that wrote the
* file to the byte order of this host.
*/
static void
swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
{
u_char *p = buf;
nflog_hdr_t *nfhdr = (nflog_hdr_t *)buf;
nflog_tlv_t *tlv;
u_int caplen = hdr->caplen;
u_int length = hdr->len;
u_int16_t size;
if (caplen < (int) sizeof(nflog_hdr_t) || length < (int) sizeof(nflog_hdr_t)) {
/* Not enough data to have any TLVs. */
return;
}
if (!(nfhdr->nflog_version) == 0) {
/* Unknown NFLOG version */
return;
}
length -= sizeof(nflog_hdr_t);
caplen -= sizeof(nflog_hdr_t);
p += sizeof(nflog_hdr_t);
while (caplen >= sizeof(nflog_tlv_t)) {
tlv = (nflog_tlv_t *) p;
/* Swap the type and length. */
tlv->tlv_type = SWAPSHORT(tlv->tlv_type);
tlv->tlv_length = SWAPSHORT(tlv->tlv_length);
/* Get the length of the TLV. */
size = tlv->tlv_length;
if (size % 4 != 0)
size += 4 - size % 4;
/* Is the TLV's length less than the minimum? */
if (size < sizeof(nflog_tlv_t)) {
/* Yes. Give up now. */
return;
}
/* Do we have enough data for the full TLV? */
if (caplen < size || length < size) {
/* No. */
return;
}
/* Skip over the TLV. */
length -= size;
caplen -= size;
p += size;
}
}
void
swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
{
/*
* Convert pseudo-headers from the byte order of
* the host on which the file was saved to our
* byte order, as necessary.
*/
switch (linktype) {
case DLT_USB_LINUX:
swap_linux_usb_header(hdr, data, 0);
break;
case DLT_USB_LINUX_MMAPPED:
swap_linux_usb_header(hdr, data, 1);
break;
case DLT_NFLOG:
swap_nflog_header(hdr, data);
break;
}
}

View File

@ -21,5 +21,5 @@ extern int dlt_to_linktype(int dlt);
extern int linktype_to_dlt(int linktype);
extern void swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
int header_len_64_bytes);
extern void swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr,
u_char *data);

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-config.1,v 1.1 2008-09-23 18:04:01 guy Exp $ (LBL)
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" All rights reserved.
@ -20,7 +18,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-CONFIG 1 "26 March 2009"
.TH PCAP-CONFIG 1 "22 May 2009"
.SH NAME
pcap-config \- write libpcap compiler and linker flags to standard output
.SH SYNOPSIS

View File

@ -15,11 +15,6 @@
* Stephen Donnelly <support@endace.com>
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.39 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -50,9 +45,12 @@ struct rtentry; /* declarations in <net/if.h> */
/*
* DAG devices have names beginning with "dag", followed by a number
* from 0 to MAXDAG.
* from 0 to DAG_MAX_BOARDS, then optionally a colon and a stream number
* from 0 to DAG_STREAM_MAX.
*/
#define MAXDAG 31
#ifndef DAG_MAX_BOARDS
#define DAG_MAX_BOARDS 32
#endif
#define ATM_CELL_SIZE 52
#define ATM_HDR_SIZE 4
@ -76,6 +74,27 @@ struct sunatm_hdr {
unsigned short vci; /* VCI */
};
/*
* Private data for capturing on DAG devices.
*/
struct pcap_dag {
struct pcap_stat stat;
#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 */
#else /* HAVE_DAG_STREAMS_API */
void *dag_mem_base; /* DAG card memory base address */
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 */
int dag_fcs_bits; /* Number of checksum bits from link layer */
int dag_offset_flags; /* Flags to pass to dag_offset(). */
int dag_stream; /* DAG stream number */
int dag_timeout; /* timeout specified to pcap_open_live.
* Same as in linux above, introduce
* generally? */
};
typedef struct pcap_dag_node {
struct pcap_dag_node *next;
pcap_t *p;
@ -124,13 +143,15 @@ delete_pcap_dag(pcap_t *p)
static void
dag_platform_cleanup(pcap_t *p)
{
struct pcap_dag *pd;
if (p != NULL) {
pd = p->priv;
#ifdef HAVE_DAG_STREAMS_API
if(dag_stop_stream(p->fd, p->md.dag_stream) < 0)
if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
if(dag_detach_stream(p->fd, p->md.dag_stream) < 0)
if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
if(dag_stop(p->fd) < 0)
@ -202,7 +223,7 @@ dag_erf_ext_header_count(uint8_t * erf, size_t len)
do {
/* sanity check we have enough bytes */
if ( len <= (24 + (hdr_num * 8)) )
if ( len < (24 + (hdr_num * 8)) )
return hdr_num;
/* get the header type */
@ -222,13 +243,14 @@ dag_erf_ext_header_count(uint8_t * erf, size_t len)
static int
dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_dag *pd = p->priv;
unsigned int processed = 0;
int flags = p->md.dag_offset_flags;
int flags = pd->dag_offset_flags;
unsigned int nonblocking = flags & DAGF_NONBLOCK;
unsigned int num_ext_hdr = 0;
/* Get the next bufferful of packets (if necessary). */
while (p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size) {
while (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size) {
/*
* Has "pcap_breakloop()" been called?
@ -255,23 +277,23 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* If non-block is specified it will return immediately. The user
* is then responsible for efficiency.
*/
if ( NULL == (p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, &(p->md.dag_mem_bottom))) ) {
if ( NULL == (pd->dag_mem_top = dag_advance_stream(p->fd, pd->dag_stream, &(pd->dag_mem_bottom))) ) {
return -1;
}
#else
/* dag_offset does not support timeouts */
p->md.dag_mem_top = dag_offset(p->fd, &(p->md.dag_mem_bottom), flags);
pd->dag_mem_top = dag_offset(p->fd, &(pd->dag_mem_bottom), flags);
#endif /* HAVE_DAG_STREAMS_API */
if (nonblocking && (p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size))
if (nonblocking && (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
{
/* Pcap is configured to process only available packets, and there aren't any, return immediately. */
return 0;
}
if(!nonblocking &&
p->md.dag_timeout &&
(p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size))
pd->dag_timeout &&
(pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
{
/* Blocking mode, but timeout set and no data has arrived, return anyway.*/
return 0;
@ -280,16 +302,16 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
/* Process the packets. */
while (p->md.dag_mem_top - p->md.dag_mem_bottom >= dag_record_size) {
while (pd->dag_mem_top - pd->dag_mem_bottom >= dag_record_size) {
unsigned short packet_len = 0;
int caplen = 0;
struct pcap_pkthdr pcap_header;
#ifdef HAVE_DAG_STREAMS_API
dag_record_t *header = (dag_record_t *)(p->md.dag_mem_bottom);
dag_record_t *header = (dag_record_t *)(pd->dag_mem_bottom);
#else
dag_record_t *header = (dag_record_t *)(p->md.dag_mem_base + p->md.dag_mem_bottom);
dag_record_t *header = (dag_record_t *)(pd->dag_mem_base + pd->dag_mem_bottom);
#endif /* HAVE_DAG_STREAMS_API */
u_char *dp = ((u_char *)header); /* + dag_record_size; */
@ -314,7 +336,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
strncpy(p->errbuf, "dag_read: record too small", PCAP_ERRBUF_SIZE);
return -1;
}
p->md.dag_mem_bottom += rlen;
pd->dag_mem_bottom += rlen;
/* Count lost packets. */
switch((header->type & 0x7f)) {
@ -330,10 +352,10 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
default:
if (header->lctr) {
if (p->md.stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
p->md.stat.ps_drop = UINT_MAX;
if (pd->stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
pd->stat.ps_drop = UINT_MAX;
} else {
p->md.stat.ps_drop += ntohs(header->lctr);
pd->stat.ps_drop += ntohs(header->lctr);
}
}
}
@ -441,7 +463,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_COLOR_ETH:
case TYPE_ETH:
packet_len = ntohs(header->wlen);
packet_len -= (p->md.dag_fcs_bits >> 3);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size - 2;
if (caplen > packet_len) {
caplen = packet_len;
@ -454,7 +476,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_COLOR_HDLC_POS:
case TYPE_HDLC_POS:
packet_len = ntohs(header->wlen);
packet_len -= (p->md.dag_fcs_bits >> 3);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size;
if (caplen > packet_len) {
caplen = packet_len;
@ -464,7 +486,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_COLOR_MC_HDLC_POS:
case TYPE_MC_HDLC:
packet_len = ntohs(header->wlen);
packet_len -= (p->md.dag_fcs_bits >> 3);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size - 4;
if (caplen > packet_len) {
caplen = packet_len;
@ -545,14 +567,14 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
pcap_header.len = packet_len;
/* Count the packet. */
p->md.stat.ps_recv++;
pd->stat.ps_recv++;
/* Call the user supplied callback function */
callback(user, &pcap_header, dp);
/* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
processed++;
if (processed == cnt && cnt > 0)
if (processed == cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
{
/* Reached the user-specified limit. */
return cnt;
@ -584,6 +606,7 @@ dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
*/
static int dag_activate(pcap_t* handle)
{
struct pcap_dag *handlep = handle->priv;
#if 0
char conf[30]; /* dag configure string */
#endif
@ -613,13 +636,13 @@ static int dag_activate(pcap_t* handle)
}
/* Parse input name to get dag device and stream number if provided */
if (dag_parse_name(device, newDev, strlen(device) + 16, &handle->md.dag_stream) < 0) {
if (dag_parse_name(device, newDev, strlen(device) + 16, &handlep->dag_stream) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s\n", pcap_strerror(errno));
goto fail;
}
device = newDev;
if (handle->md.dag_stream%2) {
if (handlep->dag_stream%2) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture\n");
goto fail;
}
@ -644,7 +667,7 @@ static int dag_activate(pcap_t* handle)
#ifdef HAVE_DAG_STREAMS_API
/* Open requested stream. Can fail if already locked or on error */
if (dag_attach_stream(handle->fd, handle->md.dag_stream, 0, 0) < 0) {
if (dag_attach_stream(handle->fd, handlep->dag_stream, 0, 0) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_attach_stream: %s\n", pcap_strerror(errno));
goto failclose;
}
@ -652,32 +675,39 @@ static int dag_activate(pcap_t* handle)
/* Set up default poll parameters for stream
* Can be overridden by pcap_set_nonblock()
*/
if (dag_get_stream_poll(handle->fd, handle->md.dag_stream,
if (dag_get_stream_poll(handle->fd, handlep->dag_stream,
&mindata, &maxwait, &poll) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
goto faildetach;
}
/* Amount of data to collect in Bytes before calling callbacks.
* Important for efficiency, but can introduce latency
* at low packet rates if to_ms not set!
*/
mindata = 65536;
if (handle->opt.immediate) {
/* Call callback immediately.
* XXX - is this the right way to handle this?
*/
mindata = 0;
} else {
/* Amount of data to collect in Bytes before calling callbacks.
* Important for efficiency, but can introduce latency
* at low packet rates if to_ms not set!
*/
mindata = 65536;
}
/* Obey md.timeout (was to_ms) if supplied. This is a good idea!
/* Obey opt.timeout (was to_ms) if supplied. This is a good idea!
* Recommend 10-100ms. Calls will time out even if no data arrived.
*/
maxwait.tv_sec = handle->md.timeout/1000;
maxwait.tv_usec = (handle->md.timeout%1000) * 1000;
maxwait.tv_sec = handle->opt.timeout/1000;
maxwait.tv_usec = (handle->opt.timeout%1000) * 1000;
if (dag_set_stream_poll(handle->fd, handle->md.dag_stream,
if (dag_set_stream_poll(handle->fd, handlep->dag_stream,
mindata, &maxwait, &poll) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
goto faildetach;
}
#else
if((handle->md.dag_mem_base = dag_mmap(handle->fd)) == MAP_FAILED) {
if((handlep->dag_mem_base = dag_mmap(handle->fd)) == MAP_FAILED) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,"dag_mmap %s: %s\n", device, pcap_strerror(errno));
goto failclose;
}
@ -707,7 +737,7 @@ static int dag_activate(pcap_t* handle)
#endif
#ifdef HAVE_DAG_STREAMS_API
if(dag_start_stream(handle->fd, handle->md.dag_stream) < 0) {
if(dag_start_stream(handle->fd, handlep->dag_stream) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s\n", device, pcap_strerror(errno));
goto faildetach;
}
@ -723,8 +753,8 @@ static int dag_activate(pcap_t* handle)
* initialized to zero on startup, it won't give you
* a compiler warning if you make this mistake!
*/
handle->md.dag_mem_bottom = 0;
handle->md.dag_mem_top = 0;
handlep->dag_mem_bottom = 0;
handlep->dag_mem_top = 0;
/*
* Find out how many FCS bits we should strip.
@ -733,7 +763,7 @@ static int dag_activate(pcap_t* handle)
daginf = dag_info(handle->fd);
if ((0x4200 == daginf->device_code) || (0x4230 == daginf->device_code)) {
/* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
handle->md.dag_fcs_bits = 0;
handlep->dag_fcs_bits = 0;
/* Note that no FCS will be supplied. */
handle->linktype_ext = LT_FCS_DATALINK_EXT(0);
@ -741,12 +771,12 @@ static int dag_activate(pcap_t* handle)
/*
* Start out assuming it's 32 bits.
*/
handle->md.dag_fcs_bits = 32;
handlep->dag_fcs_bits = 32;
/* Allow an environment variable to override. */
if ((s = getenv("ERF_FCS_BITS")) != NULL) {
if ((n = atoi(s)) == 0 || n == 16 || n == 32) {
handle->md.dag_fcs_bits = n;
handlep->dag_fcs_bits = n;
} else {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment\n", device, n);
@ -760,14 +790,14 @@ static int dag_activate(pcap_t* handle)
if ((s = getenv("ERF_DONT_STRIP_FCS")) != NULL) {
/* Yes. Note the number of bytes that will be
supplied. */
handle->linktype_ext = LT_FCS_DATALINK_EXT(handle->md.dag_fcs_bits/16);
handle->linktype_ext = LT_FCS_DATALINK_EXT(handlep->dag_fcs_bits/16);
/* And don't strip them. */
handle->md.dag_fcs_bits = 0;
handlep->dag_fcs_bits = 0;
}
}
handle->md.dag_timeout = handle->md.timeout;
handlep->dag_timeout = handle->opt.timeout;
handle->linktype = -1;
if (dag_get_datalink(handle) < 0)
@ -798,19 +828,19 @@ static int dag_activate(pcap_t* handle)
handle->setnonblock_op = dag_setnonblock;
handle->stats_op = dag_stats;
handle->cleanup_op = dag_platform_cleanup;
handle->md.stat.ps_drop = 0;
handle->md.stat.ps_recv = 0;
handle->md.stat.ps_ifdrop = 0;
handlep->stat.ps_drop = 0;
handlep->stat.ps_recv = 0;
handlep->stat.ps_ifdrop = 0;
return 0;
#ifdef HAVE_DAG_STREAMS_API
failstop:
if (dag_stop_stream(handle->fd, handle->md.dag_stream) < 0) {
if (dag_stop_stream(handle->fd, handlep->dag_stream) < 0) {
fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
}
faildetach:
if (dag_detach_stream(handle->fd, handle->md.dag_stream) < 0)
if (dag_detach_stream(handle->fd, handlep->dag_stream) < 0)
fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
failstop:
@ -838,6 +868,9 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
char *cpend;
long devnum;
pcap_t *p;
#ifdef HAVE_DAG_STREAMS_API
long stream = 0;
#endif
/* Does this look like a DAG device? */
cp = strrchr(device, '/');
@ -849,24 +882,37 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
*is_ours = 0;
return NULL;
}
/* Yes - is "dag" followed by a number from 0 to MAXDAG? */
/* Yes - is "dag" followed by a number from 0 to DAG_MAX_BOARDS-1 */
cp += 3;
devnum = strtol(cp, &cpend, 10);
#ifdef HAVE_DAG_STREAMS_API
if (*cpend == ':') {
/* Followed by a stream number. */
stream = strtol(++cpend, &cpend, 10);
}
#endif
if (cpend == cp || *cpend != '\0') {
/* Not followed by a number. */
*is_ours = 0;
return NULL;
}
if (devnum < 0 || devnum > MAXDAG) {
if (devnum < 0 || devnum >= DAG_MAX_BOARDS) {
/* Followed by a non-valid number. */
*is_ours = 0;
return NULL;
}
#ifdef HAVE_DAG_STREAMS_API
if (stream <0 || stream >= DAG_STREAM_MAX) {
/* Followed by a non-valid stream number. */
*is_ours = 0;
return NULL;
}
#endif
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_dag));
if (p == NULL)
return NULL;
@ -876,13 +922,15 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
static int
dag_stats(pcap_t *p, struct pcap_stat *ps) {
struct pcap_dag *pd = p->priv;
/* This needs to be filled out correctly. Hopefully a dagapi call will
provide all necessary information.
*/
/*p->md.stat.ps_recv = 0;*/
/*p->md.stat.ps_drop = 0;*/
/*pd->stat.ps_recv = 0;*/
/*pd->stat.ps_drop = 0;*/
*ps = p->md.stat;
*ps = pd->stat;
return 0;
}
@ -906,8 +954,8 @@ dag_findalldevs(pcap_if_t **devlistp, char *errbuf)
int dagstream;
int dagfd;
/* Try all the DAGs 0-MAXDAG */
for (c = 0; c <= MAXDAG; c++) {
/* Try all the DAGs 0-DAG_MAX_BOARDS */
for (c = 0; c < DAG_MAX_BOARDS; c++) {
snprintf(name, 12, "dag%d", c);
if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream))
{
@ -972,8 +1020,6 @@ dag_setfilter(pcap_t *p, struct bpf_program *fp)
if (install_bpf_program(p, fp) < 0)
return -1;
p->md.use_bpf = 0;
return (0);
}
@ -988,11 +1034,13 @@ dag_set_datalink(pcap_t *p, int dlt)
static int
dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{
struct pcap_dag *pd = p->priv;
/*
* Set non-blocking mode on the FD.
* XXX - is that necessary? If not, don't bother calling it,
* and have a "dag_getnonblock()" function that looks at
* "p->md.dag_offset_flags".
* "pd->dag_offset_flags".
*/
if (pcap_setnonblock_fd(p, nonblock, errbuf) < 0)
return (-1);
@ -1002,7 +1050,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
struct timeval maxwait;
struct timeval poll;
if (dag_get_stream_poll(p->fd, p->md.dag_stream,
if (dag_get_stream_poll(p->fd, pd->dag_stream,
&mindata, &maxwait, &poll) < 0) {
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
return -1;
@ -1017,7 +1065,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
else
mindata = 65536;
if (dag_set_stream_poll(p->fd, p->md.dag_stream,
if (dag_set_stream_poll(p->fd, pd->dag_stream,
mindata, &maxwait, &poll) < 0) {
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
return -1;
@ -1025,9 +1073,9 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
}
#endif /* HAVE_DAG_STREAMS_API */
if (nonblock) {
p->md.dag_offset_flags |= DAGF_NONBLOCK;
pd->dag_offset_flags |= DAGF_NONBLOCK;
} else {
p->md.dag_offset_flags &= ~DAGF_NONBLOCK;
pd->dag_offset_flags &= ~DAGF_NONBLOCK;
}
return (0);
}
@ -1035,6 +1083,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
static int
dag_get_datalink(pcap_t *p)
{
struct pcap_dag *pd = p->priv;
int index=0, dlt_index=0;
uint8_t types[255];
@ -1049,7 +1098,7 @@ dag_get_datalink(pcap_t *p)
#ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
/* Get list of possible ERF types for this card */
if (dag_get_stream_erf_types(p->fd, p->md.dag_stream, types, 255) < 0) {
if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
return (-1);
}

View File

@ -6,8 +6,6 @@
* at the same time as another type of device.
*
* Author: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.7 2008-04-04 19:37:45 guy Exp $ (LBL)
*/
pcap_t *dag_create(const char *, char *, int *);

279
contrib/libpcap/pcap-dbus.c Normal file
View File

@ -0,0 +1,279 @@
/*
* Copyright (c) 2012 Jakub Zawadzki
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* OWNER 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <dbus/dbus.h>
#include "pcap-int.h"
#include "pcap-dbus.h"
/*
* Private data for capturing on D-Bus.
*/
struct pcap_dbus {
DBusConnection *conn;
u_int packets_read; /* count of packets read */
};
static int
dbus_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
struct pcap_dbus *handlep = handle->priv;
struct pcap_pkthdr pkth;
DBusMessage *message;
char *raw_msg;
int raw_msg_len;
int count = 0;
message = dbus_connection_pop_message(handlep->conn);
while (!message) {
// XXX handle->opt.timeout = timeout_ms;
if (!dbus_connection_read_write(handlep->conn, 100)) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Connection closed");
return -1;
}
if (handle->break_loop) {
handle->break_loop = 0;
return -2;
}
message = dbus_connection_pop_message(handlep->conn);
}
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Disconnected");
return -1;
}
if (dbus_message_marshal(message, &raw_msg, &raw_msg_len)) {
pkth.caplen = pkth.len = raw_msg_len;
/* pkth.caplen = min (payload_len, handle->snapshot); */
gettimeofday(&pkth.ts, NULL);
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, (u_char *)raw_msg, pkth.len, pkth.caplen)) {
handlep->packets_read++;
callback(user, &pkth, (u_char *)raw_msg);
count++;
}
dbus_free(raw_msg);
}
return count;
}
static int
dbus_write(pcap_t *handle, const void *buf, size_t size)
{
/* XXX, not tested */
struct pcap_dbus *handlep = handle->priv;
DBusError error = DBUS_ERROR_INIT;
DBusMessage *msg;
if (!(msg = dbus_message_demarshal(buf, size, &error))) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dbus_message_demarshal() failed: %s", error.message);
dbus_error_free(&error);
return -1;
}
dbus_connection_send(handlep->conn, msg, NULL);
dbus_connection_flush(handlep->conn);
dbus_message_unref(msg);
return 0;
}
static int
dbus_stats(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_dbus *handlep = handle->priv;
stats->ps_recv = handlep->packets_read;
stats->ps_drop = 0;
stats->ps_ifdrop = 0;
return 0;
}
static void
dbus_cleanup(pcap_t *handle)
{
struct pcap_dbus *handlep = handle->priv;
dbus_connection_unref(handlep->conn);
pcap_cleanup_live_common(handle);
}
static int
dbus_activate(pcap_t *handle)
{
#define EAVESDROPPING_RULE "eavesdrop=true,"
static const char *rules[] = {
EAVESDROPPING_RULE "type='signal'",
EAVESDROPPING_RULE "type='method_call'",
EAVESDROPPING_RULE "type='method_return'",
EAVESDROPPING_RULE "type='error'",
};
#define N_RULES sizeof(rules)/sizeof(rules[0])
struct pcap_dbus *handlep = handle->priv;
const char *dev = handle->opt.source;
DBusError error = DBUS_ERROR_INIT;
int i;
if (strcmp(dev, "dbus-system") == 0) {
if (!(handlep->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Failed to get system bus: %s", error.message);
dbus_error_free(&error);
return PCAP_ERROR;
}
} else if (strcmp(dev, "dbus-session") == 0) {
if (!(handlep->conn = dbus_bus_get(DBUS_BUS_SESSION, &error))) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Failed to get session bus: %s", error.message);
dbus_error_free(&error);
return PCAP_ERROR;
}
} else if (strncmp(dev, "dbus://", 7) == 0) {
const char *addr = dev + 7;
if (!(handlep->conn = dbus_connection_open(addr, &error))) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Failed to open connection to: %s: %s", addr, error.message);
dbus_error_free(&error);
return PCAP_ERROR;
}
if (!dbus_bus_register(handlep->conn, &error)) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Failed to register bus %s: %s\n", addr, error.message);
dbus_error_free(&error);
return PCAP_ERROR;
}
} else {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't get bus address from %s", handle->opt.source);
return PCAP_ERROR;
}
/* Initialize some components of the pcap structure. */
handle->bufsize = 0;
handle->offset = 0;
handle->linktype = DLT_DBUS;
handle->read_op = dbus_read;
handle->inject_op = dbus_write;
handle->setfilter_op = install_bpf_program; /* XXX, later add support for dbus_bus_add_match() */
handle->setdirection_op = NULL;
handle->set_datalink_op = NULL; /* can't change data link type */
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
handle->stats_op = dbus_stats;
handle->selectable_fd = handle->fd = -1;
if (handle->opt.rfmon) {
/*
* Monitor mode doesn't apply to dbus connections.
*/
dbus_cleanup(handle);
return PCAP_ERROR_RFMON_NOTSUP;
}
/* dbus_connection_set_max_message_size(handlep->conn, handle->snapshot); */
if (handle->opt.buffer_size != 0)
dbus_connection_set_max_received_size(handlep->conn, handle->opt.buffer_size);
for (i = 0; i < N_RULES; i++) {
dbus_bus_add_match(handlep->conn, rules[i], &error);
if (dbus_error_is_set(&error)) {
dbus_error_free(&error);
/* try without eavesdrop */
dbus_bus_add_match(handlep->conn, rules[i] + strlen(EAVESDROPPING_RULE), &error);
if (dbus_error_is_set(&error)) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Failed to add bus match: %s\n", error.message);
dbus_error_free(&error);
dbus_cleanup(handle);
return PCAP_ERROR;
}
}
}
return 0;
}
pcap_t *
dbus_create(const char *device, char *ebuf, int *is_ours)
{
pcap_t *p;
if (strcmp(device, "dbus-system") &&
strcmp(device, "dbus-session") &&
strncmp(device, "dbus://", 7))
{
*is_ours = 0;
return NULL;
}
*is_ours = 1;
p = pcap_create_common(device, ebuf, sizeof (struct pcap_dbus));
if (p == NULL)
return (NULL);
p->activate_op = dbus_activate;
return (p);
}
int
dbus_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
if (pcap_add_if(alldevsp, "dbus-system", 0, "D-Bus system bus", err_str) < 0)
return -1;
if (pcap_add_if(alldevsp, "dbus-session", 0, "D-Bus session bus", err_str) < 0)
return -1;
return 0;
}

View File

@ -0,0 +1,2 @@
pcap_t *dbus_create(const char *, char *, int *);
int dbus_findalldevs(pcap_if_t **devlistp, char *errbuf);

View File

@ -68,11 +68,6 @@
* DL_HP_RAWDLS?
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.128 2008-12-02 16:20:23 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -245,6 +240,9 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
static int
pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
{
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd = p->priv;
#endif
int ret;
#if defined(DLIOCRAW)
@ -255,12 +253,12 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
return (-1);
}
#elif defined(DL_HP_RAWDLS)
if (p->send_fd < 0) {
if (pd->send_fd < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"send: Output FD couldn't be opened");
return (-1);
}
ret = dlrawdatareq(p->send_fd, buf, size);
ret = dlrawdatareq(pd->send_fd, buf, size);
if (ret == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
pcap_strerror(errno));
@ -321,16 +319,25 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
static void
pcap_cleanup_dlpi(pcap_t *p)
{
if (p->send_fd >= 0) {
close(p->send_fd);
p->send_fd = -1;
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd = p->priv;
if (pd->send_fd >= 0) {
close(pd->send_fd);
pd->send_fd = -1;
}
#endif
pcap_cleanup_live_common(p);
}
static int
pcap_activate_dlpi(pcap_t *p)
{
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd = p->priv;
#endif
int status = 0;
int retv;
register char *cp;
int ppa;
#ifdef HAVE_SOLARIS
@ -349,7 +356,6 @@ pcap_activate_dlpi(pcap_t *p)
#ifndef HAVE_DEV_DLPI
char dname2[100];
#endif
int status = PCAP_ERROR;
#ifdef HAVE_DEV_DLPI
/*
@ -387,6 +393,8 @@ pcap_activate_dlpi(pcap_t *p)
if ((p->fd = open(cp, O_RDWR)) < 0) {
if (errno == EPERM || errno == EACCES)
status = PCAP_ERROR_PERM_DENIED;
else
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: %s", cp, pcap_strerror(errno));
goto bad;
@ -398,13 +406,13 @@ pcap_activate_dlpi(pcap_t *p)
* receiving packets on the same descriptor - you need separate
* descriptors for sending and receiving, bound to different SAPs.
*
* If the open fails, we just leave -1 in "p->send_fd" and reject
* If the open fails, we just leave -1 in "pd->send_fd" and reject
* attempts to send packets, just as if, in pcap-bpf.c, we fail
* to open the BPF device for reading and writing, we just try
* to open it for reading only and, if that succeeds, just let
* the send attempts fail.
*/
p->send_fd = open(cp, O_RDWR);
pd->send_fd = open(cp, O_RDWR);
#endif
/*
@ -451,6 +459,8 @@ pcap_activate_dlpi(pcap_t *p)
if (errno != ENOENT) {
if (errno == EPERM || errno == EACCES)
status = PCAP_ERROR_PERM_DENIED;
else
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s", dname,
pcap_strerror(errno));
goto bad;
@ -487,6 +497,8 @@ pcap_activate_dlpi(pcap_t *p)
} else {
if (errno == EPERM || errno == EACCES)
status = PCAP_ERROR_PERM_DENIED;
else
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
dname2, pcap_strerror(errno));
}
@ -501,21 +513,28 @@ pcap_activate_dlpi(pcap_t *p)
** Attach if "style 2" provider
*/
if (dlinforeq(p->fd, p->errbuf) < 0 ||
dlinfoack(p->fd, (char *)buf, p->errbuf) < 0)
dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
}
infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
#ifdef HAVE_SOLARIS
if (infop->dl_mac_type == DL_IPATM)
isatm = 1;
#endif
if (infop->dl_provider_style == DL_STYLE2) {
status = dl_doattach(p->fd, ppa, p->errbuf);
if (status < 0)
retv = dl_doattach(p->fd, ppa, p->errbuf);
if (retv < 0) {
status = retv;
goto bad;
}
#ifdef DL_HP_RAWDLS
if (p->send_fd >= 0) {
if (dl_doattach(p->send_fd, ppa, p->errbuf) < 0)
if (pd->send_fd >= 0) {
retv = dl_doattach(pd->send_fd, ppa, p->errbuf);
if (retv < 0) {
status = retv;
goto bad;
}
}
#endif
}
@ -562,22 +581,28 @@ pcap_activate_dlpi(pcap_t *p)
*/
if ((dlbindreq(p->fd, 1537, p->errbuf) < 0 &&
dlbindreq(p->fd, 2, p->errbuf) < 0) ||
dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0)
dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
status = PCAP_ERROR;
goto bad;
}
#elif defined(DL_HP_RAWDLS)
/*
** HP-UX 10.0x and 10.1x.
*/
if (dl_dohpuxbind(p->fd, p->errbuf) < 0)
if (dl_dohpuxbind(p->fd, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
if (p->send_fd >= 0) {
}
if (pd->send_fd >= 0) {
/*
** XXX - if this fails, just close send_fd and
** set it to -1, so that you can't send but can
** still receive?
*/
if (dl_dohpuxbind(p->send_fd, p->errbuf) < 0)
if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
}
}
#else /* neither AIX nor HP-UX */
/*
@ -585,8 +610,10 @@ pcap_activate_dlpi(pcap_t *p)
** OS using DLPI.
**/
if (dlbindreq(p->fd, 0, p->errbuf) < 0 ||
dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0)
dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
status = PCAP_ERROR;
goto bad;
}
#endif /* AIX vs. HP-UX vs. other */
#endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
@ -599,6 +626,7 @@ pcap_activate_dlpi(pcap_t *p)
** help, and may break things.
*/
if (strioctl(p->fd, A_PROMISCON_REQ, 0, NULL) < 0) {
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"A_PROMISCON_REQ: %s", pcap_strerror(errno));
goto bad;
@ -609,10 +637,12 @@ pcap_activate_dlpi(pcap_t *p)
/*
** Enable promiscuous (not necessary on send FD)
*/
status = dlpromiscon(p, DL_PROMISC_PHYS);
if (status < 0) {
if (status == PCAP_ERROR_PERM_DENIED)
retv = dlpromiscon(p, DL_PROMISC_PHYS);
if (retv < 0) {
if (retv == PCAP_ERROR_PERM_DENIED)
status = PCAP_ERROR_PROMISC_PERM_DENIED;
else
status = retv;
goto bad;
}
@ -622,8 +652,8 @@ pcap_activate_dlpi(pcap_t *p)
** HP-UX or SINIX) (Not necessary on send FD)
*/
#if !defined(__hpux) && !defined(sinix)
status = dlpromiscon(p, DL_PROMISC_MULTI);
if (status < 0)
retv = dlpromiscon(p, DL_PROMISC_MULTI);
if (retv < 0)
status = PCAP_WARNING;
#endif
}
@ -643,16 +673,23 @@ pcap_activate_dlpi(pcap_t *p)
/* Everything else (except for SINIX) - always do this */
{
#endif
status = dlpromiscon(p, DL_PROMISC_SAP);
if (status < 0) {
/*
* Not fatal, since the DL_PROMISC_PHYS mode worked.
* Report it as a warning, however.
*/
if (p->opt.promisc)
retv = dlpromiscon(p, DL_PROMISC_SAP);
if (retv < 0) {
if (p->opt.promisc) {
/*
* Not fatal, since the DL_PROMISC_PHYS mode
* worked.
*
* Report it as a warning, however.
*/
status = PCAP_WARNING;
else
} else {
/*
* Fatal.
*/
status = retv;
goto bad;
}
}
}
#endif /* sinix */
@ -662,21 +699,25 @@ pcap_activate_dlpi(pcap_t *p)
** promiscuous options.
*/
#if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
if (dl_dohpuxbind(p->fd, p->errbuf) < 0)
if (dl_dohpuxbind(p->fd, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
}
/*
** We don't set promiscuous mode on the send FD, but we'll defer
** binding it anyway, just to keep the HP-UX 9/10.20 or later
** code together.
*/
if (p->send_fd >= 0) {
if (pd->send_fd >= 0) {
/*
** XXX - if this fails, just close send_fd and
** set it to -1, so that you can't send but can
** still receive?
*/
if (dl_dohpuxbind(p->send_fd, p->errbuf) < 0)
if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
}
}
#endif
@ -686,12 +727,16 @@ pcap_activate_dlpi(pcap_t *p)
** when sending packets.
*/
if (dlinforeq(p->fd, p->errbuf) < 0 ||
dlinfoack(p->fd, (char *)buf, p->errbuf) < 0)
dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
status = PCAP_ERROR;
goto bad;
}
infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
if (pcap_process_mactype(p, infop->dl_mac_type) != 0)
if (pcap_process_mactype(p, infop->dl_mac_type) != 0) {
status = PCAP_ERROR;
goto bad;
}
#ifdef DLIOCRAW
/*
@ -699,6 +744,7 @@ pcap_activate_dlpi(pcap_t *p)
** header.
*/
if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) {
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "DLIOCRAW: %s",
pcap_strerror(errno));
goto bad;
@ -729,28 +775,31 @@ pcap_activate_dlpi(pcap_t *p)
#endif
/* Push and configure bufmod. */
if (pcap_conf_bufmod(p, ss, p->md.timeout) != 0)
if (pcap_conf_bufmod(p, ss) != 0) {
status = PCAP_ERROR;
goto bad;
}
#endif
/*
** As the last operation flush the read side.
*/
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "FLUSHR: %s",
pcap_strerror(errno));
goto bad;
}
/* Allocate data buffer. */
if (pcap_alloc_databuf(p) != 0)
if (pcap_alloc_databuf(p) != 0) {
status = PCAP_ERROR;
goto bad;
/* Success - but perhaps with a warning */
if (status < 0)
status = 0;
}
/*
* Success.
*
* "p->fd" is an FD for a STREAMS device, so "select()" and
* "poll()" should work on it.
*/
@ -1696,12 +1745,18 @@ pcap_t *
pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd;
#endif
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_dlpi));
if (p == NULL)
return (NULL);
p->send_fd = -1; /* it hasn't been opened yet */
#ifdef DL_HP_RAWDLS
pd = p->priv;
pd->send_fd = -1; /* it hasn't been opened yet */
#endif
p->activate_op = pcap_activate_dlpi;
return (p);

View File

@ -4,8 +4,6 @@
*
* pcap-dos.c: Interface to PKTDRVR, NDIS2 and 32-bit pmode
* network drivers.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-dos.c,v 1.7 2008-04-22 17:16:30 guy Exp $ (LBL)
*/
#include <stdio.h>
@ -143,11 +141,19 @@ static struct device *get_device (int fd)
return handle_to_device [fd-1];
}
pcap_t *pcap_create (const char *device, char *ebuf)
/*
* Private data for capturing on MS-DOS.
*/
struct pcap_dos {
void (*wait_proc)(void); /* call proc while waiting */
struct pcap_stat stat;
};
pcap_t *pcap_create_interface (const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_dos));
if (p == NULL)
return (NULL);
@ -161,6 +167,8 @@ pcap_t *pcap_create (const char *device, char *ebuf)
*/
static int pcap_activate_dos (pcap_t *pcap)
{
struct pcap_dos *pcapd = pcap->priv;
if (pcap->opt.rfmon) {
/*
* No monitor mode on DOS.
@ -210,15 +218,16 @@ static int pcap_activate_dos (pcap_t *pcap)
static int
pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
{
struct pcap_dos *pd = p->priv;
struct pcap_pkthdr pcap;
struct timeval now, expiry;
struct timeval now, expiry = { 0,0 };
BYTE *rx_buf;
int rx_len = 0;
if (p->md.timeout > 0)
if (p->opt.timeout > 0)
{
gettimeofday2 (&now, NULL);
expiry.tv_usec = now.tv_usec + 1000UL * p->md.timeout;
expiry.tv_usec = now.tv_usec + 1000UL * p->opt.timeout;
expiry.tv_sec = now.tv_sec;
while (expiry.tv_usec >= 1000000L)
{
@ -287,10 +296,10 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
return (1);
}
/* If not to wait for a packet or pcap_close() called from
/* If not to wait for a packet or pcap_cleanup_dos() called from
* e.g. SIGINT handler, exit loop now.
*/
if (p->md.timeout <= 0 || (volatile int)p->fd <= 0)
if (p->opt.timeout <= 0 || (volatile int)p->fd <= 0)
break;
gettimeofday2 (&now, NULL);
@ -308,7 +317,7 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
if (rx_len < 0) /* receive error */
{
p->md.stat.ps_drop++;
pd->stat.ps_drop++;
#ifdef USE_32BIT_DRIVERS
if (pcap_pkt_debug > 1)
printk ("pkt-err %s\n", pktInfo.error);
@ -321,9 +330,10 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
static int
pcap_read_dos (pcap_t *p, int cnt, pcap_handler callback, u_char *data)
{
struct pcap_dos *pd = p->priv;
int rc, num = 0;
while (num <= cnt || (cnt < 0))
while (num <= cnt || PACKET_COUNT_IS_UNLIMITED(cnt))
{
if (p->fd <= 0)
return (-1);
@ -343,6 +353,7 @@ pcap_read_dos (pcap_t *p, int cnt, pcap_handler callback, u_char *data)
static int pcap_stats_dos (pcap_t *p, struct pcap_stat *ps)
{
struct net_device_stats *stats;
struct pcap_dos *pd;
struct device *dev = p ? get_device(p->fd) : NULL;
if (!dev)
@ -359,12 +370,13 @@ static int pcap_stats_dos (pcap_t *p, struct pcap_stat *ps)
FLUSHK();
p->md.stat.ps_recv = stats->rx_packets;
p->md.stat.ps_drop += stats->rx_missed_errors;
p->md.stat.ps_ifdrop = stats->rx_dropped + /* queue full */
pd = p->priv;
pd->stat.ps_recv = stats->rx_packets;
pd->stat.ps_drop += stats->rx_missed_errors;
pd->stat.ps_ifdrop = stats->rx_dropped + /* queue full */
stats->rx_errors; /* HW errors */
if (ps)
*ps = p->md.stat;
*ps = pd->stat;
return (0);
}
@ -428,10 +440,13 @@ u_long pcap_filter_packets (void)
*/
static void pcap_cleanup_dos (pcap_t *p)
{
struct pcap_dos *pd;
if (p && !exc_occured)
{
pd = p->priv;
if (pcap_stats(p,NULL) < 0)
p->md.stat.ps_drop = 0;
pd->stat.ps_drop = 0;
if (!get_device(p->fd))
return;
@ -590,10 +605,12 @@ void pcap_assert (const char *what, const char *file, unsigned line)
*/
void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait)
{
struct pcap_dos *pd;
if (p)
{
p->wait_proc = yield;
p->md.timeout = wait;
pd = p->priv;
pd->wait_proc = yield;
p->opt.timeout = wait;
}
}

View File

@ -1,8 +1,6 @@
/*
* Internal details for libpcap on DOS.
* 32-bit targets: djgpp, Pharlap or DOS4GW.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-dos.h,v 1.1 2004-12-18 08:52:10 guy Exp $ (LBL)
*/
#ifndef __PCAP_DOS_H

View File

@ -6,10 +6,6 @@
*
* Rayan Zachariassen, CA*Net
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-enet.c,v 1.9 2006-10-04 18:09:22 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-filter.manmisc.in,v 1.1 2008-10-21 07:33:01 guy Exp $ (LBL)
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" All rights reserved.
@ -20,7 +18,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-FILTER 7 "6 January 2008"
.TH PCAP-FILTER 7 "17 May 2013"
.SH NAME
pcap-filter \- packet filter syntax
.br
@ -332,8 +330,9 @@ The packet may contain, for example,
authentication header, routing header, or hop-by-hop option header,
between IPv6 header and TCP header.
The BPF code emitted by this primitive is complex and
cannot be optimized by the BPF optimizer code, so this can be somewhat
slow.
cannot be optimized by the BPF optimizer code, and is not supported by
filter engines in the kernel, so this can be somewhat slow, and may
cause more packets to be dropped.
.IP "\fBip protochain \fIprotocol\fR"
Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
.IP "\fBprotochain \fIprotocol\fR"
@ -453,6 +452,67 @@ True if the DECNET destination address is
.IP "\fBdecnet host \fIhost\fR"
True if either the DECNET source or destination address is
.IR host .
.IP \fBllc\fP
True if the packet has an 802.2 LLC header. This includes:
.IP
Ethernet packets with a length field rather than a type field that
aren't raw NetWare-over-802.3 packets;
.IP
IEEE 802.11 data packets;
.IP
Token Ring packets (no check is done for LLC frames);
.IP
FDDI packets (no check is done for LLC frames);
.IP
LLC-encapsulated ATM packets, for SunATM on Solaris.
.IP
.IP "\fBllc\fP \Fitype\fR"
True if the packet has an 802.2 LLC header and has the specified
.IR type .
.I type
can be one of:
.RS
.TP
\fBi\fR
Information (I) PDUs
.TP
\fBs\fR
Supervisory (S) PDUs
.TP
\fBu\fR
Unnumbered (U) PDUs
.TP
\fBrr\fR
Receiver Ready (RR) S PDUs
.TP
\fBrnr\fR
Receiver Not Ready (RNR) S PDUs
.TP
\fBrej\fR
Reject (REJ) S PDUs
.TP
\fBui\fR
Unnumbered Information (UI) U PDUs
.TP
\fBua\fR
Unnumbered Acknowledgment (UA) U PDUs
.TP
\fBdisc\fR
Disconnect (DISC) U PDUs
.TP
\fBsabme\fR
Set Asynchronous Balanced Mode Extended (SABME) U PDUs
.TP
\fBtest\fR
Test (TEST) U PDUs
.TP
\fBxid\fR
Exchange Identification (XID) U PDUs
.TP
\fBfrmr\fR
Frame Reject (FRMR) U PDUs
.RE
.IP "\fBifname \fIinterface\fR"
True if the packet was logged as coming from the specified interface (applies
only to packets logged by OpenBSD's or FreeBSD's
@ -487,7 +547,7 @@ name of an anchored ruleset (applies only to packets logged by OpenBSD's
or FreeBSD's
.BR pf (4)).
.IP "\fBruleset \fIname\fR"
Synonomous with the
Synonymous with the
.B rset
modifier.
.IP "\fBsrnr \fInum\fR"
@ -496,7 +556,7 @@ of an anchored ruleset (applies only to packets logged by OpenBSD's or
FreeBSD's
.BR pf (4)).
.IP "\fBsubrulenum \fInum\fR"
Synonomous with the
Synonymous with the
.B srnr
modifier.
.IP "\fBaction \fIact\fR"
@ -657,9 +717,11 @@ any outer label.
.IP \fBpppoed\fP
True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet
type 0x8863).
.IP \fBpppoes\fP
.IP "\fBpppoes \fI[session_id]\fR"
True if the packet is a PPP-over-Ethernet Session packet (Ethernet
type 0x8864).
If \fI[session_id]\fR is specified, only true if the packet has the specified
\fIsession_id\fR.
Note that the first \fBpppoes\fR keyword encountered in \fIexpression\fR
changes the decoding offsets for the remainder of \fIexpression\fR on
the assumption that the packet is a PPPoE session packet.
@ -667,10 +729,10 @@ the assumption that the packet is a PPPoE session packet.
For example:
.in +.5i
.nf
\fBpppoes && ip\fR
\fBpppoes 0x27 && ip\fR
.fi
.in -.5i
filters IPv4 protocols encapsulated in PPPoE.
filters IPv4 protocols encapsulated in PPPoE session id 0x27.
.IP "\fBiso proto \fIprotocol\fR"
True if the packet is an OSI packet of protocol type \fIprotocol\fP.
\fIProtocol\fP can be a number or one of the names
@ -702,9 +764,6 @@ on the assumption that the packet is either a LANE emulated Ethernet
packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the
tests are done under the assumption that the packet is an
LLC-encapsulated packet.
.IP \fBllc\fP
True if the packet is an ATM packet, for SunATM on Solaris, and is
an LLC-encapsulated packet.
.IP \fBoamf4s\fP
True if the packet is an ATM packet, for SunATM on Solaris, and is
a segment OAM F4 flow cell (VPI=0 & VCI=3).
@ -741,11 +800,17 @@ Release, or Release Done message.
True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =,
!=, and \fIexpr\fR is an arithmetic expression composed of integer
constants (expressed in standard C syntax), the normal binary operators
[+, -, *, /, &, |, <<, >>], a length operator, and special packet data
[+, -, *, /, %, &, |, ^, <<, >>], a length operator, and special packet data
accessors. Note that all comparisons are unsigned, so that, for example,
0x80000000 and 0xffffffff are > 0.
To access
data inside the packet, use the following syntax:
.IP
The % and ^ operators are currently only supported for filtering in the
kernel on Linux with 3.7 and later kernels; on all other systems, if
those operators are used, filtering will be done in user mode, which
will increase the overhead of capturing packets and may cause more
packets to be dropped.
.IP
To access data inside the packet, use the following syntax:
.in +.5i
.nf
\fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-filter.manmisc.in,v 1.1 2008-10-21 07:33:01 guy Exp $ (LBL)
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" All rights reserved.
@ -20,7 +18,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-FILTER @MAN_MISC_INFO@ "6 January 2008"
.TH PCAP-FILTER @MAN_MISC_INFO@ "17 May 2013"
.SH NAME
pcap-filter \- packet filter syntax
.br
@ -332,8 +330,9 @@ The packet may contain, for example,
authentication header, routing header, or hop-by-hop option header,
between IPv6 header and TCP header.
The BPF code emitted by this primitive is complex and
cannot be optimized by the BPF optimizer code, so this can be somewhat
slow.
cannot be optimized by the BPF optimizer code, and is not supported by
filter engines in the kernel, so this can be somewhat slow, and may
cause more packets to be dropped.
.IP "\fBip protochain \fIprotocol\fR"
Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
.IP "\fBprotochain \fIprotocol\fR"
@ -453,6 +452,67 @@ True if the DECNET destination address is
.IP "\fBdecnet host \fIhost\fR"
True if either the DECNET source or destination address is
.IR host .
.IP \fBllc\fP
True if the packet has an 802.2 LLC header. This includes:
.IP
Ethernet packets with a length field rather than a type field that
aren't raw NetWare-over-802.3 packets;
.IP
IEEE 802.11 data packets;
.IP
Token Ring packets (no check is done for LLC frames);
.IP
FDDI packets (no check is done for LLC frames);
.IP
LLC-encapsulated ATM packets, for SunATM on Solaris.
.IP
.IP "\fBllc\fP \Fitype\fR"
True if the packet has an 802.2 LLC header and has the specified
.IR type .
.I type
can be one of:
.RS
.TP
\fBi\fR
Information (I) PDUs
.TP
\fBs\fR
Supervisory (S) PDUs
.TP
\fBu\fR
Unnumbered (U) PDUs
.TP
\fBrr\fR
Receiver Ready (RR) S PDUs
.TP
\fBrnr\fR
Receiver Not Ready (RNR) S PDUs
.TP
\fBrej\fR
Reject (REJ) S PDUs
.TP
\fBui\fR
Unnumbered Information (UI) U PDUs
.TP
\fBua\fR
Unnumbered Acknowledgment (UA) U PDUs
.TP
\fBdisc\fR
Disconnect (DISC) U PDUs
.TP
\fBsabme\fR
Set Asynchronous Balanced Mode Extended (SABME) U PDUs
.TP
\fBtest\fR
Test (TEST) U PDUs
.TP
\fBxid\fR
Exchange Identification (XID) U PDUs
.TP
\fBfrmr\fR
Frame Reject (FRMR) U PDUs
.RE
.IP "\fBifname \fIinterface\fR"
True if the packet was logged as coming from the specified interface (applies
only to packets logged by OpenBSD's or FreeBSD's
@ -487,7 +547,7 @@ name of an anchored ruleset (applies only to packets logged by OpenBSD's
or FreeBSD's
.BR pf (4)).
.IP "\fBruleset \fIname\fR"
Synonomous with the
Synonymous with the
.B rset
modifier.
.IP "\fBsrnr \fInum\fR"
@ -496,7 +556,7 @@ of an anchored ruleset (applies only to packets logged by OpenBSD's or
FreeBSD's
.BR pf (4)).
.IP "\fBsubrulenum \fInum\fR"
Synonomous with the
Synonymous with the
.B srnr
modifier.
.IP "\fBaction \fIact\fR"
@ -657,9 +717,11 @@ any outer label.
.IP \fBpppoed\fP
True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet
type 0x8863).
.IP \fBpppoes\fP
.IP "\fBpppoes \fI[session_id]\fR"
True if the packet is a PPP-over-Ethernet Session packet (Ethernet
type 0x8864).
If \fI[session_id]\fR is specified, only true if the packet has the specified
\fIsession_id\fR.
Note that the first \fBpppoes\fR keyword encountered in \fIexpression\fR
changes the decoding offsets for the remainder of \fIexpression\fR on
the assumption that the packet is a PPPoE session packet.
@ -667,10 +729,10 @@ the assumption that the packet is a PPPoE session packet.
For example:
.in +.5i
.nf
\fBpppoes && ip\fR
\fBpppoes 0x27 && ip\fR
.fi
.in -.5i
filters IPv4 protocols encapsulated in PPPoE.
filters IPv4 protocols encapsulated in PPPoE session id 0x27.
.IP "\fBiso proto \fIprotocol\fR"
True if the packet is an OSI packet of protocol type \fIprotocol\fP.
\fIProtocol\fP can be a number or one of the names
@ -702,9 +764,6 @@ on the assumption that the packet is either a LANE emulated Ethernet
packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the
tests are done under the assumption that the packet is an
LLC-encapsulated packet.
.IP \fBllc\fP
True if the packet is an ATM packet, for SunATM on Solaris, and is
an LLC-encapsulated packet.
.IP \fBoamf4s\fP
True if the packet is an ATM packet, for SunATM on Solaris, and is
a segment OAM F4 flow cell (VPI=0 & VCI=3).
@ -741,11 +800,17 @@ Release, or Release Done message.
True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =,
!=, and \fIexpr\fR is an arithmetic expression composed of integer
constants (expressed in standard C syntax), the normal binary operators
[+, -, *, /, &, |, <<, >>], a length operator, and special packet data
[+, -, *, /, %, &, |, ^, <<, >>], a length operator, and special packet data
accessors. Note that all comparisons are unsigned, so that, for example,
0x80000000 and 0xffffffff are > 0.
To access
data inside the packet, use the following syntax:
.IP
The % and ^ operators are currently only supported for filtering in the
kernel on Linux with 3.7 and later kernels; on all other systems, if
those operators are used, filtering will be done in user mode, which
will increase the overhead of capturing packets and may cause more
packets to be dropped.
.IP
To access data inside the packet, use the following syntax:
.in +.5i
.nf
\fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR

View File

@ -29,8 +29,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.94 2008-09-16 00:20:23 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
@ -42,10 +40,6 @@
extern "C" {
#endif
#ifdef HAVE_LIBDLPI
#include <libdlpi.h>
#endif
#ifdef WIN32
#include <Packet32.h>
extern CRITICAL_SECTION g_PcapCompileCriticalSection;
@ -56,10 +50,6 @@ extern CRITICAL_SECTION g_PcapCompileCriticalSection;
#include <io.h>
#endif
#ifdef HAVE_SNF_API
#include <snf.h>
#endif
#if (defined(_MSC_VER) && (_MSC_VER <= 1200)) /* we are compiling with Visual Studio 6, that doesn't support the LL suffix*/
/*
@ -93,139 +83,39 @@ extern CRITICAL_SECTION g_PcapCompileCriticalSection;
#endif /* _MSC_VER */
/*
* Savefile
* Maximum snapshot length.
*
* Somewhat arbitrary, but chosen to be:
*
* 1) big enough for maximum-size Linux loopback packets (65549)
* and some USB packets captured with USBPcap:
*
* http://desowin.org/usbpcap/
*
* (> 131072, < 262144)
*
* and
*
* 2) small enough not to cause attempts to allocate huge amounts of
* memory; some applications might use the snapshot length in a
* savefile header to control the size of the buffer they allocate,
* so a size of, say, 2^31-1 might not work well.
*
* We don't enforce this in pcap_set_snaplen(), but we use it internally.
*/
typedef enum {
NOT_SWAPPED,
SWAPPED,
MAYBE_SWAPPED
} swapped_type_t;
/*
* Used when reading a savefile.
*/
struct pcap_sf {
FILE *rfile;
int (*next_packet_op)(pcap_t *, struct pcap_pkthdr *, u_char **);
int swapped;
size_t hdrsize;
swapped_type_t lengths_swapped;
int version_major;
int version_minor;
bpf_u_int32 ifcount; /* number of interfaces seen in this capture */
u_int tsresol; /* time stamp resolution */
u_int tsscale; /* scaling factor for resolution -> microseconds */
u_int64_t tsoffset; /* time stamp offset */
};
/*
* Used when doing a live capture.
*/
struct pcap_md {
struct pcap_stat stat;
/*XXX*/
int use_bpf; /* using kernel filter */
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 */
char *device; /* device name */
int timeout; /* timeout for buffering */
int must_do_on_close; /* stuff we must do when we close */
struct pcap *next; /* list of open pcaps that need stuff cleared on close */
#ifdef linux
int sock_packet; /* using Linux 2.0 compatible interface */
int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */
int ifindex; /* interface index of device we're bound to */
int lo_ifindex; /* interface index of the loopback device */
u_int packets_read; /* count of packets read with recvfrom() */
bpf_u_int32 oldmode; /* mode to restore when turning monitor mode off */
char *mondevice; /* mac80211 monitor device we created */
u_char *mmapbuf; /* memory-mapped region pointer */
size_t mmapbuflen; /* size of region */
int vlan_offset; /* offset at which to insert vlan tags; if -1, don't insert */
u_int tp_version; /* version of tpacket_hdr for mmaped ring */
u_int tp_hdrlen; /* hdrlen of tpacket_hdr for mmaped ring */
u_char *oneshot_buffer; /* buffer for copy of packet */
long proc_dropped; /* packets reported dropped by /proc/net/dev */
#endif /* linux */
#ifdef HAVE_DAG_API
#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 */
#else /* HAVE_DAG_STREAMS_API */
void *dag_mem_base; /* DAG card memory base address */
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 */
int dag_fcs_bits; /* Number of checksum bits from link layer */
int dag_offset_flags; /* Flags to pass to dag_offset(). */
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 */
#ifdef HAVE_SNF_API
snf_handle_t snf_handle; /* opaque device handle */
snf_ring_t snf_ring; /* opaque device ring handle */
int snf_timeout;
int snf_boardnum;
#endif /*HAVE_SNF_API*/
#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 */
};
/*
* Stuff to do when we close.
*/
#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 */
#define MAXIMUM_SNAPLEN 262144
struct pcap_opt {
int buffer_size;
char *source;
int timeout; /* timeout for buffering */
int buffer_size;
int promisc;
int rfmon;
int rfmon; /* monitor mode */
int immediate; /* immediate mode - deliver packets as soon as they arrive */
int tstamp_type;
int tstamp_precision;
};
/*
* 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
* Tru64 UNIX, and some versions of NetBSD pad FDDI packets to make everything
* line up on a nice boundary.
*/
#ifdef __NetBSD__
#include <sys/param.h> /* needed to declare __NetBSD_Version__ */
#endif
#if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000)
#define PCAP_FDDIPAD 3
#endif
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 *);
@ -240,10 +130,25 @@ typedef int (*stats_op_t)(pcap_t *, struct pcap_stat *);
typedef int (*setbuff_op_t)(pcap_t *, int);
typedef int (*setmode_op_t)(pcap_t *, int);
typedef int (*setmintocopy_op_t)(pcap_t *, int);
typedef Adapter *(*getadapter_op_t)(pcap_t *);
#endif
typedef void (*cleanup_op_t)(pcap_t *);
/*
* We put all the stuff used in the read code path at the beginning,
* to try to keep it together in the same cache line or lines.
*/
struct pcap {
/*
* Method to call to read packets on a live capture.
*/
read_op_t read_op;
/*
* Method to call to read to read packets from a savefile.
*/
int (*next_packet_op)(pcap_t *, struct pcap_pkthdr *, u_char **);
#ifdef WIN32
ADAPTER *adapter;
LPPACKET Packet;
@ -251,34 +156,8 @@ struct pcap {
#else
int fd;
int selectable_fd;
int send_fd;
#endif /* WIN32 */
#ifdef HAVE_LIBDLPI
dlpi_handle_t dlpi_hd;
#endif
int snapshot;
int linktype; /* Network linktype */
int linktype_ext; /* Extended information stored in the linktype field of a file */
int tzoff; /* timezone offset */
int offset; /* offset for proper alignment */
int activated; /* true if the capture is really started */
int oldstyle; /* if we're opening with pcap_open_live() */
int break_loop; /* flag set to force break from packet-reading loop */
#ifdef PCAP_FDDIPAD
int fddipad;
#endif
#ifdef MSDOS
void (*wait_proc)(void); /* call proc while waiting */
#endif
struct pcap_sf sf;
struct pcap_md md;
struct pcap_opt opt;
/*
* Read buffer.
*/
@ -287,6 +166,34 @@ struct pcap {
u_char *bp;
int cc;
int break_loop; /* flag set to force break from packet-reading loop */
void *priv; /* private data for methods */
int swapped;
FILE *rfile; /* null if live capture, non-null if savefile */
int fddipad;
struct pcap *next; /* list of open pcaps that need stuff cleared on close */
/*
* File version number; meaningful only for a savefile, but we
* keep it here so that apps that (mistakenly) ask for the
* version numbers will get the same zero values that they
* always did.
*/
int version_major;
int version_minor;
int snapshot;
int linktype; /* Network linktype */
int linktype_ext; /* Extended information stored in the linktype field of a file */
int tzoff; /* timezone offset */
int offset; /* offset for proper alignment */
int activated; /* true if the capture is really started */
int oldstyle; /* if we're opening with pcap_open_live() */
struct pcap_opt opt;
/*
* Place holder for pcap_next().
*/
@ -296,11 +203,25 @@ struct pcap {
pcap_direction_t direction;
/*
* Methods.
* Placeholder for filter code if bpf not in kernel.
*/
struct bpf_program fcode;
char errbuf[PCAP_ERRBUF_SIZE + 1];
int dlt_count;
u_int *dlt_list;
int tstamp_type_count;
u_int *tstamp_type_list;
int tstamp_precision_count;
u_int *tstamp_precision_list;
struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */
/*
* More methods.
*/
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;
@ -322,21 +243,9 @@ struct pcap {
setbuff_op_t setbuff_op;
setmode_op_t setmode_op;
setmintocopy_op_t setmintocopy_op;
getadapter_op_t getadapter_op;
#endif
cleanup_op_t cleanup_op;
/*
* Placeholder for filter code if bpf not in kernel.
*/
struct bpf_program fcode;
char errbuf[PCAP_ERRBUF_SIZE + 1];
int dlt_count;
u_int *dlt_list;
int tstamp_type_count;
u_int *tstamp_type_list;
struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */
};
/*
@ -377,7 +286,7 @@ struct pcap_timeval {
*
* Then supply the changes by forking the branch at
*
* https://github.com/mcr/libpcap/issues
* https://github.com/the-tcpdump-group/libpcap/issues
*
* and issuing a pull request, so that future versions of libpcap and
* programs that use it (such as tcpdump) will be able to read your new
@ -448,6 +357,12 @@ extern int snprintf (char *, size_t, const char *, ...);
extern int vsnprintf (char *, size_t, const char *, va_list ap);
#endif
/*
* Does the packet count argument to a module's read routine say
* "supply packets until you run out of packets"?
*/
#define PACKET_COUNT_IS_UNLIMITED(count) ((count) <= 0)
/*
* Routines that most pcap implementations can use for non-blocking mode.
*/
@ -468,7 +383,7 @@ int pcap_setnonblock_fd(pcap_t *p, int, char *);
* by pcap_create routines.
*/
pcap_t *pcap_create_interface(const char *, char *);
pcap_t *pcap_create_common(const char *, char *);
pcap_t *pcap_create_common(const char *, char *, size_t);
int pcap_do_addexit(pcap_t *);
void pcap_add_to_pcaps_to_close(pcap_t *);
void pcap_remove_from_pcaps_to_close(pcap_t *);
@ -493,11 +408,36 @@ int pcap_platform_finddevs(pcap_if_t **, char *);
int add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *,
size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *, size_t, char *);
int add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *dstaddr, size_t, char *errbuf);
int pcap_add_if(pcap_if_t **, const char *, u_int, const char *, char *);
struct sockaddr *dup_sockaddr(struct sockaddr *, size_t);
int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int,
const char *, char *);
/*
* Internal interfaces for "pcap_open_offline()".
*
* "pcap_open_offline_common()" allocates and fills in a pcap_t, for use
* by pcap_open_offline routines.
*
* "sf_cleanup()" closes the file handle associated with a pcap_t, if
* appropriate, and frees all data common to all modules for handling
* savefile types.
*/
pcap_t *pcap_open_offline_common(char *ebuf, size_t size);
void sf_cleanup(pcap_t *p);
/*
* Internal interfaces for both "pcap_create()" and routines that
* open savefiles.
*
* "pcap_oneshot()" is the standard one-shot callback for "pcap_next()"
* and "pcap_next_ex()".
*/
void pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);
#ifdef WIN32
char *pcap_win32strerror(void);
#endif

View File

@ -24,11 +24,6 @@
* Packet capture routines for DLPI using libdlpi under SunOS 5.11.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-libdlpi.c,v 1.6 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -52,7 +47,6 @@ static const char rcsid[] _U_ =
static int dlpromiscon(pcap_t *, bpf_u_int32);
static int pcap_read_libdlpi(pcap_t *, int, pcap_handler, u_char *);
static int pcap_inject_libdlpi(pcap_t *, const void *, size_t);
static void pcap_close_libdlpi(pcap_t *);
static void pcap_libdlpi_err(const char *, const char *, int, char *);
static void pcap_cleanup_libdlpi(pcap_t *);
@ -101,10 +95,11 @@ list_interfaces(const char *linkname, void *arg)
static int
pcap_activate_libdlpi(pcap_t *p)
{
struct pcap_dlpi *pd = p->priv;
int status = 0;
int retv;
dlpi_handle_t dh;
dlpi_info_t dlinfo;
int err = PCAP_ERROR;
/*
* Enable Solaris raw and passive DLPI extensions;
@ -114,35 +109,38 @@ pcap_activate_libdlpi(pcap_t *p)
retv = dlpi_open(p->opt.source, &dh, DLPI_RAW|DLPI_PASSIVE);
if (retv != DLPI_SUCCESS) {
if (retv == DLPI_ELINKNAMEINVAL || retv == DLPI_ENOLINK)
err = PCAP_ERROR_NO_SUCH_DEVICE;
status = PCAP_ERROR_NO_SUCH_DEVICE;
else if (retv == DL_SYSERR &&
(errno == EPERM || errno == EACCES))
err = PCAP_ERROR_PERM_DENIED;
status = PCAP_ERROR_PERM_DENIED;
else
status = PCAP_ERROR;
pcap_libdlpi_err(p->opt.source, "dlpi_open", retv,
p->errbuf);
return (err);
return (status);
}
p->dlpi_hd = dh;
pd->dlpi_hd = dh;
if (p->opt.rfmon) {
/*
* This device exists, but we don't support monitor mode
* any platforms that support DLPI.
*/
err = PCAP_ERROR_RFMON_NOTSUP;
status = PCAP_ERROR_RFMON_NOTSUP;
goto bad;
}
/* Bind with DLPI_ANY_SAP. */
if ((retv = dlpi_bind(p->dlpi_hd, DLPI_ANY_SAP, 0)) != DLPI_SUCCESS) {
if ((retv = dlpi_bind(pd->dlpi_hd, DLPI_ANY_SAP, 0)) != DLPI_SUCCESS) {
status = PCAP_ERROR;
pcap_libdlpi_err(p->opt.source, "dlpi_bind", retv, p->errbuf);
goto bad;
}
/* Enable promiscuous mode. */
if (p->opt.promisc) {
err = dlpromiscon(p, DL_PROMISC_PHYS);
if (err < 0) {
retv = dlpromiscon(p, DL_PROMISC_PHYS);
if (retv < 0) {
/*
* "You don't have permission to capture on
* this device" and "you don't have permission
@ -156,57 +154,71 @@ pcap_activate_libdlpi(pcap_t *p)
* XXX - you might have to capture in
* promiscuous mode to see outgoing packets.
*/
if (err == PCAP_ERROR_PERM_DENIED)
err = PCAP_ERROR_PROMISC_PERM_DENIED;
if (retv == PCAP_ERROR_PERM_DENIED)
status = PCAP_ERROR_PROMISC_PERM_DENIED;
else
status = retv;
goto bad;
}
} else {
/* Try to enable multicast. */
err = dlpromiscon(p, DL_PROMISC_MULTI);
if (err < 0)
retv = dlpromiscon(p, DL_PROMISC_MULTI);
if (retv < 0) {
status = retv;
goto bad;
}
}
/* Try to enable SAP promiscuity. */
err = dlpromiscon(p, DL_PROMISC_SAP);
if (err < 0) {
retv = dlpromiscon(p, DL_PROMISC_SAP);
if (retv < 0) {
/*
* Not fatal, since the DL_PROMISC_PHYS mode worked.
* Report it as a warning, however.
*/
if (p->opt.promisc)
err = PCAP_WARNING;
else
status = PCAP_WARNING;
else {
status = retv;
goto bad;
}
}
/* Determine link type. */
if ((retv = dlpi_info(p->dlpi_hd, &dlinfo, 0)) != DLPI_SUCCESS) {
if ((retv = dlpi_info(pd->dlpi_hd, &dlinfo, 0)) != DLPI_SUCCESS) {
status = PCAP_ERROR;
pcap_libdlpi_err(p->opt.source, "dlpi_info", retv, p->errbuf);
goto bad;
}
if (pcap_process_mactype(p, dlinfo.di_mactype) != 0)
if (pcap_process_mactype(p, dlinfo.di_mactype) != 0) {
status = PCAP_ERROR;
goto bad;
}
p->fd = dlpi_fd(p->dlpi_hd);
p->fd = dlpi_fd(pd->dlpi_hd);
/* Push and configure bufmod. */
if (pcap_conf_bufmod(p, p->snapshot, p->md.timeout) != 0)
if (pcap_conf_bufmod(p, p->snapshot) != 0) {
status = PCAP_ERROR;
goto bad;
}
/*
* Flush the read side.
*/
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
status = PCAP_ERROR;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "FLUSHR: %s",
pcap_strerror(errno));
goto bad;
}
/* Allocate data buffer. */
if (pcap_alloc_databuf(p) != 0)
if (pcap_alloc_databuf(p) != 0) {
status = PCAP_ERROR;
goto bad;
}
/*
* "p->fd" is a FD for a STREAMS device, so "select()" and
@ -224,10 +236,10 @@ pcap_activate_libdlpi(pcap_t *p)
p->stats_op = pcap_stats_dlpi;
p->cleanup_op = pcap_cleanup_libdlpi;
return (0);
return (status);
bad:
pcap_cleanup_libdlpi(p);
return (err);
return (status);
}
#define STRINGIFY(n) #n
@ -235,9 +247,11 @@ pcap_activate_libdlpi(pcap_t *p)
static int
dlpromiscon(pcap_t *p, bpf_u_int32 level)
{
struct pcap_dlpi *pd = p->priv;
int retv;
int err;
retv = dlpi_promiscon(p->dlpi_hd, level);
retv = dlpi_promiscon(pd->dlpi_hd, level);
if (retv != DLPI_SUCCESS) {
if (retv == DL_SYSERR &&
(errno == EPERM || errno == EACCES))
@ -299,6 +313,7 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
static int
pcap_read_libdlpi(pcap_t *p, int count, pcap_handler callback, u_char *user)
{
struct pcap_dlpi *pd = p->priv;
int len;
u_char *bufp;
size_t msglen;
@ -324,7 +339,7 @@ pcap_read_libdlpi(pcap_t *p, int count, pcap_handler callback, u_char *user)
msglen = p->bufsize;
bufp = p->buffer + p->offset;
retv = dlpi_recv(p->dlpi_hd, NULL, NULL, bufp,
retv = dlpi_recv(pd->dlpi_hd, NULL, NULL, bufp,
&msglen, -1, NULL);
if (retv != DLPI_SUCCESS) {
/*
@ -336,7 +351,7 @@ pcap_read_libdlpi(pcap_t *p, int count, pcap_handler callback, u_char *user)
len = 0;
continue;
}
pcap_libdlpi_err(dlpi_linkname(p->dlpi_hd),
pcap_libdlpi_err(dlpi_linkname(pd->dlpi_hd),
"dlpi_recv", retv, p->errbuf);
return (-1);
}
@ -350,11 +365,12 @@ pcap_read_libdlpi(pcap_t *p, int count, pcap_handler callback, u_char *user)
static int
pcap_inject_libdlpi(pcap_t *p, const void *buf, size_t size)
{
struct pcap_dlpi *pd = p->priv;
int retv;
retv = dlpi_send(p->dlpi_hd, NULL, 0, buf, size, NULL);
retv = dlpi_send(pd->dlpi_hd, NULL, 0, buf, size, NULL);
if (retv != DLPI_SUCCESS) {
pcap_libdlpi_err(dlpi_linkname(p->dlpi_hd), "dlpi_send", retv,
pcap_libdlpi_err(dlpi_linkname(pd->dlpi_hd), "dlpi_send", retv,
p->errbuf);
return (-1);
}
@ -372,9 +388,11 @@ pcap_inject_libdlpi(pcap_t *p, const void *buf, size_t size)
static void
pcap_cleanup_libdlpi(pcap_t *p)
{
if (p->dlpi_hd != NULL) {
dlpi_close(p->dlpi_hd);
p->dlpi_hd = NULL;
struct pcap_dlpi *pd = p->priv;
if (pd->dlpi_hd != NULL) {
dlpi_close(pd->dlpi_hd);
pd->dlpi_hd = NULL;
p->fd = -1;
}
pcap_cleanup_live_common(p);
@ -395,7 +413,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_dlpi));
if (p == NULL)
return (NULL);

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-linktype.manmisc.in,v 1.3 2008-10-27 22:52:30 guy Exp $
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" All rights reserved.
@ -20,7 +18,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-LINKTYPE 7 "23 October 2008"
.TH PCAP-LINKTYPE 7 "12 March 2011"
.SH NAME
pcap-linktype \- link-layer header types supported by libpcap
.SH DESCRIPTION

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-linktype.manmisc.in,v 1.3 2008-10-27 22:52:30 guy Exp $
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" All rights reserved.
@ -20,7 +18,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-LINKTYPE @MAN_MISC_INFO@ "23 October 2008"
.TH PCAP-LINKTYPE @MAN_MISC_INFO@ "12 March 2011"
.SH NAME
pcap-linktype \- link-layer header types supported by libpcap
.SH DESCRIPTION

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006-10-04 18:13:32 guy Exp $ (LBL)
*/
/*

View File

@ -74,11 +74,19 @@
typedef enum { OTHER = -1, NFLOG, NFQUEUE } nftype_t;
/*
* Private data for capturing on Linux netfilter sockets.
*/
struct pcap_netfilter {
u_int packets_read; /* count of packets read with recvfrom() */
};
static int nfqueue_send_verdict(const pcap_t *handle, u_int16_t group_id, u_int32_t id, u_int32_t verdict);
static int
netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
struct pcap_netfilter *handlep = handle->priv;
const unsigned char *buf;
int count = 0;
int len;
@ -109,12 +117,11 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
}
if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_ULOG &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFULNL_MSG_PACKET)
type = NFLOG;
if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_QUEUE &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFQNL_MSG_PACKET)
type = NFQUEUE;
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFULNL_MSG_PACKET)
type = NFLOG;
else if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_QUEUE &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFQNL_MSG_PACKET)
type = NFQUEUE;
if (type != OTHER) {
const unsigned char *payload = NULL;
@ -179,7 +186,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
{
handle->md.packets_read++;
handlep->packets_read++;
callback(user, &pkth, payload);
count++;
}
@ -211,7 +218,9 @@ netfilter_set_datalink(pcap_t *handle, int dlt)
static int
netfilter_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
stats->ps_recv = handle->md.packets_read;
struct pcap_netfilter *handlep = handle->priv;
stats->ps_recv = handlep->packets_read;
stats->ps_drop = 0;
stats->ps_ifdrop = 0;
return 0;
@ -471,7 +480,6 @@ netfilter_activate(pcap_t* handle)
handle->inject_op = netfilter_inject_linux;
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
handle->setdirection_op = NULL;
handle->set_datalink_op = NULL;
handle->set_datalink_op = netfilter_set_datalink;
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
@ -612,7 +620,7 @@ netfilter_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_netfilter));
if (p == NULL)
return (NULL);
@ -623,7 +631,6 @@ netfilter_create(const char *device, char *ebuf, int *is_ours)
int
netfilter_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
pcap_if_t *found_dev = *alldevsp;
int sock;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER);
@ -637,9 +644,9 @@ netfilter_findalldevs(pcap_if_t **alldevsp, char *err_str)
}
close(sock);
if (pcap_add_if(&found_dev, NFLOG_IFACE, 0, "Linux netfilter log (NFLOG) interface", err_str) < 0)
if (pcap_add_if(alldevsp, NFLOG_IFACE, 0, "Linux netfilter log (NFLOG) interface", err_str) < 0)
return -1;
if (pcap_add_if(&found_dev, NFQUEUE_IFACE, 0, "Linux netfilter queue (NFQUEUE) interface", err_str) < 0)
if (pcap_add_if(alldevsp, NFQUEUE_IFACE, 0, "Linux netfilter queue (NFQUEUE) interface", err_str) < 0)
return -1;
return 0;
}

View File

@ -18,10 +18,6 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.62 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -71,9 +67,17 @@ static const char rcsid[] _U_ =
/* Forwards */
static int nit_setflags(int, int, int, char *);
/*
* Private data for capturing on NIT devices.
*/
struct pcap_nit {
struct pcap_stat stat;
};
static int
pcap_stats_nit(pcap_t *p, struct pcap_stat *ps)
{
struct pcap_nit *pn = p->priv;
/*
* "ps_recv" counts packets handed to the filter, not packets
@ -91,13 +95,14 @@ pcap_stats_nit(pcap_t *p, struct pcap_stat *ps)
* kernel by libpcap or packets not yet read from libpcap by the
* application.
*/
*ps = p->md.stat;
*ps = pn->stat;
return (0);
}
static int
pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_nit *pn = p->priv;
register int cc, n;
register u_char *bp, *cp, *ep;
register struct nit_hdr *nh;
@ -156,7 +161,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case NIT_NOMBUF:
case NIT_NOCLUSTER:
case NIT_NOSPACE:
p->md.stat.ps_drop = nh->nh_dropped;
pn->stat.ps_drop = nh->nh_dropped;
continue;
case NIT_SEQNO:
@ -167,7 +172,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
"bad nit state %d", nh->nh_state);
return (-1);
}
++p->md.stat.ps_recv;
++pn->stat.ps_recv;
bp += ((sizeof(struct nit_hdr) + nh->nh_datalen +
sizeof(int) - 1) & ~(sizeof(int) - 1));
@ -180,7 +185,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
h.len = nh->nh_wirelen;
h.caplen = caplen;
(*callback)(user, &h, cp);
if (++n >= cnt && cnt > 0) {
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
p->cc = ep - bp;
p->bp = bp;
return (n);
@ -209,28 +214,42 @@ pcap_inject_nit(pcap_t *p, const void *buf, size_t size)
}
static int
nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
nit_setflags(pcap_t *p)
{
struct nit_ioc nioc;
memset(&nioc, 0, sizeof(nioc));
nioc.nioc_bufspace = BUFSPACE;
nioc.nioc_chunksize = CHUNKSIZE;
nioc.nioc_typetomatch = NT_ALLTYPES;
nioc.nioc_snaplen = p->snapshot;
nioc.nioc_bufalign = sizeof(int);
nioc.nioc_bufoffset = 0;
if (to_ms != 0) {
nioc.nioc_flags |= NF_TIMEOUT;
nioc.nioc_timeout.tv_sec = to_ms / 1000;
nioc.nioc_timeout.tv_usec = (to_ms * 1000) % 1000000;
if (p->opt.buffer_size != 0)
nioc.nioc_bufspace = p->opt.buffer_size;
else {
/* Default buffer size */
nioc.nioc_bufspace = BUFSPACE;
}
if (promisc)
if (p->opt.immediate) {
/*
* XXX - will this cause packets to be delivered immediately?
* XXX - given that this is for SunOS prior to 4.0, do
* we care?
*/
nioc.nioc_chunksize = 0;
} else
nioc.nioc_chunksize = CHUNKSIZE;
if (p->opt.timeout != 0) {
nioc.nioc_flags |= NF_TIMEOUT;
nioc.nioc_timeout.tv_sec = p->opt.timeout / 1000;
nioc.nioc_timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
}
if (p->opt.promisc)
nioc.nioc_flags |= NF_PROMISC;
if (ioctl(fd, SIOCSNIT, &nioc) < 0) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNIT: %s",
if (ioctl(p->fd, SIOCSNIT, &nioc) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "SIOCSNIT: %s",
pcap_strerror(errno));
return (-1);
}
@ -273,7 +292,8 @@ pcap_activate_nit(pcap_t *p)
"bind: %s: %s", snit.snit_ifname, pcap_strerror(errno));
goto bad;
}
nit_setflags(p->fd, p->opt.promisc, p->md.timeout, p->errbuf);
if (nit_setflags(p) < 0)
goto bad;
/*
* NIT supports only ethernets.
@ -332,7 +352,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_nit));
if (p == NULL)
return (NULL);

View File

@ -18,10 +18,6 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.22 2008-04-04 19:37:45 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"

View File

@ -22,11 +22,6 @@
* Extraction/creation by Jeffrey Mogul, DECWRL
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.97 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -74,6 +69,24 @@ struct rtentry;
#include "os-proto.h"
#endif
/*
* FDDI packets are padded to make everything line up on a nice boundary.
*/
#define PCAP_FDDIPAD 3
/*
* Private data for capturing on Ultrix and DEC OSF/1^WDigital UNIX^W^W
* Tru64 UNIX packetfilter devices.
*/
struct pcap_pf {
int filtering_in_kernel; /* using kernel filter */
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 */
};
static int pcap_setfilter_pf(pcap_t *, struct bpf_program *);
/*
@ -87,15 +100,14 @@ static int pcap_setfilter_pf(pcap_t *, struct bpf_program *);
static int
pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_pf *pf = pc->priv;
register u_char *p, *bp;
register int cc, n, buflen, inc;
register struct enstamp *sp;
#ifdef LBL_ALIGN
struct enstamp stamp;
#endif
#ifdef PCAP_FDDIPAD
register int pad;
#endif
again:
cc = pc->cc;
@ -126,9 +138,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
* Loop through each packet.
*/
n = 0;
#ifdef PCAP_FDDIPAD
pad = pc->fddipad;
#endif
while (cc > 0) {
/*
* Has "pcap_breakloop()" been called?
@ -177,42 +187,34 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
inc = ENALIGN(buflen + sp->ens_stamplen);
cc -= inc;
bp += inc;
pc->md.TotPkts++;
pc->md.TotDrops += sp->ens_dropped;
pc->md.TotMissed = sp->ens_ifoverflows;
if (pc->md.OrigMissed < 0)
pc->md.OrigMissed = pc->md.TotMissed;
pf->TotPkts++;
pf->TotDrops += sp->ens_dropped;
pf->TotMissed = sp->ens_ifoverflows;
if (pf->OrigMissed < 0)
pf->OrigMissed = pf->TotMissed;
/*
* Short-circuit evaluation: if using BPF filter
* in kernel, no need to do it now - we already know
* the packet passed the filter.
*
#ifdef PCAP_FDDIPAD
* Note: the filter code was generated assuming
* that pc->fddipad was the amount of padding
* before the header, as that's what's required
* in the kernel, so we run the filter before
* skipping that padding.
#endif
*/
if (pc->md.use_bpf ||
if (pf->filtering_in_kernel ||
bpf_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
struct pcap_pkthdr h;
pc->md.TotAccepted++;
pf->TotAccepted++;
h.ts = sp->ens_tstamp;
#ifdef PCAP_FDDIPAD
h.len = sp->ens_count - pad;
#else
h.len = sp->ens_count;
#endif
#ifdef PCAP_FDDIPAD
p += pad;
buflen -= pad;
#endif
h.caplen = buflen;
(*callback)(user, &h, p);
if (++n >= cnt && cnt > 0) {
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
pc->cc = cc;
pc->bp = bp;
return (n);
@ -240,6 +242,7 @@ pcap_inject_pf(pcap_t *p, const void *buf, size_t size)
static int
pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
{
struct pcap_pf *pf = p->priv;
/*
* If packet filtering is being done in the kernel:
@ -277,9 +280,9 @@ pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
* the kernel by libpcap, but they may include packets not
* yet read from libpcap by the application.
*/
ps->ps_recv = p->md.TotAccepted;
ps->ps_drop = p->md.TotDrops;
ps->ps_ifdrop = p->md.TotMissed - p->md.OrigMissed;
ps->ps_recv = pf->TotAccepted;
ps->ps_drop = pf->TotDrops;
ps->ps_ifdrop = pf->TotMissed - pf->OrigMissed;
return (0);
}
@ -294,6 +297,7 @@ pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
static int
pcap_activate_pf(pcap_t *p)
{
struct pcap_pf *pf = p->priv;
short enmode;
int backlog = -1; /* request the most */
struct enfilter Filter;
@ -327,8 +331,10 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
p->opt.source, pcap_strerror(errno));
goto bad;
}
p->md.OrigMissed = -1;
enmode = ENTSTAMP|ENBATCH|ENNONEXCL;
pf->OrigMissed = -1;
enmode = ENTSTAMP|ENNONEXCL;
if (!p->opt.immediate)
enmode |= ENBATCH;
if (p->opt.promisc)
enmode |= ENPROMISC;
if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
@ -436,7 +442,6 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
goto bad;
}
/* set truncation */
#ifdef PCAP_FDDIPAD
if (p->linktype == DLT_FDDI) {
p->fddipad = PCAP_FDDIPAD;
@ -444,7 +449,6 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
p->snapshot += PCAP_FDDIPAD;
} else
p->fddipad = 0;
#endif
if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&p->snapshot) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCTRUNCATE: %s",
pcap_strerror(errno));
@ -460,10 +464,10 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
goto bad;
}
if (p->md.timeout != 0) {
if (p->opt.timeout != 0) {
struct timeval timeout;
timeout.tv_sec = p->md.timeout / 1000;
timeout.tv_usec = (p->md.timeout * 1000) % 1000000;
timeout.tv_sec = p->opt.timeout / 1000;
timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSRTIMEOUT: %s",
pcap_strerror(errno));
@ -503,7 +507,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_pf));
if (p == NULL)
return (NULL);
@ -520,6 +524,7 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
static int
pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
{
struct pcap_pf *pf = p->priv;
struct bpf_version bv;
/*
@ -561,7 +566,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
* a window to annoy the user.
*/
fprintf(stderr, "tcpdump: Using kernel BPF filter\n");
p->md.use_bpf = 1;
pf->filtering_in_kernel = 1;
/*
* Discard any previously-received packets,
@ -599,6 +604,6 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
* a warning of some sort.
*/
fprintf(stderr, "tcpdump: Filtering in user process\n");
p->md.use_bpf = 0;
pf->filtering_in_kernel = 0;
return (0);
}

View File

@ -1,6 +1,3 @@
'\" t
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-savefile.manfile.in,v 1.2 2008-10-24 07:33:50 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\"
@ -20,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-SAVEFILE 5 "21 October 2008"
.TH PCAP-SAVEFILE 5 "29 July 2013"
.SH NAME
pcap-savefile \- libpcap savefile format
.SH DESCRIPTION
@ -55,16 +52,24 @@ Link-layer header type
.RE
.PP
All fields in the per-file header are in the byte order of the host
writing the file. The first field in the per-file header is a 4-byte
magic number, with the value 0xa1b2c3d4. The magic number, when read by
a host with the same byte order as the host that wrote the file, will
have the value 0xa1b2c3d4, and, when read by a host with the opposite
byte order as the host that wrote the file, will have the value
writing the file. Normally, the first field in the per-file header is a
4-byte magic number, with the value 0xa1b2c3d4. The magic number, when
read by a host with the same byte order as the host that wrote the file,
will have the value 0xa1b2c3d4, and, when read by a host with the
opposite byte order as the host that wrote the file, will have the value
0xd4c3b2a1. That allows software reading the file to determine whether
the byte order of the host that wrote the file is the same as the byte
order of the host on which the file is being read, and thus whether the
values in the per-file and per-packet headers need to be byte-swapped.
.PP
If the magic number has the value 0xa1b23c4d (with the two nibbles of
the two lower-order bytes of the magic number swapped), which would be
read as 0xa1b23c4d by a host with the same byte order as the host that
wrote the file and as 0x4d3cb2a1 by a host with the opposite byte order
as the host that wrote the file, the file format is the same as for
regular files, except that the time stamps for packets are given in
seconds and nanoseconds rather than seconds and microseconds.
.PP
Following this are:
.IP
A 2-byte file format major version number; the current version number is
@ -104,7 +109,7 @@ box;
c.
Time stamp, seconds value
_
Time stamp, microseconds value
Time stamp, microseconds or nanoseconds value
_
Length of captured packet data
_
@ -117,11 +122,12 @@ writing the file. The per-packet header begins with a time stamp giving
the approximate time the packet was captured; the time stamp consists of
a 4-byte value, giving the time in seconds since January 1, 1970,
00:00:00 UTC, followed by a 4-byte value, giving the time in
microseconds since that second. Following that are a 4-byte value
giving the number of bytes of captured data that follow the per-packet
header and a 4-byte value giving the number of bytes that would have
been present had the packet not been truncated by the snapshot length.
The two lengths will be equal if the number of bytes of packet data are
less than or equal to the snapshot length.
microseconds or nanoseconds since that second, depending on the magic
number in the file header. Following that are a 4-byte value giving the
number of bytes of captured data that follow the per-packet header and a
4-byte value giving the number of bytes that would have been present had
the packet not been truncated by the snapshot length. The two lengths
will be equal if the number of bytes of packet data are less than or
equal to the snapshot length.
.SH SEE ALSO
pcap(3PCAP), pcap-linktype(7)

View File

@ -1,6 +1,3 @@
'\" t
.\" @(#) $Header: /tcpdump/master/libpcap/pcap-savefile.manfile.in,v 1.2 2008-10-24 07:33:50 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\"
@ -20,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-SAVEFILE @MAN_FILE_FORMATS@ "21 October 2008"
.TH PCAP-SAVEFILE @MAN_FILE_FORMATS@ "29 July 2013"
.SH NAME
pcap-savefile \- libpcap savefile format
.SH DESCRIPTION
@ -55,16 +52,24 @@ Link-layer header type
.RE
.PP
All fields in the per-file header are in the byte order of the host
writing the file. The first field in the per-file header is a 4-byte
magic number, with the value 0xa1b2c3d4. The magic number, when read by
a host with the same byte order as the host that wrote the file, will
have the value 0xa1b2c3d4, and, when read by a host with the opposite
byte order as the host that wrote the file, will have the value
writing the file. Normally, the first field in the per-file header is a
4-byte magic number, with the value 0xa1b2c3d4. The magic number, when
read by a host with the same byte order as the host that wrote the file,
will have the value 0xa1b2c3d4, and, when read by a host with the
opposite byte order as the host that wrote the file, will have the value
0xd4c3b2a1. That allows software reading the file to determine whether
the byte order of the host that wrote the file is the same as the byte
order of the host on which the file is being read, and thus whether the
values in the per-file and per-packet headers need to be byte-swapped.
.PP
If the magic number has the value 0xa1b23c4d (with the two nibbles of
the two lower-order bytes of the magic number swapped), which would be
read as 0xa1b23c4d by a host with the same byte order as the host that
wrote the file and as 0x4d3cb2a1 by a host with the opposite byte order
as the host that wrote the file, the file format is the same as for
regular files, except that the time stamps for packets are given in
seconds and nanoseconds rather than seconds and microseconds.
.PP
Following this are:
.IP
A 2-byte file format major version number; the current version number is
@ -104,7 +109,7 @@ box;
c.
Time stamp, seconds value
_
Time stamp, microseconds value
Time stamp, microseconds or nanoseconds value
_
Length of captured packet data
_
@ -117,11 +122,12 @@ writing the file. The per-packet header begins with a time stamp giving
the approximate time the packet was captured; the time stamp consists of
a 4-byte value, giving the time in seconds since January 1, 1970,
00:00:00 UTC, followed by a 4-byte value, giving the time in
microseconds since that second. Following that are a 4-byte value
giving the number of bytes of captured data that follow the per-packet
header and a 4-byte value giving the number of bytes that would have
been present had the packet not been truncated by the snapshot length.
The two lengths will be equal if the number of bytes of packet data are
less than or equal to the snapshot length.
microseconds or nanoseconds since that second, depending on the magic
number in the file header. Following that are a 4-byte value giving the
number of bytes of captured data that follow the per-packet header and a
4-byte value giving the number of bytes that would have been present had
the packet not been truncated by the snapshot length. The two lengths
will be equal if the number of bytes of packet data are less than or
equal to the snapshot length.
.SH SEE ALSO
pcap(3PCAP), pcap-linktype(@MAN_MISC_INFO@)

View File

@ -14,11 +14,6 @@
* (+961 3 485243)
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-septel.c,v 1.4 2008-04-14 20:40:58 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -50,6 +45,13 @@ static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
static int septel_stats(pcap_t *p, struct pcap_stat *ps);
static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
/*
* Private data for capturing on Septel devices.
*/
struct pcap_septel {
struct pcap_stat stat;
}
/*
* Read at most max_packets from the capture queue and call the callback
* for each of them. Returns the number of packets handled, -1 if an
@ -57,6 +59,7 @@ static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
*/
static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) {
struct pcap_septel *ps = p->priv;
HDR *h;
MSG *m;
int processed = 0 ;
@ -154,7 +157,7 @@ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
pcap_header.len = packet_len;
/* Count the packet. */
p->md.stat.ps_recv++;
ps->stat.ps_recv++;
/* Call the user supplied callback function */
callback(user, &pcap_header, dp);
@ -229,7 +232,7 @@ pcap_t *septel_create(const char *device, char *ebuf, int *is_ours) {
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_septel));
if (p == NULL)
return NULL;
@ -238,10 +241,11 @@ pcap_t *septel_create(const char *device, char *ebuf, int *is_ours) {
}
static int septel_stats(pcap_t *p, struct pcap_stat *ps) {
/*p->md.stat.ps_recv = 0;*/
/*p->md.stat.ps_drop = 0;*/
struct pcap_septel *handlep = p->priv;
/*handlep->stat.ps_recv = 0;*/
/*handlep->stat.ps_drop = 0;*/
*ps = p->md.stat;
*ps = handlep->stat;
return 0;
}
@ -250,13 +254,8 @@ static int septel_stats(pcap_t *p, struct pcap_stat *ps) {
int
septel_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
unsigned char *p;
const char description[512]= "Intel/Septel device";
char name[512]="septel" ;
int ret = 0;
pcap_add_if(devlistp,name,0,description,errbuf);
return (ret);
return (pcap_add_if(devlistp,"septel",0,
"Intel/Septel device",errbuf));
}
@ -282,8 +281,6 @@ static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
return -1;
}
p->md.use_bpf = 0;
return (0);
}
@ -291,5 +288,6 @@ static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
static int
septel_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{
return (0);
fprintf(errbuf, PCAP_ERRBUF_SIZE, "Non-blocking mode not supported on Septel devices");
return (-1);
}

View File

@ -7,8 +7,6 @@
*
* Authors: Gilbert HOYEK (gil_hoyek@hotmail.com), Elias M. KHOURY
* (+961 3 485343);
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-septel.h,v 1.2 2008-04-04 19:37:45 guy Exp $
*/
pcap_t *septel_create(const char *device, char *ebuf, int *is_ours);

View File

@ -24,8 +24,6 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* $Id: pcap-sita.c */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -55,40 +53,37 @@
#define LIVE 1
typedef struct iface {
struct iface *next; /* a pointer to the next interface */
char *name; /* this interface's name on Wireshark */
char *IOPname; /* this interface's name on an IOP */
uint32_t iftype; /* the type of interface (DLT values) */
struct iface *next; /* a pointer to the next interface */
char *name; /* this interface's name */
char *IOPname; /* this interface's name on an IOP */
uint32_t iftype; /* the type of interface (DLT values) */
} iface_t;
typedef struct unit {
char *ip; /* this unit's IP address (as extracted from /etc/hosts) */
int fd; /* the connection to this unit (if it exists) */
int find_fd; /* a big kludge to avoid my programming limitations since I could have this unit open for findalldevs purposes */
int first_time; /* 0 = just opened via acn_open_live(), ie. the first time, NZ = nth time */
struct sockaddr_in *serv_addr; /* the address control block for comms to this unit */
int chassis;
int geoslot;
iface_t *iface; /* a pointer to a linked list of interface structures */
char *imsg; /* a pointer to an inbound message */
int len; /* the current size of the inbound message */
char *ip; /* this unit's IP address (as extracted from /etc/hosts) */
int fd; /* the connection to this unit (if it exists) */
int find_fd; /* a big kludge to avoid my programming limitations since I could have this unit open for findalldevs purposes */
int first_time; /* 0 = just opened via acn_open_live(), ie. the first time, NZ = nth time */
struct sockaddr_in *serv_addr; /* the address control block for comms to this unit */
int chassis;
int geoslot;
iface_t *iface; /* a pointer to a linked list of interface structures */
char *imsg; /* a pointer to an inbound message */
int len; /* the current size of the inbound message */
} unit_t;
static char *errorString;
static unit_t units[MAX_CHASSIS+1][MAX_GEOSLOT+1]; /* we use indexes of 1 through 8, but we reserve/waste index 0 */
static fd_set readfds; /* a place to store the file descriptors for the connections to the IOPs */
static fd_set working_set;
static int max_fs;
static char static_buf[32];
static fd_set readfds; /* a place to store the file descriptors for the connections to the IOPs */
static int max_fs;
pcap_if_t *acn_if_list; /* pcap's list of available interfaces */
pcap_if_t *acn_if_list; /* pcap's list of available interfaces */
static void dump_interface_list(void) {
pcap_if_t *iff;
pcap_addr_t *addr;
int longest_name_len = 0;
int longest_name_len = 0;
char *n, *d, *f;
int if_number = 0;
int if_number = 0;
iff = acn_if_list;
while (iff) {
@ -405,18 +400,16 @@ static void acn_freealldevs(void) {
}
}
static char *nonUnified_port_num(unit_t *u, int IOPportnum) {
static void nonUnified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u) {
sprintf(static_buf, "%d_%d", u->chassis, u->geoslot);
return static_buf;
snprintf(buf, bufsize, "%s_%d_%d", proto, u->chassis, u->geoslot);
}
static char *unified_port_num(unit_t *u, int IOPportnum) {
static void unified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u, int IOPportnum) {
int portnum;
portnum = ((u->chassis - 1) * 64) + ((u->geoslot - 1) * 8) + IOPportnum + 1;
sprintf(static_buf, "%d", portnum);
return static_buf;
snprintf(buf, bufsize, "%s_%d", proto, portnum);
}
static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 iftype) {
@ -448,24 +441,38 @@ static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 if
if (strncmp(IOPname, "lo", 2) == 0) {
IOPportnum = atoi(&IOPname[2]);
switch (iftype) {
case DLT_EN10MB: proto = "lo"; port = nonUnified_port_num(u, IOPportnum); break;
default: proto = "???"; port = unified_port_num(u, IOPportnum); break;
case DLT_EN10MB:
nonUnified_IOP_port_name(buf, sizeof buf, "lo", u);
break;
default:
unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
break;
}
} else if (strncmp(IOPname, "eth", 3) == 0) {
IOPportnum = atoi(&IOPname[3]);
switch (iftype) {
case DLT_EN10MB: proto = "eth"; port = nonUnified_port_num(u, IOPportnum); break;
default: proto = "???"; port = unified_port_num(u, IOPportnum); break;
case DLT_EN10MB:
nonUnified_IOP_port_name(buf, sizeof buf, "eth", u);
break;
default:
unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
break;
}
} else if (strncmp(IOPname, "wan", 3) == 0) {
IOPportnum = atoi(&IOPname[3]);
switch (iftype) {
case DLT_SITA: proto = "wan"; port = unified_port_num(u, IOPportnum); break;
default: proto = "???"; port = unified_port_num(u, IOPportnum); break;
case DLT_SITA:
unified_IOP_port_name(buf, sizeof buf, "wan", u, IOPportnum);
break;
default:
unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
break;
}
} else {
fprintf(stderr, "Error... invalid IOP name %s\n", IOPname);
return NULL;
}
sprintf(buf, "%s_%s", proto, port); /* compose the user's name for that IOP port name */
name = malloc(strlen(buf) + 1); /* get memory for that name */
if (name == NULL) { /* oops, we didn't get the memory requested */
fprintf(stderr, "Error...couldn't allocate memory for IOP port name...value of errno is: %d\n", errno);
@ -714,6 +721,8 @@ static void wait_for_all_answers(void) {
while (1) {
int flag = 0;
fd_set working_set;
for (fd = 0; fd <= max_fs; fd++) { /* scan the list of descriptors we may be listening to */
if (FD_ISSET(fd, &readfds)) flag = 1; /* and see if there are any still set */
}
@ -931,7 +940,7 @@ static int pcap_read_acn(pcap_t *handle, int max_packets, pcap_handler callback,
struct pcap_pkthdr pcap_header;
//printf("pcap_read_acn()\n"); // fulko
acn_start_monitor(handle->fd, handle->snapshot, handle->md.timeout, handle->md.clear_promisc, handle->direction); /* maybe tell him to start monitoring */
acn_start_monitor(handle->fd, handle->snapshot, handle->opt.timeout, handle->opt.promisc, handle->direction); /* maybe tell him to start monitoring */
//printf("pcap_read_acn() after start monitor\n"); // fulko
handle->bp = packet_header;
@ -976,7 +985,6 @@ static int pcap_activate_sita(pcap_t *handle) {
&handle->linktype);
if (fd == -1)
return PCAP_ERROR;
handle->md.clear_promisc = handle->md.promisc;
handle->fd = fd;
handle->bufsize = handle->snapshot;
@ -1002,7 +1010,7 @@ static int pcap_activate_sita(pcap_t *handle) {
pcap_t *pcap_create_interface(const char *device, char *ebuf) {
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, 0);
if (p == NULL)
return (NULL);

View File

@ -2,8 +2,6 @@
* pcap-sita.h: Packet capture interface for SITA WAN devices
*
* Authors: Fulko Hew (fulko.hew@sita.aero) (+1 905 6815570);
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-sita.h
*/
extern int acn_parse_hosts_file(char *errbuf);

View File

@ -15,8 +15,20 @@
#include <sys/types.h>
#include <unistd.h>
#include "snf.h"
#include <snf.h>
#include "pcap-int.h"
#include "pcap-snf.h"
/*
* Private data for capturing on SNF devices.
*/
struct pcap_snf {
snf_handle_t snf_handle; /* opaque device handle */
snf_ring_t snf_ring; /* opaque device ring handle */
int snf_timeout;
int snf_boardnum;
};
static int
snf_set_datalink(pcap_t *p, int dlt)
@ -31,7 +43,7 @@ snf_pcap_stats(pcap_t *p, struct pcap_stat *ps)
struct snf_ring_stats stats;
int rc;
if ((rc = snf_ring_getstats(p->md.snf_ring, &stats))) {
if ((rc = snf_ring_getstats(ps->snf_ring, &stats))) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "snf_get_stats: %s",
pcap_strerror(rc));
return -1;
@ -45,30 +57,36 @@ snf_pcap_stats(pcap_t *p, struct pcap_stat *ps)
static void
snf_platform_cleanup(pcap_t *p)
{
struct pcap_snf *ps = p->priv;
if (p == NULL)
return;
snf_ring_close(p->md.snf_ring);
snf_close(p->md.snf_handle);
snf_ring_close(ps->snf_ring);
snf_close(ps->snf_handle);
pcap_cleanup_live_common(p);
}
static int
snf_getnonblock(pcap_t *p, char *errbuf)
{
return (p->md.snf_timeout == 0);
struct pcap_snf *ps = p->priv;
return (ps->snf_timeout == 0);
}
static int
snf_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{
struct pcap_snf *ps = p->priv;
if (nonblock)
p->md.snf_timeout = 0;
ps->snf_timeout = 0;
else {
if (p->md.timeout <= 0)
p->md.snf_timeout = -1; /* forever */
if (p->opt.timeout <= 0)
ps->snf_timeout = -1; /* forever */
else
p->md.snf_timeout = p->md.timeout;
ps->snf_timeout = p->opt.timeout;
}
return (0);
}
@ -91,6 +109,7 @@ snf_timestamp_to_timeval(const int64_t ts_nanosec)
static int
snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_snf *ps = p->priv;
struct pcap_pkthdr hdr;
int i, flags, err, caplen, n;
struct snf_recv_req req;
@ -99,7 +118,7 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
return -1;
n = 0;
while (n < cnt || cnt < 0) {
while (n < cnt || PACKET_COUNT_IS_UNLIMITED(cnt)) {
/*
* Has "pcap_breakloop()" been called?
*/
@ -112,7 +131,7 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
err = snf_ring_recv(p->md.snf_ring, p->md.snf_timeout, &req);
err = snf_ring_recv(ps->snf_ring, ps->snf_timeout, &req);
if (err) {
if (err == EBUSY || err == EAGAIN)
@ -158,8 +177,6 @@ snf_setfilter(pcap_t *p, struct bpf_program *fp)
if (install_bpf_program(p, fp) < 0)
return -1;
p->md.use_bpf = 0;
return (0);
}
@ -174,6 +191,7 @@ snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
static int
snf_activate(pcap_t* p)
{
struct pcap_snf *ps = p->priv;
char *device = p->opt.source;
const char *nr = NULL;
int err;
@ -192,31 +210,31 @@ snf_activate(pcap_t* p)
else
nr = NULL;
err = snf_open(p->md.snf_boardnum,
err = snf_open(ps->snf_boardnum,
0, /* let SNF API parse SNF_NUM_RINGS, if set */
NULL, /* default RSS, or use SNF_RSS_FLAGS env */
0, /* default to SNF_DATARING_SIZE from env */
flags, /* may want pshared */
&p->md.snf_handle);
&ps->snf_handle);
if (err != 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snf_open failed: %s", pcap_strerror(err));
return -1;
}
err = snf_ring_open(p->md.snf_handle, &p->md.snf_ring);
err = snf_ring_open(ps->snf_handle, &ps->snf_ring);
if (err != 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snf_ring_open failed: %s", pcap_strerror(err));
return -1;
}
if (p->md.timeout <= 0)
p->md.snf_timeout = -1;
if (p->opt.timeout <= 0)
ps->snf_timeout = -1;
else
p->md.snf_timeout = p->md.timeout;
ps->snf_timeout = p->opt.timeout;
err = snf_start(p->md.snf_handle);
err = snf_start(ps->snf_handle);
if (err != 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snf_start failed: %s", pcap_strerror(err));
@ -237,9 +255,6 @@ snf_activate(pcap_t* p)
p->setnonblock_op = snf_setnonblock;
p->stats_op = snf_pcap_stats;
p->cleanup_op = snf_platform_cleanup;
p->md.stat.ps_recv = 0;
p->md.stat.ps_drop = 0;
p->md.stat.ps_ifdrop = 0;
return 0;
}
@ -260,6 +275,7 @@ snf_create(const char *device, char *ebuf, int *is_ours)
int boardnum = -1;
struct snf_ifaddrs *ifaddrs, *ifa;
size_t devlen;
struct pcap_snf *ps;
if (snf_init(SNF_VERSION_API)) {
/* Can't initialize the API, so no SNF devices */
@ -303,11 +319,12 @@ snf_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_snf));
if (p == NULL)
return NULL;
ps = p->priv;
p->activate_op = snf_activate;
p->md.snf_boardnum = boardnum;
ps->snf_boardnum = boardnum;
return p;
}

View File

@ -23,11 +23,6 @@
* This module now handles the STREAMS based NIT.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.77 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -84,9 +79,17 @@ static const char rcsid[] _U_ =
/* Forwards */
static int nit_setflags(int, int, int, char *);
/*
* Private data for capturing on STREAMS NIT devices.
*/
struct pcap_snit {
struct pcap_stat stat;
};
static int
pcap_stats_snit(pcap_t *p, struct pcap_stat *ps)
{
struct pcap_snit *psn = p->priv;
/*
* "ps_recv" counts packets handed to the filter, not packets
@ -105,13 +108,14 @@ pcap_stats_snit(pcap_t *p, struct pcap_stat *ps)
* kernel by libpcap or packets not yet read from libpcap by the
* application.
*/
*ps = p->md.stat;
*ps = psn->stat;
return (0);
}
static int
pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_snit *psn = p->priv;
register int cc, n;
register u_char *bp, *cp, *ep;
register struct nit_bufhdr *hdrp;
@ -160,7 +164,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
++p->md.stat.ps_recv;
++psn->stat.ps_recv;
cp = bp;
/* get past NIT buffer */
@ -172,7 +176,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
cp += sizeof(*ntp);
ndp = (struct nit_ifdrops *)cp;
p->md.stat.ps_drop = ndp->nh_drops;
psn->stat.ps_drop = ndp->nh_drops;
cp += sizeof *ndp;
/* get past packet len */
@ -192,7 +196,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
h.len = nlp->nh_pktlen;
h.caplen = caplen;
(*callback)(user, &h, cp);
if (++n >= cnt && cnt > 0) {
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
p->cc = ep - bp;
p->bp = bp;
return (n);
@ -227,33 +231,48 @@ pcap_inject_snit(pcap_t *p, const void *buf, size_t size)
}
static int
nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
nit_setflags(pcap_t *p)
{
bpf_u_int32 flags;
struct strioctl si;
u_int zero = 0;
struct timeval timeout;
if (p->opt.immediate) {
/*
* Set the chunk size to zero, so that chunks get sent
* up immediately.
*/
si.ic_cmd = NIOCSCHUNK;
si.ic_len = sizeof(zero);
si.ic_dp = (char *)&zero;
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "NIOCSCHUNK: %s",
pcap_strerror(errno));
return (-1);
}
}
si.ic_timout = INFTIM;
if (to_ms != 0) {
timeout.tv_sec = to_ms / 1000;
timeout.tv_usec = (to_ms * 1000) % 1000000;
if (p->opt.timeout != 0) {
timeout.tv_sec = p->opt.timeout / 1000;
timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
si.ic_cmd = NIOCSTIME;
si.ic_len = sizeof(timeout);
si.ic_dp = (char *)&timeout;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSTIME: %s",
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "NIOCSTIME: %s",
pcap_strerror(errno));
return (-1);
}
}
flags = NI_TIMESTAMP | NI_LEN | NI_DROPS;
if (promisc)
if (p->opt.promisc)
flags |= NI_PROMISC;
si.ic_cmd = NIOCSFLAGS;
si.ic_len = sizeof(flags);
si.ic_dp = (char *)&flags;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSFLAGS: %s",
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "NIOCSFLAGS: %s",
pcap_strerror(errno));
return (-1);
}
@ -349,7 +368,7 @@ pcap_activate_snit(pcap_t *p)
pcap_strerror(errno));
goto bad;
}
if (nit_setflags(p->fd, p->opt.promisc, p->md.timeout, p->errbuf) < 0)
if (nit_setflags(p) < 0)
goto bad;
(void)ioctl(fd, I_FLUSH, (char *)FLUSHR);
@ -411,7 +430,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_snit));
if (p == NULL)
return (NULL);

View File

@ -18,10 +18,6 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.59 2008-12-02 16:25:14 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -58,9 +54,17 @@ static const char rcsid[] _U_ =
#include "os-proto.h"
#endif
/*
* Private data for capturing on snoop devices.
*/
struct pcap_snoop {
struct pcap_stat stat;
};
static int
pcap_read_snoop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_snoop *psn = p->priv;
int cc;
register struct snoopheader *sh;
register u_int datalen;
@ -124,7 +128,7 @@ pcap_read_snoop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (p->fcode.bf_insns == NULL ||
bpf_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
struct pcap_pkthdr h;
++p->md.stat.ps_recv;
++psn->stat.ps_recv;
h.ts.tv_sec = sh->snoop_timestamp.tv_sec;
h.ts.tv_usec = sh->snoop_timestamp.tv_usec;
h.len = datalen;
@ -156,6 +160,7 @@ pcap_inject_snoop(pcap_t *p, const void *buf, size_t size)
static int
pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
{
struct pcap_snoop *psn = p->priv;
register struct rawstats *rs;
struct rawstats rawstats;
@ -180,7 +185,7 @@ pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
* rather than just this socket? If not, why does it have
* both Snoop and Drain statistics?
*/
p->md.stat.ps_drop =
psn->stat.ps_drop =
rs->rs_snoop.ss_ifdrops + rs->rs_snoop.ss_sbdrops +
rs->rs_drain.ds_ifdrops + rs->rs_drain.ds_sbdrops;
@ -189,7 +194,7 @@ pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
* As filtering is done in userland, this does not include
* packets dropped because we ran out of buffer space.
*/
*ps = p->md.stat;
*ps = psn->stat;
return (0);
}
@ -398,7 +403,7 @@ pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_snoop));
if (p == NULL)
return (NULL);

View File

@ -27,63 +27,57 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL)
*/
#ifndef pcap_stdinc_h
#define pcap_stdinc_h
/*
* Avoids a compiler warning in case this was already defined
* Avoids a compiler warning in case this was already defined
* (someone defined _WINSOCKAPI_ when including 'windows.h', in order
* to prevent it from including 'winsock.h')
*/
#ifdef _WINSOCKAPI_
#undef _WINSOCKAPI_
#endif
#include <winsock2.h>
#include <fcntl.h>
#include "bittypes.h"
#include <time.h>
#include <io.h>
#ifndef __MINGW32__
#include "bittypes.h"
#include "IP6_misc.h"
#endif
#define caddr_t char*
#if _MSC_VER < 1500
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strdup _strdup
#if defined(_MSC_VER)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strdup _strdup
#endif
#define inline __inline
#define inline __inline
#ifdef __MINGW32__
#include <stdint.h>
#else /*__MINGW32__*/
/* MSVC compiler */
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#include <stdint.h>
#else
typedef _W64 unsigned int uintptr_t;
#endif
#define _UINTPTR_T_DEFINED
#endif
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef _W64 int intptr_t;
#endif
#define _INTPTR_T_DEFINED
#endif
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef _W64 unsigned int uintptr_t;
#endif
#define _UINTPTR_T_DEFINED
#endif
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef _W64 int intptr_t;
#endif
#define _INTPTR_T_DEFINED
#endif
#endif /*__MINGW32__*/
#endif /* pcap_stdinc_h */

View File

@ -19,7 +19,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-TSTAMP 7 "22 August 2010"
.TH PCAP-TSTAMP 7 "21 December 2013"
.SH NAME
pcap-tstamp \- packet time stamps in libpcap
.SH DESCRIPTION
@ -95,7 +95,7 @@ The time stamp types are listed here; the first value is the #define to
use in code, the second value is the value returned by
.B pcap_tstamp_type_val_to_name()
and accepted by
.BR pcap_tstamp_name_to_val() .
.BR pcap_tstamp_type_name_to_val() .
.RS 5
.TP 5
.BR PCAP_TSTAMP_HOST " - " host
@ -129,4 +129,4 @@ the host operating system's clock.
pcap_set_tstamp_type(3PCAP),
pcap_list_tstamp_types(3PCAP),
pcap_tstamp_type_val_to_name(3PCAP),
pcap_tstamp_name_to_val(3PCAP)
pcap_tstamp_type_name_to_val(3PCAP)

View File

@ -19,7 +19,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP-TSTAMP @MAN_MISC_INFO@ "22 August 2010"
.TH PCAP-TSTAMP @MAN_MISC_INFO@ "21 December 2013"
.SH NAME
pcap-tstamp \- packet time stamps in libpcap
.SH DESCRIPTION
@ -95,7 +95,7 @@ The time stamp types are listed here; the first value is the #define to
use in code, the second value is the value returned by
.B pcap_tstamp_type_val_to_name()
and accepted by
.BR pcap_tstamp_name_to_val() .
.BR pcap_tstamp_type_name_to_val() .
.RS 5
.TP 5
.BR PCAP_TSTAMP_HOST " - " host
@ -129,4 +129,4 @@ the host operating system's clock.
pcap_set_tstamp_type(3PCAP),
pcap_list_tstamp_types(3PCAP),
pcap_tstamp_type_val_to_name(3PCAP),
pcap_tstamp_name_to_val(3PCAP)
pcap_tstamp_type_name_to_val(3PCAP)

View File

@ -32,10 +32,6 @@
* Modifications: Kris Katterjohn <katterjohn@gmail.com>
*
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-usb-linux.c,v 1.33 2008-12-23 21:38:50 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -121,6 +117,16 @@ struct mon_bin_mfetch {
#define MON_BIN_DATA_ZERO 0x4 /* data buffer is not available */
#define MON_BIN_ERROR 0x8
/*
* Private data for capturing on Linux USB.
*/
struct pcap_usb_linux {
u_char *mmapbuf; /* memory-mapped region pointer */
size_t mmapbuflen; /* size of region */
int bus_index;
u_int packets_read;
};
/* forward declaration */
static int usb_activate(pcap_t *);
static int usb_stats_linux(pcap_t *, struct pcap_stat *);
@ -204,16 +210,19 @@ usb_findalldevs(pcap_if_t **alldevsp, char *err_str)
static
int usb_mmap(pcap_t* handle)
{
struct pcap_usb_linux *handlep = handle->priv;
int len = ioctl(handle->fd, MON_IOCQ_RING_SIZE);
if (len < 0)
return 0;
handle->md.mmapbuflen = len;
handle->md.mmapbuf = mmap(0, handle->md.mmapbuflen, PROT_READ,
handlep->mmapbuflen = len;
handlep->mmapbuf = mmap(0, handlep->mmapbuflen, PROT_READ,
MAP_SHARED, handle->fd, 0);
return handle->md.mmapbuf != MAP_FAILED;
return handlep->mmapbuf != MAP_FAILED;
}
#ifdef HAVE_LINUX_USBDEVICE_FS_H
#define CTRL_TIMEOUT (5*1000) /* milliseconds */
#define USB_DIR_IN 0x80
@ -282,6 +291,7 @@ probe_devices(int bus)
}
closedir(dir);
}
#endif /* HAVE_LINUX_USBDEVICE_FS_H */
pcap_t *
usb_create(const char *device, char *ebuf, int *is_ours)
@ -318,7 +328,7 @@ usb_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_usb_linux));
if (p == NULL)
return (NULL);
@ -329,6 +339,7 @@ usb_create(const char *device, char *ebuf, int *is_ours)
static int
usb_activate(pcap_t* handle)
{
struct pcap_usb_linux *handlep = handle->priv;
char full_path[USB_LINE_LEN];
/* Initialize some components of the pcap structure. */
@ -344,7 +355,7 @@ usb_activate(pcap_t* handle)
handle->setnonblock_op = pcap_setnonblock_fd;
/*get usb bus index from device name */
if (sscanf(handle->opt.source, USB_IFACE"%d", &handle->md.ifindex) != 1)
if (sscanf(handle->opt.source, USB_IFACE"%d", &handlep->bus_index) != 1)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get USB bus index from %s", handle->opt.source);
@ -352,7 +363,7 @@ usb_activate(pcap_t* handle)
}
/*now select the read method: try to open binary interface */
snprintf(full_path, USB_LINE_LEN, LINUX_USB_MON_DEV"%d", handle->md.ifindex);
snprintf(full_path, USB_LINE_LEN, LINUX_USB_MON_DEV"%d", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
if (handle->fd >= 0)
{
@ -370,7 +381,9 @@ usb_activate(pcap_t* handle)
handle->stats_op = usb_stats_linux_bin;
handle->read_op = usb_read_linux_mmap;
handle->cleanup_op = usb_cleanup_linux_mmap;
probe_devices(handle->md.ifindex);
#ifdef HAVE_LINUX_USBDEVICE_FS_H
probe_devices(handlep->bus_index);
#endif
/*
* "handle->fd" is a real file, so "select()" and
@ -383,11 +396,13 @@ usb_activate(pcap_t* handle)
/* can't mmap, use plain binary interface access */
handle->stats_op = usb_stats_linux_bin;
handle->read_op = usb_read_linux_bin;
probe_devices(handle->md.ifindex);
#ifdef HAVE_LINUX_USBDEVICE_FS_H
probe_devices(handlep->bus_index);
#endif
}
else {
/*Binary interface not available, try open text interface */
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR"/%dt", handle->md.ifindex);
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR"/%dt", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
if (handle->fd < 0)
{
@ -397,7 +412,7 @@ usb_activate(pcap_t* handle)
* Not found at the new location; try
* the old location.
*/
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%dt", handle->md.ifindex);
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%dt", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
}
if (handle->fd < 0) {
@ -456,6 +471,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
* /usr/src/linux/Documentation/usb/usbmon.txt
* for message format
*/
struct pcap_usb_linux *handlep = handle->priv;
unsigned timestamp;
int tag, cnt, ep_num, dev_addr, dummy, ret, urb_len, data_len;
char etype, pipeid1, pipeid2, status[16], urb_tag, line[USB_LINE_LEN];
@ -500,7 +516,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
}
uhdr->id = tag;
uhdr->device_address = dev_addr;
uhdr->bus_id = handle->md.ifindex;
uhdr->bus_id = handlep->bus_index;
uhdr->status = 0;
string += cnt;
@ -639,7 +655,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, handle->buffer,
pkth.len, pkth.caplen)) {
handle->md.packets_read++;
handlep->packets_read++;
callback(user, &pkth, handle->buffer);
return 1;
}
@ -657,13 +673,14 @@ usb_inject_linux(pcap_t *handle, const void *buf, size_t size)
static int
usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_usb_linux *handlep = handle->priv;
int dummy, ret, consumed, cnt;
char string[USB_LINE_LEN];
char token[USB_LINE_LEN];
char * ptr = string;
int fd;
snprintf(string, USB_LINE_LEN, USB_TEXT_DIR"/%ds", handle->md.ifindex);
snprintf(string, USB_LINE_LEN, USB_TEXT_DIR"/%ds", handlep->bus_index);
fd = open(string, O_RDONLY, 0);
if (fd < 0)
{
@ -673,7 +690,7 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
* Not found at the new location; try the old
* location.
*/
snprintf(string, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%ds", handle->md.ifindex);
snprintf(string, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%ds", handlep->bus_index);
fd = open(string, O_RDONLY, 0);
}
if (fd < 0) {
@ -724,7 +741,7 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
ptr += cnt;
}
stats->ps_recv = handle->md.packets_read;
stats->ps_recv = handlep->packets_read;
stats->ps_ifdrop = 0;
return 0;
}
@ -740,6 +757,7 @@ usb_setdirection_linux(pcap_t *p, pcap_direction_t d)
static int
usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_usb_linux *handlep = handle->priv;
int ret;
struct mon_bin_stats st;
ret = ioctl(handle->fd, MON_IOCG_STATS, &st);
@ -750,7 +768,7 @@ usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
return -1;
}
stats->ps_recv = handle->md.packets_read + st.queued;
stats->ps_recv = handlep->packets_read + st.queued;
stats->ps_drop = st.dropped;
stats->ps_ifdrop = 0;
return 0;
@ -763,6 +781,7 @@ usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
static int
usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
struct pcap_usb_linux *handlep = handle->priv;
struct mon_bin_get info;
int ret;
struct pcap_pkthdr pkth;
@ -805,7 +824,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, handle->buffer,
pkth.len, pkth.caplen)) {
handle->md.packets_read++;
handlep->packets_read++;
callback(user, &pkth, handle->buffer);
return 1;
}
@ -821,6 +840,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha
static int
usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
struct pcap_usb_linux *handlep = handle->priv;
struct mon_bin_mfetch fetch;
int32_t vec[VEC_SIZE];
struct pcap_pkthdr pkth;
@ -866,7 +886,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
nflush = fetch.nfetch;
for (i=0; i<fetch.nfetch; ++i) {
/* discard filler */
hdr = (pcap_usb_header*) &handle->md.mmapbuf[vec[i]];
hdr = (pcap_usb_header*) &handlep->mmapbuf[vec[i]];
if (hdr->event_type == '@')
continue;
@ -885,14 +905,14 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, (u_char*) hdr,
pkth.len, pkth.caplen)) {
handle->md.packets_read++;
handlep->packets_read++;
callback(user, &pkth, (u_char*) hdr);
packets++;
}
}
/* with max_packets <= 0 we stop afer the first chunk*/
if ((max_packets <= 0) || (packets == max_packets))
/* with max_packets specifying "unlimited" we stop afer the first chunk*/
if (PACKET_COUNT_IS_UNLIMITED(max_packets) || (packets == max_packets))
break;
}
@ -904,10 +924,12 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
static void
usb_cleanup_linux_mmap(pcap_t* handle)
{
struct pcap_usb_linux *handlep = handle->priv;
/* if we have a memory-mapped buffer, unmap it */
if (handle->md.mmapbuf != NULL) {
munmap(handle->md.mmapbuf, handle->md.mmapbuflen);
handle->md.mmapbuf = NULL;
if (handlep->mmapbuf != NULL) {
munmap(handlep->mmapbuf, handlep->mmapbuflen);
handlep->mmapbuf = NULL;
}
pcap_cleanup_live_common(handle);
}

View File

@ -29,8 +29,6 @@
*
* USB sniffing API implementation for Linux platform
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-usb-linux.h,v 1.5 2008-04-04 19:37:45 guy Exp $ (LBL)
*/
/*

View File

@ -31,11 +31,6 @@
*
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.42 2008-05-21 22:15:25 gianluca Exp $ (LBL)";
#endif
#include <pcap-int.h>
#include <Packet32.h>
#ifdef __MINGW32__
@ -71,6 +66,19 @@ static int pcap_setnonblock_win32(pcap_t *, int, char *);
/* Equivalent to ntohs(), but a lot faster under Windows */
#define SWAPS(_X) ((_X & 0xff) << 8) | (_X >> 8)
/*
* Private data for capturing on WinPcap devices.
*/
struct pcap_win {
int nonblock;
int filtering_in_kernel; /* using kernel filter */
#ifdef HAVE_DAG_API
int dag_fcs_bits; /* Number of checksum bits from link layer */
#endif
};
/*
* Header that the WinPcap driver associates to the packets.
* Once was in bpf.h
@ -105,16 +113,27 @@ wsockinit()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
static int err = -1;
static int done = 0;
if (done)
return err;
wVersionRequested = MAKEWORD( 1, 1);
err = WSAStartup( wVersionRequested, &wsaData );
atexit ((void(*)(void))WSACleanup);
InitializeCriticalSection(&g_PcapCompileCriticalSection);
done = 1;
if ( err != 0 )
{
return -1;
}
return 0;
err = -1;
return err;
}
int pcap_wsockinit()
{
return wsockinit();
}
static int
pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
@ -165,12 +184,21 @@ pcap_setmintocopy_win32(pcap_t *p, int size)
return 0;
}
/*return the Adapter for a pcap_t*/
static Adapter *
pcap_getadapter_win32(pcap_t *p)
{
return p->adapter;
}
static int
pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
int cc;
int n = 0;
register u_char *bp, *ep;
u_char *datap;
struct pcap_win *pw = p->priv;
cc = p->cc;
if (p->cc == 0) {
@ -180,17 +208,17 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (p->break_loop) {
/*
* Yes - clear the flag that indicates that it
* has, and return -2 to indicate that we were
* told to break out of the loop.
* has, and return PCAP_ERROR_BREAK to indicate
* that we were told to break out of the loop.
*/
p->break_loop = 0;
return (-2);
return (PCAP_ERROR_BREAK);
}
/* capture the packets */
if(PacketReceivePacket(p->adapter,p->Packet,TRUE)==FALSE){
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
return (-1);
return (PCAP_ERROR);
}
cc = p->Packet->ulBytesReceived;
@ -211,16 +239,17 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/*
* Has "pcap_breakloop()" been called?
* If so, return immediately - if we haven't read any
* packets, clear the flag and return -2 to indicate
* that we were told to break out of the loop, otherwise
* leave the flag set, so that the *next* call will break
* out of the loop without having read any packets, and
* return the number of packets we've processed so far.
* packets, clear the flag and return PCAP_ERROR_BREAK
* to indicate that we were told to break out of the loop,
* otherwise leave the flag set, so that the *next* call
* will break out of the loop without having read any
* packets, and return the number of packets we've
* processed so far.
*/
if (p->break_loop) {
if (n == 0) {
p->break_loop = 0;
return (-2);
return (PCAP_ERROR_BREAK);
} else {
p->bp = bp;
p->cc = ep - bp;
@ -232,16 +261,35 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
caplen = bhp->bh_caplen;
hdrlen = bhp->bh_hdrlen;
datap = bp + hdrlen;
/*
* XXX A bpf_hdr matches a pcap_pkthdr.
* Short-circuit evaluation: if using BPF filter
* in kernel, no need to do it now - we already know
* the packet passed the filter.
*
* XXX - bpf_filter() should always return TRUE if
* handed a null pointer for the program, but it might
* just try to "run" the filter, so we check here.
*/
(*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen);
bp += Packet_WORDALIGN(caplen + hdrlen);
if (++n >= cnt && cnt > 0) {
p->bp = bp;
p->cc = ep - bp;
return (n);
if (pw->filtering_in_kernel ||
p->fcode.bf_insns == NULL ||
bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
/*
* XXX A bpf_hdr matches a pcap_pkthdr.
*/
(*callback)(user, (struct pcap_pkthdr*)bp, datap);
bp += Packet_WORDALIGN(caplen + hdrlen);
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
p->bp = bp;
p->cc = ep - bp;
return (n);
}
} else {
/*
* Skip this packet.
*/
bp += Packet_WORDALIGN(caplen + hdrlen);
}
}
#undef bhp
@ -253,6 +301,7 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
static int
pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_win *pw = p->priv;
u_char *dp = NULL;
int packet_len = 0, caplen = 0;
struct pcap_pkthdr pcap_header;
@ -295,7 +344,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
break;
/* Increase the number of captured packets */
p->md.stat.ps_recv++;
pw->stat.ps_recv++;
/* Find the beginning of the packet */
dp = ((u_char *)header) + dag_record_size;
@ -312,7 +361,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_ETH:
swt = SWAPS(header->wlen);
packet_len = swt - (p->md.dag_fcs_bits);
packet_len = swt - (pw->dag_fcs_bits);
caplen = erf_record_len - dag_record_size - 2;
if (caplen > packet_len)
{
@ -324,7 +373,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_HDLC_POS:
swt = SWAPS(header->wlen);
packet_len = swt - (p->md.dag_fcs_bits);
packet_len = swt - (pw->dag_fcs_bits);
caplen = erf_record_len - dag_record_size;
if (caplen > packet_len)
{
@ -397,7 +446,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
header = (dag_record_t*)((char*)header + erf_record_len);
/* Stop if the number of packets requested by user has been reached*/
if (++n >= cnt && cnt > 0)
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
{
p->bp = (char*)header;
p->cc = endofbuf - (char*)header;
@ -457,6 +506,7 @@ pcap_cleanup_win32(pcap_t *p)
static int
pcap_activate_win32(pcap_t *p)
{
struct pcap_win *pw = p->priv;
NetType type;
if (p->opt.rfmon) {
@ -622,11 +672,23 @@ pcap_activate_win32(pcap_t *p)
PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
/* tell the driver to copy the buffer only if it contains at least 16K */
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
if (p->opt.immediate)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
goto bad;
/* tell the driver to copy the buffer as soon as data arrives */
if(PacketSetMinToCopy(p->adapter,0)==FALSE)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
goto bad;
}
}
else
{
/* tell the driver to copy the buffer only if it contains at least 16K */
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s", pcap_win32strerror());
goto bad;
}
}
}
else
@ -672,13 +734,13 @@ pcap_activate_win32(pcap_t *p)
/* Set the length of the FCS associated to any packet. This value
* will be subtracted to the packet length */
p->md.dag_fcs_bits = p->adapter->DagFcsLen;
pw->dag_fcs_bits = p->adapter->DagFcsLen;
}
#else
goto bad;
#endif /* HAVE_DAG_API */
PacketSetReadTimeout(p->adapter, p->md.timeout);
PacketSetReadTimeout(p->adapter, p->opt.timeout);
#ifdef HAVE_DAG_API
if(p->adapter->Flags & INFO_FLAG_DAG_CARD)
@ -706,6 +768,7 @@ pcap_activate_win32(pcap_t *p)
p->setbuff_op = pcap_setbuff_win32;
p->setmode_op = pcap_setmode_win32;
p->setmintocopy_op = pcap_setmintocopy_win32;
p->getadapter_op = pcap_getadapter_win32;
p->cleanup_op = pcap_cleanup_win32;
return (0);
@ -743,12 +806,12 @@ pcap_create_interface(const char *device, char *ebuf)
}
snprintf(deviceAscii, length + 1, "%ws", (wchar_t*)device);
p = pcap_create_common(deviceAscii, ebuf);
p = pcap_create_common(deviceAscii, ebuf, sizeof (struct pcap_win));
free(deviceAscii);
}
else
{
p = pcap_create_common(device, ebuf);
p = pcap_create_common(device, ebuf, sizeof (struct pcap_win));
}
if (p == NULL)
@ -761,16 +824,51 @@ pcap_create_interface(const char *device, char *ebuf)
static int
pcap_setfilter_win32_npf(pcap_t *p, struct bpf_program *fp)
{
struct pcap_win *pw = p->priv;
if(PacketSetBpf(p->adapter,fp)==FALSE){
/*
* Kernel filter not installed.
* XXX - fall back on userland filtering, as is done
* on other platforms?
*
* XXX - we don't know whether this failed because:
*
* the kernel rejected the filter program as invalid,
* in which case we should fall back on userland
* filtering;
*
* the kernel rejected the filter program as too big,
* in which case we should again fall back on
* userland filtering;
*
* there was some other problem, in which case we
* should probably report an error.
*
* For NPF devices, the Win32 status will be
* STATUS_INVALID_DEVICE_REQUEST for invalid
* filters, but I don't know what it'd be for
* other problems, and for some other devices
* it might not be set at all.
*
* So we just fall back on userland filtering in
* all cases.
*/
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Driver error: cannot set bpf filter: %s", pcap_win32strerror());
return (-1);
/*
* install_bpf_program() validates the program.
*
* XXX - what if we already have a filter in the kernel?
*/
if (install_bpf_program(p, fp) < 0)
return (-1);
pw->filtering_in_kernel = 0; /* filtering in userland */
return (0);
}
/*
* It worked.
*/
pw->filtering_in_kernel = 1; /* filtering in the kernel */
/*
* Discard any previously-received packets, as they might have
* passed whatever filter was formerly in effect, but might
@ -801,25 +899,26 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
return -1;
}
p->md.use_bpf = 0;
return (0);
}
static int
pcap_getnonblock_win32(pcap_t *p, char *errbuf)
{
struct pcap_win *pw = p->priv;
/*
* XXX - if there were a PacketGetReadTimeout() call, we
* would use it, and return 1 if the timeout is -1
* and 0 otherwise.
*/
return (p->nonblock);
return (pw->nonblock);
}
static int
pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
{
struct pcap_win *pw = p->priv;
int newtimeout;
if (nonblock) {
@ -833,14 +932,14 @@ pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
* (Note that this may be -1, in which case we're not
* really leaving non-blocking mode.)
*/
newtimeout = p->md.timeout;
newtimeout = p->opt.timeout;
}
if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
snprintf(errbuf, PCAP_ERRBUF_SIZE,
"PacketSetReadTimeout: %s", pcap_win32strerror());
return (-1);
}
p->nonblock = (newtimeout == -1);
pw->nonblock = (newtimeout == -1);
return (0);
}

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3pcap.in,v 1.1 2008-10-21 07:33:01 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\"
@ -19,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP 3PCAP "4 April 2008"
.TH PCAP 3PCAP "16 April 2014"
.SH NAME
pcap \- Packet Capture library
.SH SYNOPSIS
@ -309,6 +307,19 @@ handle, call
lists the values it returns and describes the packet formats that
correspond to those values.
.PP
Do
.B NOT
assume that the packets for a given capture or ``savefile`` will have
any given link-layer header type, such as
.B DLT_EN10MB
for Ethernet. For example, the "any" device on Linux will have a
link-layer header type of
.B DLT_LINUX_SLL
even if all devices on the system at the time the "any" device is opened
have some other data link type, such as
.B DLT_EN10MB
for Ethernet.
.PP
To obtain the
.B "FILE\ *"
corresponding to a
@ -410,7 +421,7 @@ get name for a time stamp type
.BR pcap_tstamp_type_val_to_description (3PCAP)
get description for a time stamp type
.TP
.BR pcap_tstamp_name_to_val (3PCAP)
.BR pcap_tstamp_type_name_to_val (3PCAP)
get time stamp type corresponding to a name
.TP
.BR pcap_datalink (3PCAP)
@ -510,20 +521,13 @@ number of bytes available from the capture, if the length of the packet
is larger than the maximum number of bytes to capture).
.RE
.PP
.BR pcap_next_ex ()
supplies that pointer through a pointer argument.
.BR pcap_next ()
is passed an argument that points to a
.I struct pcap_pkthdr
structure, and fills it in.
.PP
The callback is also supplied a
.I const u_char
pointer to the first
.B caplen
(as given in the
.I struct pcap_pkthdr
a pointer to which is passed to the callback routine)
mentioned above)
bytes of data from the packet. This won't necessarily be the entire
packet; to capture the entire packet, you will have to provide a value
for
@ -534,10 +538,28 @@ that is sufficiently large to get all of the packet's data - a value of
65535 should be sufficient on most if not all networks). When reading
from a ``savefile'', the snapshot length specified when the capture was
performed will limit the amount of packet data available.
.PP
.BR pcap_next ()
returns that pointer;
is passed an argument that points to a
.I struct pcap_pkthdr
structure, and fills it in with the time stamp and length values for the
packet. It returns a
.I const u_char
to the first
.B caplen
bytes of the packet on success, and NULL on error.
.PP
.BR pcap_next_ex ()
supplies that pointer through a pointer argument.
is passed two pointer arguments, one of which points to a
.IR struct pcap_pkthdr *
and one of which points to a
.IR "const u_char" *.
It sets the first pointer to point to a
.I struct pcap_pkthdr
structure with the time stamp and length values for the packet, and sets
the second pointer to point to the first
.B caplen
bytes of the packet.
.PP
To force the loop in
.BR pcap_dispatch ()
@ -821,12 +843,12 @@ get a string for an error or warning status code
.RE
.SS Getting library version information
To get a string giving version information about libpcap, call
.BR pcap_library_version ().
.BR pcap_lib_version ().
.TP
.B Routines
.RS
.TP
.BR pcap_library_version (3PCAP)
.BR pcap_lib_version (3PCAP)
get library version string
.RE
.SH BACKWARDS COMPATIBILITY

View File

@ -1,5 +1,3 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3pcap.in,v 1.1 2008-10-21 07:33:01 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\"
@ -19,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP 3PCAP "4 April 2008"
.TH PCAP 3PCAP "16 April 2014"
.SH NAME
pcap \- Packet Capture library
.SH SYNOPSIS
@ -309,6 +307,19 @@ handle, call
lists the values it returns and describes the packet formats that
correspond to those values.
.PP
Do
.B NOT
assume that the packets for a given capture or ``savefile`` will have
any given link-layer header type, such as
.B DLT_EN10MB
for Ethernet. For example, the "any" device on Linux will have a
link-layer header type of
.B DLT_LINUX_SLL
even if all devices on the system at the time the "any" device is opened
have some other data link type, such as
.B DLT_EN10MB
for Ethernet.
.PP
To obtain the
.B "FILE\ *"
corresponding to a
@ -410,7 +421,7 @@ get name for a time stamp type
.BR pcap_tstamp_type_val_to_description (3PCAP)
get description for a time stamp type
.TP
.BR pcap_tstamp_name_to_val (3PCAP)
.BR pcap_tstamp_type_name_to_val (3PCAP)
get time stamp type corresponding to a name
.TP
.BR pcap_datalink (3PCAP)
@ -510,20 +521,13 @@ number of bytes available from the capture, if the length of the packet
is larger than the maximum number of bytes to capture).
.RE
.PP
.BR pcap_next_ex ()
supplies that pointer through a pointer argument.
.BR pcap_next ()
is passed an argument that points to a
.I struct pcap_pkthdr
structure, and fills it in.
.PP
The callback is also supplied a
.I const u_char
pointer to the first
.B caplen
(as given in the
.I struct pcap_pkthdr
a pointer to which is passed to the callback routine)
mentioned above)
bytes of data from the packet. This won't necessarily be the entire
packet; to capture the entire packet, you will have to provide a value
for
@ -534,10 +538,28 @@ that is sufficiently large to get all of the packet's data - a value of
65535 should be sufficient on most if not all networks). When reading
from a ``savefile'', the snapshot length specified when the capture was
performed will limit the amount of packet data available.
.PP
.BR pcap_next ()
returns that pointer;
is passed an argument that points to a
.I struct pcap_pkthdr
structure, and fills it in with the time stamp and length values for the
packet. It returns a
.I const u_char
to the first
.B caplen
bytes of the packet on success, and NULL on error.
.PP
.BR pcap_next_ex ()
supplies that pointer through a pointer argument.
is passed two pointer arguments, one of which points to a
.IR struct pcap_pkthdr *
and one of which points to a
.IR "const u_char" *.
It sets the first pointer to point to a
.I struct pcap_pkthdr
structure with the time stamp and length values for the packet, and sets
the second pointer to point to the first
.B caplen
bytes of the packet.
.PP
To force the loop in
.BR pcap_dispatch ()
@ -821,12 +843,12 @@ get a string for an error or warning status code
.RE
.SS Getting library version information
To get a string giving version information about libpcap, call
.BR pcap_library_version ().
.BR pcap_lib_version ().
.TP
.B Routines
.RS
.TP
.BR pcap_library_version (3PCAP)
.BR pcap_lib_version (3PCAP)
get library version string
.RE
.SH BACKWARDS COMPATIBILITY

View File

@ -31,11 +31,6 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.128 2008-12-23 20:13:29 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -94,6 +89,10 @@ static const char rcsid[] _U_ =
#include "pcap-bt-linux.h"
#endif
#ifdef PCAP_SUPPORT_BT_MONITOR
#include "pcap-bt-monitor-linux.h"
#endif
#ifdef PCAP_SUPPORT_CAN
#include "pcap-can-linux.h"
#endif
@ -110,13 +109,25 @@ static const char rcsid[] _U_ =
pcap_t* pcap_netmap_create(const char *device, char *ebuf, int *is_ours);
#endif
int
pcap_not_initialized(pcap_t *pcap)
#ifdef PCAP_SUPPORT_DBUS
#include "pcap-dbus.h"
#endif
int
pcap_not_initialized(pcap_t *pcap _U_)
{
/* this means 'not initialized' */
return (PCAP_ERROR_NOT_ACTIVATED);
}
#ifdef WIN32
Adapter *
pcap_no_adapter(pcap_t *pcap _U_)
{
return (NULL);
}
#endif
/*
* Returns 1 if rfmon mode can be set on the pcap_t, 0 if it can't,
* a PCAP_ERROR value on an error.
@ -191,7 +202,7 @@ pcap_free_tstamp_types(int *tstamp_type_list)
* packet data cannot be guaranteed to be available after the callback
* returns, so that a copy must be made.
*/
static void
void
pcap_oneshot(u_char *user, const struct pcap_pkthdr *h, const u_char *pkt)
{
struct oneshot_userdata *sp = (struct oneshot_userdata *)user;
@ -214,7 +225,7 @@ pcap_next(pcap_t *p, struct pcap_pkthdr *h)
return (pkt);
}
int
int
pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
const u_char **pkt_data)
{
@ -227,7 +238,7 @@ pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
/* Saves a pointer to the packet headers */
*pkt_header= &p->pcap_header;
if (p->sf.rfile != NULL) {
if (p->rfile != NULL) {
int status;
/* We are on an offline capture */
@ -320,6 +331,9 @@ struct capture_source_type {
#ifdef PCAP_SUPPORT_BT
{ bt_findalldevs, bt_create },
#endif
#ifdef PCAP_SUPPORT_BT_MONITOR
{ bt_monitor_findalldevs, bt_monitor_create },
#endif
#if PCAP_SUPPORT_CANUSB
{ canusb_findalldevs, canusb_create },
#endif
@ -331,6 +345,9 @@ struct capture_source_type {
#endif
#ifdef PCAP_SUPPORT_NETFILTER
{ netfilter_findalldevs, netfilter_create },
#endif
#ifdef PCAP_SUPPORT_DBUS
{ dbus_findalldevs, dbus_create },
#endif
{ NULL, NULL }
};
@ -348,7 +365,7 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
/*
* Get the list of regular interfaces first.
*/
*/
if (pcap_findalldevs_interfaces(alldevsp, errbuf) == -1)
return (-1); /* failure */
@ -385,6 +402,7 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
return (-1);
}
}
return (0);
}
@ -454,6 +472,7 @@ initialize_ops(pcap_t *p)
p->setbuff_op = (setbuff_op_t)pcap_not_initialized;
p->setmode_op = (setmode_op_t)pcap_not_initialized;
p->setmintocopy_op = (setmintocopy_op_t)pcap_not_initialized;
p->getadapter_op = pcap_no_adapter;
#endif
/*
@ -464,29 +483,64 @@ initialize_ops(pcap_t *p)
p->cleanup_op = pcap_cleanup_live_common;
/*
* In most cases, the standard one-short callback can
* In most cases, the standard one-shot callback can
* be used for pcap_next()/pcap_next_ex().
*/
p->oneshot_callback = pcap_oneshot;
}
pcap_t *
pcap_create_common(const char *source, char *ebuf)
static pcap_t *
pcap_alloc_pcap_t(char *ebuf, size_t size)
{
char *chunk;
pcap_t *p;
p = malloc(sizeof(*p));
if (p == NULL) {
/*
* Allocate a chunk of memory big enough for a pcap_t
* plus a structure following it of size "size". The
* structure following it is a private data structure
* for the routines that handle this pcap_t.
*/
chunk = malloc(sizeof (pcap_t) + size);
if (chunk == NULL) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
pcap_strerror(errno));
return (NULL);
}
memset(p, 0, sizeof(*p));
memset(chunk, 0, sizeof (pcap_t) + size);
/*
* Get a pointer to the pcap_t at the beginning.
*/
p = (pcap_t *)chunk;
#ifndef WIN32
p->fd = -1; /* not opened yet */
p->selectable_fd = -1;
p->send_fd = -1;
#endif
#endif
if (size == 0) {
/* No private data was requested. */
p->priv = NULL;
} else {
/*
* Set the pointer to the private data; that's the structure
* of size "size" following the pcap_t.
*/
p->priv = (void *)(chunk + sizeof (pcap_t));
}
return (p);
}
pcap_t *
pcap_create_common(const char *source, char *ebuf, size_t size)
{
pcap_t *p;
p = pcap_alloc_pcap_t(ebuf, size);
if (p == NULL)
return (NULL);
p->opt.source = strdup(source);
if (p->opt.source == NULL) {
@ -507,11 +561,14 @@ pcap_create_common(const char *source, char *ebuf)
initialize_ops(p);
/* put in some defaults*/
pcap_set_timeout(p, 0);
pcap_set_snaplen(p, 65535); /* max packet size */
pcap_set_snaplen(p, MAXIMUM_SNAPLEN); /* max packet size */
p->opt.timeout = 0; /* no timeout specified */
p->opt.buffer_size = 0; /* use the platform's default */
p->opt.promisc = 0;
p->opt.buffer_size = 0;
p->opt.rfmon = 0;
p->opt.immediate = 0;
p->opt.tstamp_type = -1; /* default to not setting time stamp type */
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
return (p);
}
@ -558,7 +615,7 @@ pcap_set_timeout(pcap_t *p, int timeout_ms)
{
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
p->md.timeout = timeout_ms;
p->opt.timeout = timeout_ms;
return (0);
}
@ -571,32 +628,44 @@ pcap_set_tstamp_type(pcap_t *p, int tstamp_type)
return (PCAP_ERROR_ACTIVATED);
/*
* If p->tstamp_type_count is 0, we don't support setting
* the time stamp type at all.
* If p->tstamp_type_count is 0, we only support PCAP_TSTAMP_HOST;
* the default time stamp type is PCAP_TSTAMP_HOST.
*/
if (p->tstamp_type_count == 0)
return (PCAP_ERROR_CANTSET_TSTAMP_TYPE);
/*
* Check whether we claim to support this type of time stamp.
*/
for (i = 0; i < p->tstamp_type_count; i++) {
if (p->tstamp_type_list[i] == tstamp_type) {
/*
* Yes.
*/
if (p->tstamp_type_count == 0) {
if (tstamp_type == PCAP_TSTAMP_HOST) {
p->opt.tstamp_type = tstamp_type;
return (0);
}
} else {
/*
* Check whether we claim to support this type of time stamp.
*/
for (i = 0; i < p->tstamp_type_count; i++) {
if (p->tstamp_type_list[i] == tstamp_type) {
/*
* Yes.
*/
p->opt.tstamp_type = tstamp_type;
return (0);
}
}
}
/*
* No. We support setting the time stamp type, but not to this
* particular value.
* We don't support this type of time stamp.
*/
return (PCAP_WARNING_TSTAMP_TYPE_NOTSUP);
}
int
pcap_set_immediate_mode(pcap_t *p, int immediate)
{
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
p->opt.immediate = immediate;
return (0);
}
int
pcap_set_buffer_size(pcap_t *p, int buffer_size)
{
@ -606,6 +675,54 @@ pcap_set_buffer_size(pcap_t *p, int buffer_size)
return (0);
}
int
pcap_set_tstamp_precision(pcap_t *p, int tstamp_precision)
{
int i;
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
/*
* If p->tstamp_precision_count is 0, we only support setting
* the time stamp precision to microsecond precision; every
* pcap module *MUST* support microsecond precision, even if
* it does so by converting the native precision to
* microseconds.
*/
if (p->tstamp_precision_count == 0) {
if (tstamp_precision == PCAP_TSTAMP_PRECISION_MICRO) {
p->opt.tstamp_precision = tstamp_precision;
return (0);
}
} else {
/*
* Check whether we claim to support this precision of
* time stamp.
*/
for (i = 0; i < p->tstamp_precision_count; i++) {
if (p->tstamp_precision_list[i] == tstamp_precision) {
/*
* Yes.
*/
p->opt.tstamp_precision = tstamp_precision;
return (0);
}
}
}
/*
* We don't support this time stamp precision.
*/
return (PCAP_ERROR_TSTAMP_PRECISION_NOTSUP);
}
int
pcap_get_tstamp_precision(pcap_t *p)
{
return (p->opt.tstamp_precision);
}
int
pcap_activate(pcap_t *p)
{
@ -693,6 +810,27 @@ pcap_open_live(const char *source, int snaplen, int promisc, int to_ms, char *er
return (NULL);
}
pcap_t *
pcap_open_offline_common(char *ebuf, size_t size)
{
pcap_t *p;
p = pcap_alloc_pcap_t(ebuf, size);
if (p == NULL)
return (NULL);
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
p->opt.source = strdup("(savefile)");
if (p->opt.source == NULL) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
pcap_strerror(errno));
free(p);
return (NULL);
}
return (p);
}
int
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
@ -715,7 +853,7 @@ pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
register int n;
for (;;) {
if (p->sf.rfile != NULL) {
if (p->rfile != NULL) {
/*
* 0 means EOF, so don't loop if we get 0.
*/
@ -731,7 +869,7 @@ pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
if (n <= 0)
return (n);
if (cnt > 0) {
if (!PACKET_COUNT_IS_UNLIMITED(cnt)) {
cnt -= n;
if (cnt <= 0)
return (0);
@ -751,18 +889,24 @@ pcap_breakloop(pcap_t *p)
int
pcap_datalink(pcap_t *p)
{
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->linktype);
}
int
pcap_datalink_ext(pcap_t *p)
{
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->linktype_ext);
}
int
pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
{
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
if (p->dlt_count == 0) {
/*
* We couldn't fetch the list of DLTs, which means
@ -774,7 +918,7 @@ pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
if (*dlt_buffer == NULL) {
(void)snprintf(p->errbuf, sizeof(p->errbuf),
"malloc: %s", pcap_strerror(errno));
return (-1);
return (PCAP_ERROR);
}
**dlt_buffer = p->linktype;
return (1);
@ -783,7 +927,7 @@ pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
if (*dlt_buffer == NULL) {
(void)snprintf(p->errbuf, sizeof(p->errbuf),
"malloc: %s", pcap_strerror(errno));
return (-1);
return (PCAP_ERROR);
}
(void)memcpy(*dlt_buffer, p->dlt_list,
sizeof(**dlt_buffer) * p->dlt_count);
@ -1011,6 +1155,7 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS, "802.11 plus AVS radio information header"),
DLT_CHOICE(DLT_JUNIPER_MONITOR, "Juniper Passive Monitor PIC"),
DLT_CHOICE(DLT_BACNET_MS_TP, "BACnet MS/TP"),
DLT_CHOICE(DLT_PPP_PPPD, "PPP for pppd, with direction flag"),
DLT_CHOICE(DLT_JUNIPER_PPPOE, "Juniper PPPoE"),
DLT_CHOICE(DLT_JUNIPER_PPPOE_ATM, "Juniper PPPoE/ATM"),
@ -1048,6 +1193,7 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_AX25_KISS, "AX.25 with KISS header"),
DLT_CHOICE(DLT_IEEE802_15_4_NONASK_PHY, "IEEE 802.15.4 with non-ASK PHY data"),
DLT_CHOICE(DLT_MPLS, "MPLS with label as link-layer header"),
DLT_CHOICE(DLT_LINUX_EVDEV, "Linux evdev events"),
DLT_CHOICE(DLT_USB_LINUX_MMAPPED, "USB with padded Linux header"),
DLT_CHOICE(DLT_DECT, "DECT"),
DLT_CHOICE(DLT_AOS, "AOS Space Data Link protocol"),
@ -1059,15 +1205,33 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_IPV4, "Raw IPv4"),
DLT_CHOICE(DLT_IPV6, "Raw IPv6"),
DLT_CHOICE(DLT_IEEE802_15_4_NOFCS, "IEEE 802.15.4 without FCS"),
DLT_CHOICE(DLT_DBUS, "D-Bus"),
DLT_CHOICE(DLT_JUNIPER_VS, "Juniper Virtual Server"),
DLT_CHOICE(DLT_JUNIPER_SRX_E2E, "Juniper SRX E2E"),
DLT_CHOICE(DLT_JUNIPER_FIBRECHANNEL, "Juniper Fibre Channel"),
DLT_CHOICE(DLT_DVB_CI, "DVB-CI"),
DLT_CHOICE(DLT_MUX27010, "MUX27010"),
DLT_CHOICE(DLT_STANAG_5066_D_PDU, "STANAG 5066 D_PDUs"),
DLT_CHOICE(DLT_JUNIPER_ATM_CEMIC, "Juniper ATM CEMIC"),
DLT_CHOICE(DLT_NFLOG, "Linux netfilter log messages"),
DLT_CHOICE(DLT_NETANALYZER, "Ethernet with Hilscher netANALYZER pseudo-header"),
DLT_CHOICE(DLT_NETANALYZER_TRANSPARENT, "Ethernet with Hilscher netANALYZER pseudo-header and with preamble and SFD"),
DLT_CHOICE(DLT_IPOIB, "RFC 4391 IP-over-Infiniband"),
DLT_CHOICE(DLT_MPEG_2_TS, "MPEG-2 transport stream"),
DLT_CHOICE(DLT_NG40, "ng40 protocol tester Iub/Iur"),
DLT_CHOICE(DLT_NFC_LLCP, "NFC LLCP PDUs with pseudo-header"),
DLT_CHOICE(DLT_INFINIBAND, "InfiniBand"),
DLT_CHOICE(DLT_SCTP, "SCTP"),
DLT_CHOICE(DLT_USBPCAP, "USB with USBPcap header"),
DLT_CHOICE(DLT_RTAC_SERIAL, "Schweitzer Engineering Laboratories RTAC packets"),
DLT_CHOICE(DLT_BLUETOOTH_LE_LL, "Bluetooth Low Energy air interface"),
DLT_CHOICE(DLT_NETLINK, "Linux netlink"),
DLT_CHOICE(DLT_BLUETOOTH_LINUX_MONITOR, "Bluetooth Linux Monitor"),
DLT_CHOICE(DLT_BLUETOOTH_BREDR_BB, "Bluetooth Basic Rate/Enhanced Data Rate baseband packets"),
DLT_CHOICE(DLT_BLUETOOTH_LE_LL_WITH_PHDR, "Bluetooth Low Energy air interface with pseudo-header"),
DLT_CHOICE(DLT_PROFIBUS_DL, "PROFIBUS data link layer"),
DLT_CHOICE(DLT_PKTAP, "Apple DLT_PKTAP"),
DLT_CHOICE(DLT_EPON, "Ethernet with 802.3 Clause 65 EPON preamble"),
DLT_CHOICE_SENTINEL
};
@ -1162,31 +1326,39 @@ pcap_tstamp_type_val_to_description(int tstamp_type)
int
pcap_snapshot(pcap_t *p)
{
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->snapshot);
}
int
pcap_is_swapped(pcap_t *p)
{
return (p->sf.swapped);
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->swapped);
}
int
pcap_major_version(pcap_t *p)
{
return (p->sf.version_major);
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->version_major);
}
int
pcap_minor_version(pcap_t *p)
{
return (p->sf.version_minor);
if (!p->activated)
return (PCAP_ERROR_NOT_ACTIVATED);
return (p->version_minor);
}
FILE *
pcap_file(pcap_t *p)
{
return (p->sf.rfile);
return (p->rfile);
}
int
@ -1198,7 +1370,7 @@ pcap_fileno(pcap_t *p)
if (p->adapter != NULL)
return ((int)(DWORD)p->adapter->hFile);
else
return (-1);
return (PCAP_ERROR);
#endif
}
@ -1315,7 +1487,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf)
#ifdef WIN32
/*
* Generate a string for the last Win32-specific error (i.e. an error generated when
* Generate a string for the last Win32-specific error (i.e. an error generated when
* calling a Win32 API).
* For errors occurred during standard C calls, we still use pcap_strerror()
*/
@ -1397,6 +1569,9 @@ pcap_statustostr(int errnum)
case PCAP_ERROR_PROMISC_PERM_DENIED:
return ("You don't have permission to capture in promiscuous mode on that device");
case PCAP_ERROR_TSTAMP_PRECISION_NOTSUP:
return ("That device doesn't support that time stamp precision");
}
(void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
@ -1494,6 +1669,12 @@ pcap_setmintocopy(pcap_t *p, int size)
return (p->setmintocopy_op(p, size));
}
Adapter *
pcap_get_adapter(pcap_t *p)
{
return (p->getadapter_op(p));
}
static int
pcap_setmintocopy_dead(pcap_t *p, int size)
{
@ -1561,7 +1742,7 @@ pcap_do_addexit(pcap_t *p)
void
pcap_add_to_pcaps_to_close(pcap_t *p)
{
p->md.next = pcaps_to_close;
p->next = pcaps_to_close;
pcaps_to_close = p;
}
@ -1571,7 +1752,7 @@ pcap_remove_from_pcaps_to_close(pcap_t *p)
pcap_t *pc, *prevpc;
for (pc = pcaps_to_close, prevpc = NULL; pc != NULL;
prevpc = pc, pc = pc->md.next) {
prevpc = pc, pc = pc->next) {
if (pc == p) {
/*
* Found it. Remove it from the list.
@ -1580,12 +1761,12 @@ pcap_remove_from_pcaps_to_close(pcap_t *p)
/*
* It was at the head of the list.
*/
pcaps_to_close = pc->md.next;
pcaps_to_close = pc->next;
} else {
/*
* It was in the middle of the list.
*/
prevpc->md.next = pc->md.next;
prevpc->next = pc->next;
}
break;
}
@ -1609,6 +1790,11 @@ pcap_cleanup_live_common(pcap_t *p)
p->tstamp_type_list = NULL;
p->tstamp_type_count = 0;
}
if (p->tstamp_precision_list != NULL) {
free(p->tstamp_precision_list);
p->tstamp_precision_list = NULL;
p->tstamp_precision_count = 0;
}
pcap_freecode(&p->fcode);
#if !defined(WIN32) && !defined(MSDOS)
if (p->fd >= 0) {
@ -1616,7 +1802,6 @@ pcap_cleanup_live_common(pcap_t *p)
p->fd = -1;
}
p->selectable_fd = -1;
p->send_fd = -1;
#endif
}
@ -1627,16 +1812,26 @@ pcap_cleanup_dead(pcap_t *p _U_)
}
pcap_t *
pcap_open_dead(int linktype, int snaplen)
pcap_open_dead_with_tstamp_precision(int linktype, int snaplen, u_int precision)
{
pcap_t *p;
switch (precision) {
case PCAP_TSTAMP_PRECISION_MICRO:
case PCAP_TSTAMP_PRECISION_NANO:
break;
default:
return NULL;
}
p = malloc(sizeof(*p));
if (p == NULL)
return NULL;
memset (p, 0, sizeof(*p));
p->snapshot = snaplen;
p->linktype = linktype;
p->opt.tstamp_precision = precision;
p->stats_op = pcap_stats_dead;
#ifdef WIN32
p->setbuff_op = pcap_setbuff_dead;
@ -1648,6 +1843,13 @@ pcap_open_dead(int linktype, int snaplen)
return (p);
}
pcap_t *
pcap_open_dead(int linktype, int snaplen)
{
return (pcap_open_dead_with_tstamp_precision(linktype, snaplen,
PCAP_TSTAMP_PRECISION_MICRO));
}
/*
* API compatible with WinPcap's "send a packet" routine - returns -1
* on error, 0 otherwise.
@ -1693,7 +1895,7 @@ pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
{
const struct bpf_insn *fcode = fp->bf_insns;
if (fcode != NULL)
if (fcode != NULL)
return (bpf_filter(fcode, pkt, h->len, h->caplen));
else
return (0);
@ -1753,6 +1955,8 @@ pcap_lib_version(void)
strlen(pcap_version_string);
full_pcap_version_string =
malloc(full_pcap_version_string_len);
if (full_pcap_version_string == NULL)
return (NULL);
sprintf(full_pcap_version_string,
pcap_version_string_fmt, wpcap_version_string,
pcap_version_string);
@ -1770,7 +1974,8 @@ pcap_lib_version(void)
strlen(packet_version_string) +
strlen(pcap_version_string);
full_pcap_version_string = malloc(full_pcap_version_string_len);
if (full_pcap_version_string == NULL)
return (NULL);
sprintf(full_pcap_version_string,
pcap_version_string_packet_dll_fmt,
wpcap_version_string, packet_version_string,
@ -1799,6 +2004,8 @@ pcap_lib_version (void)
sizeof dospfx + strlen(pcap_version_string);
full_pcap_version_string =
malloc(full_pcap_version_string_len);
if (full_pcap_version_string == NULL)
return (NULL);
strcpy(full_pcap_version_string, dospfx);
strcat(full_pcap_version_string, pcap_version_string);
}

View File

@ -29,8 +29,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006-10-04 18:09:22 guy Exp $ (LBL)
*/
/*

View File

@ -29,20 +29,27 @@
*
* bluetooth data struct
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007-09-22 02:10:17 guy Exp $
*/
#ifndef _PCAP_BLUETOOTH_STRUCTS_H__
#define _PCAP_BLUETOOTH_STRUCTS_H__
/*
* Header prepended libpcap to each bluetooth h:4 frame.
* Header prepended libpcap to each bluetooth h4 frame,
* fields are in network byte order
*/
typedef struct _pcap_bluetooth_h4_header {
u_int32_t direction; /* if first bit is set direction is incoming */
} pcap_bluetooth_h4_header;
/*
* Header prepended libpcap to each bluetooth linux monitor frame,
* fields are in network byte order
*/
typedef struct _pcap_bluetooth_linux_monitor_header {
u_int16_t adapter_id;
u_int16_t opcode;
} pcap_bluetooth_linux_monitor_header;
#endif

View File

@ -36,8 +36,6 @@
* SUCH DAMAGE.
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/bpf.h,v 1.32 2008-12-23 20:13:29 guy Exp $ (LBL)
*/
/*
@ -1189,7 +1187,131 @@ struct bpf_program {
*/
#define DLT_SCTP 248
#define DLT_MATCHING_MAX 248 /* highest value in the "matching" range */
/*
* USB packets, beginning with a USBPcap header.
*
* Requested by Tomasz Mon <desowin@gmail.com>
*/
#define DLT_USBPCAP 249
/*
* Schweitzer Engineering Laboratories "RTAC" product serial-line
* packets.
*
* Requested by Chris Bontje <chris_bontje@selinc.com>.
*/
#define DLT_RTAC_SERIAL 250
/*
* Bluetooth Low Energy air interface link-layer packets.
*
* Requested by Mike Kershaw <dragorn@kismetwireless.net>.
*/
#define DLT_BLUETOOTH_LE_LL 251
/*
* DLT type for upper-protocol layer PDU saves from wireshark.
*
* the actual contents are determined by two TAGs stored with each
* packet:
* EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
* original packet.
*
* EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector
* that can make sense of the data stored.
*/
#define DLT_WIRESHARK_UPPER_PDU 252
/*
* DLT type for the netlink protocol (nlmon devices).
*/
#define DLT_NETLINK 253
/*
* Bluetooth Linux Monitor headers for the BlueZ stack.
*/
#define DLT_BLUETOOTH_LINUX_MONITOR 254
/*
* Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as
* captured by Ubertooth.
*/
#define DLT_BLUETOOTH_BREDR_BB 255
/*
* Bluetooth Low Energy link layer packets, as captured by Ubertooth.
*/
#define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256
/*
* PROFIBUS data link layer.
*/
#define DLT_PROFIBUS_DL 257
/*
* Apple's DLT_PKTAP headers.
*
* Sadly, the folks at Apple either had no clue that the DLT_USERn values
* are for internal use within an organization and partners only, and
* didn't know that the right way to get a link-layer header type is to
* ask tcpdump.org for one, or knew and didn't care, so they just
* used DLT_USER2, which causes problems for everything except for
* their version of tcpdump.
*
* So I'll just give them one; hopefully this will show up in a
* libpcap release in time for them to get this into 10.10 Big Sur
* or whatever Mavericks' successor is called. LINKTYPE_PKTAP
* will be 258 *even on OS X*; that is *intentional*, so that
* PKTAP files look the same on *all* OSes (different OSes can have
* different numerical values for a given DLT_, but *MUST NOT* have
* different values for what goes in a file, as files can be moved
* between OSes!).
*
* When capturing, on a system with a Darwin-based OS, on a device
* that returns 149 (DLT_USER2 and Apple's DLT_PKTAP) with this
* version of libpcap, the DLT_ value for the pcap_t will be DLT_PKTAP,
* and that will continue to be DLT_USER2 on Darwin-based OSes. That way,
* binary compatibility with Mavericks is preserved for programs using
* this version of libpcap. This does mean that if you were using
* DLT_USER2 for some capture device on OS X, you can't do so with
* this version of libpcap, just as you can't with Apple's libpcap -
* on OS X, they define DLT_PKTAP to be DLT_USER2, so programs won't
* be able to distinguish between PKTAP and whatever you were using
* DLT_USER2 for.
*
* If the program saves the capture to a file using this version of
* libpcap's pcap_dump code, the LINKTYPE_ value in the file will be
* LINKTYPE_PKTAP, which will be 258, even on Darwin-based OSes.
* That way, the file will *not* be a DLT_USER2 file. That means
* that the latest version of tcpdump, when built with this version
* of libpcap, and sufficiently recent versions of Wireshark will
* be able to read those files and interpret them correctly; however,
* Apple's version of tcpdump in OS X 10.9 won't be able to handle
* them. (Hopefully, Apple will pick up this version of libpcap,
* and the corresponding version of tcpdump, so that tcpdump will
* be able to handle the old LINKTYPE_USER2 captures *and* the new
* LINKTYPE_PKTAP captures.)
*/
#ifdef __APPLE__
#define DLT_PKTAP DLT_USER2
#else
#define DLT_PKTAP 258
#endif
/*
* Ethernet packets preceded by a header giving the last 6 octets
* of the preamble specified by 802.3-2012 Clause 65, section
* 65.1.3.2 "Transmit".
*/
#define DLT_EPON 259
/*
* IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format"
* in the PICMG HPM.2 specification.
*/
#define DLT_IPMI_HPM_2 260
#define DLT_MATCHING_MAX 260 /* highest value in the "matching" range */
/*
* DLT and savefile link type values are split into a class and
@ -1213,7 +1335,17 @@ struct bpf_program {
/*
* The instruction encodings.
*
* Please inform tcpdump-workers@lists.tcpdump.org if you use any
* of the reserved values, so that we can note that they're used
* (and perhaps implement it in the reference BPF implementation
* and encourage its implementation elsewhere).
*/
/*
* The upper 8 bits of the opcode aren't used. BSD/OS used 0x8000.
*/
/* instruction classes */
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
@ -1230,6 +1362,7 @@ struct bpf_program {
#define BPF_W 0x00
#define BPF_H 0x08
#define BPF_B 0x10
/* 0x18 reserved; used by BSD/OS */
#define BPF_MODE(code) ((code) & 0xe0)
#define BPF_IMM 0x00
#define BPF_ABS 0x20
@ -1237,6 +1370,8 @@ struct bpf_program {
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
/* 0xc0 reserved; used by BSD/OS */
/* 0xe0 reserved; used by BSD/OS */
/* alu/jmp fields */
#define BPF_OP(code) ((code) & 0xf0)
@ -1249,11 +1384,30 @@ struct bpf_program {
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_MOD 0x90
#define BPF_XOR 0xa0
/* 0xb0 reserved */
/* 0xc0 reserved */
/* 0xd0 reserved */
/* 0xe0 reserved */
/* 0xf0 reserved */
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
/* 0x50 reserved; used on BSD/OS */
/* 0x60 reserved */
/* 0x70 reserved */
/* 0x80 reserved */
/* 0x90 reserved */
/* 0xa0 reserved */
/* 0xb0 reserved */
/* 0xc0 reserved */
/* 0xd0 reserved */
/* 0xe0 reserved */
/* 0xf0 reserved */
#define BPF_SRC(code) ((code) & 0x08)
#define BPF_K 0x00
#define BPF_X 0x08
@ -1261,11 +1415,43 @@ struct bpf_program {
/* ret - BPF_K and BPF_X also apply */
#define BPF_RVAL(code) ((code) & 0x18)
#define BPF_A 0x10
/* 0x18 reserved */
/* misc */
#define BPF_MISCOP(code) ((code) & 0xf8)
#define BPF_TAX 0x00
/* 0x08 reserved */
/* 0x10 reserved */
/* 0x18 reserved */
/* #define BPF_COP 0x20 NetBSD "coprocessor" extensions */
/* 0x28 reserved */
/* 0x30 reserved */
/* 0x38 reserved */
/* #define BPF_COPX 0x40 NetBSD "coprocessor" extensions */
/* also used on BSD/OS */
/* 0x48 reserved */
/* 0x50 reserved */
/* 0x58 reserved */
/* 0x60 reserved */
/* 0x68 reserved */
/* 0x70 reserved */
/* 0x78 reserved */
#define BPF_TXA 0x80
/* 0x88 reserved */
/* 0x90 reserved */
/* 0x98 reserved */
/* 0xa0 reserved */
/* 0xa8 reserved */
/* 0xb0 reserved */
/* 0xb8 reserved */
/* 0xc0 reserved; used on BSD/OS */
/* 0xc8 reserved */
/* 0xd0 reserved */
/* 0xd8 reserved */
/* 0xe0 reserved */
/* 0xe8 reserved */
/* 0xf0 reserved */
/* 0xf8 reserved */
/*
* The instruction data structure.

View File

@ -29,8 +29,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/namedb.h,v 1.1 2006-10-04 18:09:22 guy Exp $ (LBL)
*/
#ifndef lib_pcap_namedb_h

View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, Petar Alilovic,
* Faculty of Electrical Engineering and Computing, University of Zagreb
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#ifndef _PCAP_NFLOG_H__
#define _PCAP_NFLOG_H__
/*
* Structure of an NFLOG header and TLV parts, as described at
* http://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html
*
* The NFLOG header is big-endian.
*
* The TLV length and type are in host byte order. The value is either
* big-endian or is an array of bytes in some externally-specified byte
* order (text string, link-layer address, link-layer header, packet
* data, etc.).
*/
typedef struct nflog_hdr {
u_int8_t nflog_family; /* address family */
u_int8_t nflog_version; /* version */
u_int16_t nflog_rid; /* resource ID */
} nflog_hdr_t;
typedef struct nflog_tlv {
u_int16_t tlv_length; /* tlv length */
u_int16_t tlv_type; /* tlv type */
/* value follows this */
} nflog_tlv_t;
typedef struct nflog_packet_hdr {
u_int16_t hw_protocol; /* hw protocol */
u_int8_t hook; /* netfilter hook */
u_int8_t pad; /* padding to 32 bits */
} nflog_packet_hdr_t;
typedef struct nflog_hwaddr {
u_int16_t hw_addrlen; /* address length */
u_int16_t pad; /* padding to 32-bit boundary */
u_int8_t hw_addr[8]; /* address, up to 8 bytes */
} nflog_hwaddr_t;
typedef struct nflog_timestamp {
u_int64_t sec;
u_int64_t usec;
} nflog_timestamp_t;
/*
* TLV types.
*/
#define NFULA_PACKET_HDR 1 /* nflog_packet_hdr_t */
#define NFULA_MARK 2 /* packet mark from skbuff */
#define NFULA_TIMESTAMP 3 /* nflog_timestamp_t for skbuff's time stamp */
#define NFULA_IFINDEX_INDEV 4 /* ifindex of device on which packet received (possibly bridge group) */
#define NFULA_IFINDEX_OUTDEV 5 /* ifindex of device on which packet transmitted (possibly bridge group) */
#define NFULA_IFINDEX_PHYSINDEV 6 /* ifindex of physical device on which packet received (not bridge group) */
#define NFULA_IFINDEX_PHYSOUTDEV 7 /* ifindex of physical device on which packet transmitted (not bridge group) */
#define NFULA_HWADDR 8 /* nflog_hwaddr_t for hardware address */
#define NFULA_PAYLOAD 9 /* packet payload */
#define NFULA_PREFIX 10 /* text string - null-terminated, count includes NUL */
#define NFULA_UID 11 /* UID owning socket on which packet was sent/received */
#define NFULA_SEQ 12 /* sequence number of packets on this NFLOG socket */
#define NFULA_SEQ_GLOBAL 13 /* sequence number of pakets on all NFLOG sockets */
#define NFULA_GID 14 /* GID owning socket on which packet was sent/received */
#define NFULA_HWTYPE 15 /* ARPHRD_ type of skbuff's device */
#define NFULA_HWHEADER 16 /* skbuff's MAC-layer header */
#define NFULA_HWLEN 17 /* length of skbuff's MAC-layer header */
#endif

View File

@ -30,8 +30,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.15 2008-10-06 15:27:32 gianluca Exp $ (LBL)
*/
#ifndef lib_pcap_pcap_h
@ -113,7 +111,7 @@ typedef struct pcap_addr pcap_addr_t;
*
* Then supply the changes by forking the branch at
*
* https://github.com/mcr/libpcap/issues
* https://github.com/the-tcpdump-group/libpcap/issues
*
* and issuing a pull request, so that future versions of libpcap and
* programs that use it (such as tcpdump) will be able to read your new
@ -131,7 +129,7 @@ struct pcap_file_header {
/*
* Macros for the value returned by pcap_datalink_ext().
*
*
* If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
* gives the FCS length of packets in the capture.
*/
@ -220,6 +218,8 @@ struct pcap_if {
};
#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
#define PCAP_IF_UP 0x00000002 /* interface is up */
#define PCAP_IF_RUNNING 0x00000004 /* interface is running */
/*
* Representation of an interface address.
@ -252,6 +252,7 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */
#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */
#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */
/*
* Warning codes for the pcap API.
@ -278,7 +279,10 @@ int pcap_can_set_rfmon(pcap_t *);
int pcap_set_rfmon(pcap_t *, int);
int pcap_set_timeout(pcap_t *, int);
int pcap_set_tstamp_type(pcap_t *, int);
int pcap_set_immediate_mode(pcap_t *, int);
int pcap_set_buffer_size(pcap_t *, int);
int pcap_set_tstamp_precision(pcap_t *, int);
int pcap_get_tstamp_precision(pcap_t *);
int pcap_activate(pcap_t *);
int pcap_list_tstamp_types(pcap_t *, int **);
@ -331,18 +335,34 @@ const char *pcap_tstamp_type_val_to_description(int);
#define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */
#define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */
/*
* Time stamp resolution types.
* Not all systems and interfaces will necessarily support all of these
* resolutions when doing live captures; all of them can be requested
* when reading a savefile.
*/
#define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */
#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */
pcap_t *pcap_open_live(const char *, int, int, int, char *);
pcap_t *pcap_open_dead(int, int);
pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
pcap_t *pcap_open_offline(const char *, char *);
#if defined(WIN32)
pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
pcap_t *pcap_hopen_offline(intptr_t, char *);
#if !defined(LIBPCAP_EXPORTS)
#define pcap_fopen_offline_with_tstamp_precision(f,p,b) \
pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b)
#define pcap_fopen_offline(f,b) \
pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
#else /*LIBPCAP_EXPORTS*/
static pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
static pcap_t *pcap_fopen_offline(FILE *, char *);
#endif
#else /*WIN32*/
pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
pcap_t *pcap_fopen_offline(FILE *, char *);
#endif /*WIN32*/
@ -424,6 +444,7 @@ void bpf_dump(const struct bpf_program *, int);
int pcap_setbuff(pcap_t *p, int dim);
int pcap_setmode(pcap_t *p, int mode);
int pcap_setmintocopy(pcap_t *p, int size);
Adapter *pcap_get_adapter(pcap_t *p);
#ifdef WPCAP
/* Include file with the wpcap-specific extensions */

View File

@ -34,8 +34,6 @@
* 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/sll.h,v 1.3 2008-05-30 01:35:33 guy Exp $ (LBL)
*/
/*

Some files were not shown because too many files have changed in this diff Show More