Build libpcap-0.9.4 from src/dist.
While there are some open issues, particulary wrt support of old NetBSD-specific interfaces, it is better to get the code some public testing before NetBSD-4 is branched.
This commit is contained in:
parent
313c1811bf
commit
741f357fc1
@ -1,4 +1,4 @@
|
||||
# $NetBSD: shl.elf,v 1.111 2006/03/30 00:00:23 rtr Exp $
|
||||
# $NetBSD: shl.elf,v 1.112 2006/04/25 18:36:44 drochner Exp $
|
||||
# Note: libtermcap and libtermlib are hardlinked and share the same version.
|
||||
./lib/libc.so base-sys-shlib
|
||||
./lib/libc.so.12 base-sys-shlib
|
||||
@ -130,7 +130,7 @@
|
||||
./usr/lib/libpam.so base-sys-shlib pam
|
||||
./usr/lib/libpam.so.0 base-sys-shlib pam
|
||||
./usr/lib/libpcap.so base-net-shlib
|
||||
./usr/lib/libpcap.so.1 base-net-shlib
|
||||
./usr/lib/libpcap.so.2 base-net-shlib
|
||||
./usr/lib/libpci.so base-sys-shlib
|
||||
./usr/lib/libpci.so.1 base-sys-shlib
|
||||
./usr/lib/libposix.so base-sys-shlib
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: shl.mi,v 1.350 2006/04/17 23:31:24 salo Exp $
|
||||
# $NetBSD: shl.mi,v 1.351 2006/04/25 18:36:44 drochner Exp $
|
||||
# Note: libtermcap and libtermlib are hardlinked and share the same version.
|
||||
./lib/libc.so.12.140 base-sys-shlib
|
||||
./lib/libcrypt.so.0.2 base-sys-shlib
|
||||
@ -67,7 +67,7 @@
|
||||
./usr/lib/libmenu.so.5.0 base-sys-shlib
|
||||
./usr/lib/libossaudio.so.0.0 base-sys-shlib
|
||||
./usr/lib/libpam.so.0.0 base-sys-shlib pam
|
||||
./usr/lib/libpcap.so.1.5 base-net-shlib
|
||||
./usr/lib/libpcap.so.2.0 base-net-shlib
|
||||
./usr/lib/libpci.so.1.0 base-sys-shlib
|
||||
./usr/lib/libposix.so.0.1 base-sys-shlib
|
||||
./usr/lib/libpthread.so.0.6 base-sys-shlib
|
||||
|
@ -1,387 +0,0 @@
|
||||
$NetBSD: CHANGES,v 1.5 2004/09/27 23:02:53 dyoung Exp $
|
||||
@(#) Header: /tcpdump/master/libpcap/CHANGES,v 1.56.4.3 2004/03/30 14:29:16 mcr Exp (LBL)
|
||||
|
||||
Tue. March 30, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.3 release
|
||||
|
||||
Fixed minor problem in gencode.c that would appear on 64-bit
|
||||
platforms.
|
||||
Version number is now sane.
|
||||
|
||||
Mon. March 29, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.2 release
|
||||
|
||||
updates for autoconf 2.5
|
||||
fixes for ppp interfaces for freebsd 4.1
|
||||
pcap gencode can generate code for 802.11, IEEE1394, and pflog.
|
||||
|
||||
Wed. November 12, 2003. mcr@sandelman.ottawa.on.ca. Summary for 0.8 release
|
||||
|
||||
added pcap_findalldevs()
|
||||
Win32 patches from NetGroup, Politecnico di Torino (Italy)
|
||||
OpenBSD pf, DLT_PFLOG added
|
||||
Many changes to ATM support.
|
||||
lookup pcap_lookupnet()
|
||||
Added DLT_ARCNET_LINUX, DLT_ENC, DLT_IEEE802_11_RADIO, DLT_SUNATM,
|
||||
DLT_IP_OVER_FC, DLT_FRELAY, others.
|
||||
Sigh. More AIX wonderfulness.
|
||||
Document updates.
|
||||
Changes to API: pcap_next_ex(), pcap_breakloop(), pcap_dump_flush(),
|
||||
pcap_list_datalinks(), pcap_set_datalink(),
|
||||
pcap_lib_version(), pcap_datalink_val_to_name(),
|
||||
pcap_datalink_name_to_val(), new error returns.
|
||||
|
||||
Tuesday, February 25, 2003. fenner@research.att.com. 0.7.2 release
|
||||
|
||||
Support link types that use 802.2 always, never, and sometimes.
|
||||
Don't decrease the size of the BPF buffer from the default.
|
||||
Support frame relay.
|
||||
Handle 32-bit timestamps in DLPI, and pass the right buffer size.
|
||||
Handle Linux systems with modern kernel but without
|
||||
SOL_PACKET in the userland headers.
|
||||
Linux support for ARPHRD_RAWHDLC.
|
||||
Handle 32-bit timestamps in snoop.
|
||||
Support eg (Octane/O2xxx/O3xxx Gigabit) devices.
|
||||
Add new reserved DLT types.
|
||||
|
||||
Monday October 23, 2001. mcr@sandelman.ottawa.on.ca. Summary for 0.7 release
|
||||
|
||||
Added pcap_findalldevs() call to get list of interfaces in a MI way.
|
||||
|
||||
pcap_stats() has been documented as to what its counters mean on
|
||||
each platform.
|
||||
|
||||
Tuesday January 9, 2001. guy@alum.mit.edu. Summary for 0.6 release
|
||||
|
||||
New Linux libpcap implementation, which, in 2.2 and later
|
||||
kernels, uses PF_PACKET sockets and supports kernel packet
|
||||
filtering (if compiled into the kernel), and supports the "any"
|
||||
device for capturing on all interfaces. Cleans up promiscuous
|
||||
mode better on pre-2.2 kernels, and has various other fixes
|
||||
(handles 2.4 ARPHRD_IEEE802_TR, handles ISDN devices better,
|
||||
doesn't show duplicate packets on loopback interface, etc.).
|
||||
|
||||
Fixed HP-UX libpcap implementation to correctly get the PPA for
|
||||
an interface, to allow interfaces to be opened by interface name.
|
||||
|
||||
libpcap savefiles have system-independent link-layer type values
|
||||
in the header, rather than sometimes platform-dependent DLT_
|
||||
values, to make it easier to exchange capture files between
|
||||
different OSes.
|
||||
|
||||
Non-standard capture files produced by some Linux tcpdumps, e.g.
|
||||
the one from Red Hat Linux 6.2 and later, can now be read.
|
||||
|
||||
Updated autoconf stock files.
|
||||
|
||||
Filter expressions can filter on VLAN IDs and various OSI
|
||||
protocols, and work on Token Ring (with non-source-routed
|
||||
packets).
|
||||
|
||||
"pcap_open_dead()" added to allow compiling filter expressions
|
||||
to pcap code without opening a capture device or capture file.
|
||||
|
||||
Header files fixed to allow use in C++ programs.
|
||||
|
||||
Removed dependancy on native headers for packet layout.
|
||||
Removed Linux specific headers that were shipped.
|
||||
|
||||
Security fixes: Strcpy replaced with strlcpy, sprintf replaced
|
||||
with snprintf.
|
||||
|
||||
Fixed bug that could cause subsequent "pcap_compile()"s to fail
|
||||
erroneously after one compile failed.
|
||||
|
||||
Assorted other bug fixes.
|
||||
|
||||
README.aix and README.linux files added to describe
|
||||
platform-specific issues.
|
||||
|
||||
"getifaddrs()" rather than SIOCGIFCONF used, if available.
|
||||
|
||||
v0.5 Sat Jun 10 11:09:15 PDT 2000
|
||||
|
||||
itojun@iijlab.net
|
||||
- Brought in KAME IPv6/IPsec bpf compiler.
|
||||
- Fixes for NetBSD.
|
||||
- Support added for OpenBSD DLT_LOOP and BSD/OS DLT_C_HDLC (Cisco HDLC),
|
||||
and changes to work around different BSDs having different DLT_ types
|
||||
with the same numeric value.
|
||||
|
||||
Assar Westerlund <assar@sics.se>
|
||||
- Building outside the source code tree fixed.
|
||||
- Changed to write out time stamps with 32-bit seconds and microseconds
|
||||
fields, regardless of whether those fields are 32 bits or 64 bits in
|
||||
the OS's native "struct timeval".
|
||||
- Changed "pcap_lookupdev()" to dynamically grow the buffer into which
|
||||
the list of interfaces is read as necessary in order to hold the
|
||||
entire list.
|
||||
|
||||
Greg Troxel <gdt@ir.bbn.com>
|
||||
- Added a new "pcap_compile_nopcap()", which lets you compile a filter
|
||||
expression into a BPF program without having an open live capture or
|
||||
capture file.
|
||||
|
||||
v0.4 Sat Jul 25 12:40:09 PDT 1998
|
||||
|
||||
- Fix endian problem with DLT_NULL devices. From FreeBSD via Bill
|
||||
Fenner (fenner@parc.xerox.com)
|
||||
|
||||
- Fix alignment problem with FDDI under DLPI. This was causing core
|
||||
dumps under Solaris.
|
||||
|
||||
- Added configure options to disable flex and bison. Resulted from a
|
||||
bug report by barnett@grymoire.crd.ge.com (Bruce Barnett). Also added
|
||||
options to disable gcc and to force a particular packet capture type.
|
||||
|
||||
- Added support for Fore ATM interfaces (qaa and fa) under IRIX. Thanks
|
||||
to John Hawkinson (jhawk@mit.edu)
|
||||
|
||||
- Change Linux PPP and SLIP to use DLT_RAW since the kernel does not
|
||||
supply any "link layer" data.
|
||||
|
||||
- Change Linux to use SIOCGIFHWADDR ioctl to determine link layer type.
|
||||
Thanks to Thomas Sailer (sailer@ife.ee.ethz.ch)
|
||||
|
||||
- Change IRIX PPP to use DLT_RAW since the kernel does not supply any
|
||||
"link layer" data.
|
||||
|
||||
- Modified to support the new BSD/OS 2.1 PPP and SLIP link layer header
|
||||
formats.
|
||||
|
||||
- Added some new SGI snoop interface types. Thanks to Steve Alexander
|
||||
(sca@refugee.engr.sgi.com)
|
||||
|
||||
- Fixes for HP-UX 10.20 (which is similar to HP-UX 9). Thanks to
|
||||
Richard Allen (ra@hp.is) and Steinar Haug (sthaug@nethelp.no)
|
||||
|
||||
- Fddi supports broadcast as reported by Jeff Macdonald
|
||||
(jeff@iacnet.com). Also correct ieee802 and arcnet.
|
||||
|
||||
- Determine Linux pcap buffer size at run time or else it might not be
|
||||
big enough for some interface types (e.g. FDDI). Thanks to Jes
|
||||
Sorensen (Jes.Sorensen@cern.ch)
|
||||
|
||||
- Fix some linux alignment problems.
|
||||
|
||||
- Document promisc argument to pcap_open_live(). Reported by Ian Marsh
|
||||
(ianm@sics.se)
|
||||
|
||||
- Support Metricom radio packets under Linux. Thanks to Kevin Lai
|
||||
(laik@gunpowder.stanford.edu)
|
||||
|
||||
- Bind to interface name under Linux to avoid packets from multiple
|
||||
interfaces on multi-homed hosts. Thanks to Kevin Lai
|
||||
(laik@gunpowder.stanford.edu)
|
||||
|
||||
- Change L_SET to SEEK_SET for HP-UX. Thanks to Roland Roberts
|
||||
(rroberts@muller.com)
|
||||
|
||||
- Fixed an uninitialized memory reference found by Kent Vander Velden
|
||||
(graphix@iastate.edu)
|
||||
|
||||
- Fixed lex pattern for IDs to allow leading digits. As reported by
|
||||
Theo de Raadt (deraadt@cvs.openbsd.org)
|
||||
|
||||
- Fixed Linux include file problems when using GNU libc.
|
||||
|
||||
- Ifdef ARPHRD_FDDI since not all versions of the Linux kernel have it.
|
||||
Reported reported by Eric Jacksch (jacksch@tenebris.ca)
|
||||
|
||||
- Fixed bug in pcap_dispatch() that kept it from returning on packet
|
||||
timeouts.
|
||||
|
||||
- Changed ISLOOPBACK() macro when IFF_LOOPBACK isn't available to check
|
||||
for "lo" followed by an eos or digit (newer versions of Linux
|
||||
apparently call the loopback "lo" instead of "lo0").
|
||||
|
||||
- Fixed Linux networking include files to use ints instead of longs to
|
||||
avoid problems with 64 bit longs on the alpha. Thanks to Cristian
|
||||
Gafton (gafton@redhat.com)
|
||||
|
||||
v0.3 Sat Nov 30 20:56:27 PST 1996
|
||||
|
||||
- Added Linux support.
|
||||
|
||||
- Fixed savefile bugs.
|
||||
|
||||
- Solaris x86 fix from Tim Rylance (t.rylance@elsevier.nl)
|
||||
|
||||
- Add support for bpf kernel port filters.
|
||||
|
||||
- Remove duplicate atalk protocol table entry. Thanks to Christian
|
||||
Hopps (chopps@water.emich.edu)
|
||||
|
||||
- Fixed pcap_lookupdev() to ignore nonexistent devices. This was
|
||||
reported to happen under BSD/OS by David Vincenzetti
|
||||
(vince@cryptonet.it)
|
||||
|
||||
- Avoid solaris compiler warnings. Thanks to Bruce Barnett
|
||||
(barnett@grymoire.crd.ge.com)
|
||||
|
||||
v0.2.1 Sun Jul 14 03:02:26 PDT 1996
|
||||
|
||||
- Fixes for HP-UX 10. Thanks in part to to Thomas Wolfram
|
||||
(wolf@prz.tu-berlin.de) and Rick Jones (raj@hpisrdq.cup.hp.com)
|
||||
|
||||
- Added support for SINIX. Thanks to Andrej Borsenkow
|
||||
(borsenkow.msk@sni.de)
|
||||
|
||||
- Fixes for AIX (although this system is not yet supported). Thanks to
|
||||
John Hawkinson (jhawk@mit.edu)
|
||||
|
||||
- Use autoconf's idea of the top level directory in install targets.
|
||||
Thanks to John Hawkinson.
|
||||
|
||||
- Add missing autoconf packet capture result message. Thanks to Bill
|
||||
Fenner (fenner@parc.xerox.com)
|
||||
|
||||
- Fixed padding problems in the pf module.
|
||||
|
||||
- Fixed some more alignment problems on the alpha.
|
||||
|
||||
- Added explicit netmask support. Thanks to Steve Nuchia
|
||||
(steve@research.oknet.com)
|
||||
|
||||
- Fixed to handle raw ip addresses such as 0.0.0.1 without "left
|
||||
justifing"
|
||||
|
||||
- Add "sca" keyword (for DEC cluster services) as suggested by Terry
|
||||
Kennedy (terry@spcvxa.spc.edu)
|
||||
|
||||
- Add "atalk" keyword as suggested by John Hawkinson.
|
||||
|
||||
- Add "igrp" keyword.
|
||||
|
||||
- Fixed HID definition in grammar.y to be a string, not a value.
|
||||
|
||||
- Use $CC when checking gcc version. Thanks to Carl Lindberg
|
||||
(carl_lindberg@blacksmith.com)
|
||||
|
||||
- Removed obsolete reference to pcap_immediate() from the man page.
|
||||
Michael Stolarchuk (mts@terminator.rs.itd.umich.edu)
|
||||
|
||||
- DLT_NULL has a 4 byte family header. Thanks to Jeffrey Honig
|
||||
(jch@bsdi.com)
|
||||
|
||||
v0.2 Sun Jun 23 02:28:42 PDT 1996
|
||||
|
||||
- Add support for HP-UX. Resulted from code contributed by Tom Murray
|
||||
(tmurray@hpindck.cup.hp.com) and Philippe-Andri Prindeville
|
||||
(philipp@res.enst.fr)
|
||||
|
||||
- Update INSTALL with a reminder to install include files. Thanks to
|
||||
Mark Andrews (mandrews@aw.sgi.com)
|
||||
|
||||
- Fix bpf compiler alignment bug on the alpha.
|
||||
|
||||
- Use autoconf to detect architectures that can't handle misaligned
|
||||
accesses.
|
||||
|
||||
- Added loopback support for snoop. Resulted from report Steve
|
||||
Alexander (sca@engr.sgi.com)
|
||||
|
||||
v0.1 Fri Apr 28 18:11:03 PDT 1995
|
||||
|
||||
- Fixed compiler and optimizer bugs. The BPF filter engine uses unsigned
|
||||
comparison operators, while the code generator and optimizer assumed
|
||||
signed semantics in several places. Thanks to Charlie Slater
|
||||
(cslater@imatek.com) for pointing this out.
|
||||
|
||||
- Removed FDDI ifdef's, they aren't really needed. Resulted from report
|
||||
by Gary Veum (veum@boa.gsfc.nasa.gov).
|
||||
|
||||
- Add pcap-null.c which allows offline use of libpcap on systems that
|
||||
don't support live package capture. This feature resulting from a
|
||||
request from Jan van Oorschot (j.p.m.voorschot@et.tudelft.nl).
|
||||
|
||||
- Make bpf_compile() reentrant. Fix thanks to Pascal Hennequin
|
||||
(Pascal.Hennequin@hugo.int-evry.fr).
|
||||
|
||||
- Port to GNU autoconf.
|
||||
|
||||
- Fix pcap-dlpi.c to work with isdn. Resulted from report by Flemming
|
||||
Johansen (fsj@csd.cri.dk).
|
||||
|
||||
- Handle multi-digit interface unit numbers (aka ppa's) under dlpi.
|
||||
Resulted from report by Daniel Ehrlich (ehrlich@cse.psu.edu).
|
||||
|
||||
- Fix pcap-dlpi.c to work in non-promiscuous mode. Resulted from report
|
||||
by Jeff Murphy (jcmurphy@acsu.buffalo.edu).
|
||||
|
||||
- Add support for "long jumps". Thanks to Jeffrey Mogul
|
||||
(mogul@pa.dec.com).
|
||||
|
||||
- Fix minor problems when compiling with BDEBUG as noticed by Scott
|
||||
Bertilson (scott@unet.umn.edu).
|
||||
|
||||
- Declare sys_errlist "const char *const" to avoid problems under
|
||||
FreeBSD. Resulted from report by jher@eden.com.
|
||||
|
||||
v0.0.6 Fri Apr 28 04:07:13 PDT 1995
|
||||
|
||||
- Add missing variable declaration missing from 0.0.6
|
||||
|
||||
v0.0.5 Fri Apr 28 00:22:21 PDT 1995
|
||||
|
||||
- Workaround for problems when pcap_read() returns 0 due to the timeout
|
||||
expiring.
|
||||
|
||||
v0.0.4 Thu Apr 20 20:41:48 PDT 1995
|
||||
|
||||
- Change configuration to not use gcc v2 flags with gcc v1.
|
||||
|
||||
- Fixed a bug in pcap_next(); if pcap_dispatch() returns 0, pcap_next()
|
||||
should also return 0. Thanks to Richard Stevens (rstevens@noao.edu).
|
||||
|
||||
- Fixed configure to test for snoop before dlpi to avoid problems under
|
||||
IRIX 5. Thanks to J. Eric Townsend (jet@abulafia.genmagic.com).
|
||||
|
||||
- Hack around deficiency in Ultrix's make.
|
||||
|
||||
- Fix two bugs related to the Solaris pre-5.3.2 bufmod bug; handle
|
||||
savefiles that have more than snapshot bytes of data in them (so we
|
||||
can read old savefiles) and avoid writing such files.
|
||||
|
||||
- Added checkioctl which is used with gcc to check that the
|
||||
"fixincludes" script has been run.
|
||||
|
||||
v0.0.3 Tue Oct 18 18:13:46 PDT 1994
|
||||
|
||||
- Fixed configure to test for snoop before dlpi to avoid problems under
|
||||
IRIX 5. Thanks to J. Eric Townsend (jet@abulafia.genmagic.com).
|
||||
|
||||
v0.0.2 Wed Oct 12 20:56:37 PDT 1994
|
||||
|
||||
- Implement timeout in the dlpi pcap_open_live(). Thanks to Richard
|
||||
Stevens.
|
||||
|
||||
- Determine pcap link type from dlpi media type. Resulted from report
|
||||
by Mahesh Jethanandani (mahesh@npix.com).
|
||||
|
||||
v0.0.1 Fri Jun 24 14:50:57 PDT 1994
|
||||
|
||||
- Fixed bug in nit_setflags() in pcap-snit.c. The streams ioctl timeout
|
||||
wasn't being initialized sometimes resulting in an "NIOCSFLAGS:
|
||||
Invalid argument" error under OSF/1. Reported by Matt Day
|
||||
(mday@artisoft.com) and Danny Mitzel (dmitzel@whitney.hitc.com).
|
||||
|
||||
- Turn on FDDI support by default.
|
||||
|
||||
v0.0 Mon Jun 20 19:20:16 PDT 1994
|
||||
|
||||
- Initial release.
|
||||
|
||||
- Fixed bug with greater/less keywords, reported by Mark Andrews
|
||||
(mandrews@alias.com).
|
||||
|
||||
- Fix bug where '|' was defined as BPF_AND instead of BPF_OR, reported
|
||||
by Elan Amir (elan@leeb.cs.berkeley.edu).
|
||||
|
||||
- Machines with little-endian byte ordering are supported thanks to
|
||||
Jeff Mogul.
|
||||
|
||||
- Add hack for version 2.3 savefiles which don't have caplen and len
|
||||
swapped thanks to Vern Paxson.
|
||||
|
||||
- Added "&&" and "||" aliases for "and" and "or" thanks to Vern Paxson.
|
||||
|
||||
- Added length, inbound and outbound keywords.
|
@ -1,39 +1,43 @@
|
||||
# $NetBSD: Makefile,v 1.27 2005/01/10 02:58:58 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.28 2006/04/25 18:36:44 drochner Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
LIB= pcap
|
||||
MAN= pcap.3
|
||||
SRCDIR= ${NETBSDSRCDIR}/dist/libpcap
|
||||
.PATH: ${SRCDIR}
|
||||
|
||||
WARNS?= 1
|
||||
LIB= pcap
|
||||
MAN= pcap.3
|
||||
|
||||
CPPFLAGS+=-I. -I${.CURDIR} -I${NETBSDSRCDIR}/sys/dist/pf -DYYBISON
|
||||
CPPFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_IOCCOM_H=1 -DHAVE_SYS_SOCKIO_H=1
|
||||
CPPFLAGS+=-DHAVE_NETINET_IF_ETHER_H
|
||||
CPPFLAGS+=-DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_SOCKADDR_SA_LEN=1
|
||||
CPPFLAGS+=-DHAVE_IFADDRS_H=1 -DHAVE_LIMITS_H=1
|
||||
CPPFLAGS+=-DHAVE_SNPRINTF=1 -DHAVE_STRLCPY=1 -DHAVE_VSNPRINTF=1
|
||||
# used in no place
|
||||
#CPPFLAGS+=-DLBL_ALIGN=1
|
||||
LPREFIX=pcap_
|
||||
YPREFIX=pcap_
|
||||
YHEADER=1
|
||||
WARNS?= 3
|
||||
|
||||
CPPFLAGS+= -I${.CURDIR} -I. -I${SRCDIR}
|
||||
CPPFLAGS+= -DYYBISON
|
||||
LPREFIX= pcap_
|
||||
YPREFIX= pcap_
|
||||
YHEADER= 1
|
||||
|
||||
CPPFLAGS+= -DHAVE_CONFIG_H
|
||||
CPPFLAGS+= -D_U_="__attribute__((unused))"
|
||||
|
||||
.if (${USE_INET6} != "no")
|
||||
CPPFLAGS+=-DINET6
|
||||
CPPFLAGS+= -DINET6
|
||||
.endif
|
||||
|
||||
SRCS= scanner.l savefile.c pcap.c pcap-bpf.c optimize.c nametoaddr.c \
|
||||
inet.c grammar.y gencode.c fad-getad.c etherent.c bpf_image.c \
|
||||
bpf_dump.c
|
||||
SRCS+= bpf_filter.c version.c
|
||||
inet.c grammar.y gencode.c fad-getad.c etherent.c bpf_image.c \
|
||||
bpf_dump.c
|
||||
|
||||
.PATH: ${NETBSDSRCDIR}/sys/net
|
||||
SRCS+= bpf_filter.c
|
||||
|
||||
INCS= pcap-namedb.h pcap.h
|
||||
INCSDIR=/usr/include
|
||||
INCS= pcap-namedb.h pcap.h
|
||||
INCSDIR= /usr/include
|
||||
|
||||
# XXX -dcy
|
||||
scanner.c: grammar.h
|
||||
scanner.d scanner.o: tokdefs.h
|
||||
|
||||
tokdefs.h: grammar.h
|
||||
cp $? $@
|
||||
|
||||
CLEANFILES+= tokdefs.h
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
@ -1,95 +0,0 @@
|
||||
$NetBSD: README,v 1.6 2004/09/27 23:02:53 dyoung Exp $
|
||||
@(#) Header: /tcpdump/master/libpcap/README,v 1.27.2.1 2003/11/15 23:29:19 guy Exp (LBL)
|
||||
|
||||
LIBPCAP 0.8
|
||||
Now maintained by "The Tcpdump Group"
|
||||
See www.tcpdump.org
|
||||
|
||||
Please send inquiries/comments/reports to tcpdump-workers@tcpdump.org
|
||||
|
||||
Anonymous CVS is available via:
|
||||
cvs -d :pserver:tcpdump@cvs.tcpdump.org:/tcpdump/master login
|
||||
(password "anoncvs")
|
||||
cvs -d :pserver:tcpdump@cvs.tcpdump.org:/tcpdump/master checkout libpcap
|
||||
|
||||
Version 0.8 of LIBPCAP can be retrieved with the CVS tag "libpcap_0_8rel1":
|
||||
cvs -d :pserver:tcpdump@cvs.tcpdump.org:/tcpdump/master checkout -r libpcap_0_8rel1 libpcap
|
||||
|
||||
Please send patches against the master copy to patches@tcpdump.org.
|
||||
|
||||
formerly from Lawrence Berkeley National Laboratory
|
||||
Network Research Group <libpcap@ee.lbl.gov>
|
||||
ftp://ftp.ee.lbl.gov/libpcap.tar.Z (0.4)
|
||||
|
||||
This directory contains source code for libpcap, a system-independent
|
||||
interface for user-level packet capture. libpcap provides a portable
|
||||
framework for low-level network monitoring. Applications include
|
||||
network statistics collection, security monitoring, network debugging,
|
||||
etc. Since almost every system vendor provides a different interface
|
||||
for packet capture, and since we've developed several tools that
|
||||
require this functionality, we've created this system-independent API
|
||||
to ease in porting and to alleviate the need for several
|
||||
system-dependent packet capture modules in each application.
|
||||
|
||||
Note well: this interface is new and is likely to change.
|
||||
|
||||
For some platforms there are README.{system} files that discuss issues
|
||||
with the OS's interface for packet capture on those platforms, such as
|
||||
how to enable support for that interface in the OS, if it's not built in
|
||||
by default.
|
||||
|
||||
The libpcap interface supports a filtering mechanism based on the
|
||||
architecture in the BSD packet filter. BPF is described in the 1993
|
||||
Winter Usenix paper ``The BSD Packet Filter: A New Architecture for
|
||||
User-level Packet Capture''. A compressed PostScript version can be
|
||||
found at
|
||||
|
||||
ftp://ftp.ee.lbl.gov/papers/bpf-usenix93.ps.Z
|
||||
|
||||
or
|
||||
|
||||
http://www.tcpdump.org/papers/bpf-usenix93.ps.Z
|
||||
|
||||
and a gzipped version can be found at
|
||||
|
||||
http://www.tcpdump.org/papers/bpf-usenix93.ps.gz
|
||||
|
||||
A PDF version can be found at
|
||||
|
||||
http://www.tcpdump.org/papers/bpf-usenix93.pdf
|
||||
|
||||
Although most packet capture interfaces support in-kernel filtering,
|
||||
libpcap uses in-kernel filtering only for the BPF interface.
|
||||
On systems that don't have BPF, all packets are read into user-space
|
||||
and the BPF filters are evaluated in the libpcap library, incurring
|
||||
added overhead (especially, for selective filters). Ideally, libpcap
|
||||
would translate BPF filters into a filter program that is compatible
|
||||
with the underlying kernel subsystem, but this is not yet implemented.
|
||||
|
||||
BPF is standard in 4.4BSD, BSD/OS, NetBSD, FreeBSD, and OpenBSD. DEC
|
||||
OSF/1/Digital UNIX/Tru64 UNIX uses the packetfilter interface but has
|
||||
been extended to accept BPF filters (which libpcap utilizes). Also, you
|
||||
can add BPF filter support to Ultrix using the kernel source and/or
|
||||
object patches available in:
|
||||
|
||||
ftp://gatekeeper.dec.com/pub/DEC/net/bpfext42.tar.Z.
|
||||
|
||||
Linux, in the 2.2 kernel and later kernels, has a "Socket Filter"
|
||||
mechanism that accepts BPF filters; see the README.linux file for
|
||||
information on configuring that option.
|
||||
|
||||
Problems, bugs, questions, desirable enhancements, etc. should be sent
|
||||
to the address "tcpdump-workers@tcpdump.org". Bugs, support requests,
|
||||
and feature requests may also be submitted on the SourceForge site for
|
||||
libpcap at
|
||||
|
||||
http://sourceforge.net/projects/libpcap/
|
||||
|
||||
Source code contributions, etc. should be sent to the email address
|
||||
"patches@tcpdump.org", or submitted as patches on the SourceForge site
|
||||
for libpcap.
|
||||
|
||||
Current versions can be found at www.tcpdump.org, or the SourceForge
|
||||
site for libpcap.
|
||||
|
||||
- The TCPdump team
|
@ -1,89 +0,0 @@
|
||||
/* $NetBSD: atmuni31.h,v 1.1.1.2 2004/09/19 21:57:55 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Yen Yen Lim and North Dakota State University
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Yen Yen Lim and
|
||||
North Dakota State University
|
||||
* 4. 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 AUTHOR ``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 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.
|
||||
*
|
||||
* @(#) Header: /tcpdump/master/libpcap/atmuni31.h,v 1.1 2002/07/11 09:06:32 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
/* Based on UNI3.1 standard by ATM Forum */
|
||||
|
||||
/* ATM traffic types based on VPI=0 and (the following VCI */
|
||||
#define PPC 0x05 /* Point-to-point signal msg */
|
||||
#define BCC 0x02 /* Broadcast signal msg */
|
||||
#define OAMF4SC 0x03 /* Segment OAM F4 flow cell */
|
||||
#define OAMF4EC 0x04 /* End-to-end OAM F4 flow cell */
|
||||
#define METAC 0x01 /* Meta signal msg */
|
||||
#define ILMIC 0x10 /* ILMI msg */
|
||||
|
||||
/* Q.2931 signalling messages */
|
||||
#define CALL_PROCEED 0x02 /* call proceeding */
|
||||
#define CONNECT 0x07 /* connect */
|
||||
#define CONNECT_ACK 0x0f /* connect_ack */
|
||||
#define SETUP 0x05 /* setup */
|
||||
#define RELEASE 0x4d /* release */
|
||||
#define RELEASE_DONE 0x5a /* release_done */
|
||||
#define RESTART 0x46 /* restart */
|
||||
#define RESTART_ACK 0x4e /* restart ack */
|
||||
#define STATUS 0x7d /* status */
|
||||
#define STATUS_ENQ 0x75 /* status ack */
|
||||
#define ADD_PARTY 0x80 /* add party */
|
||||
#define ADD_PARTY_ACK 0x81 /* add party ack */
|
||||
#define ADD_PARTY_REJ 0x82 /* add party rej */
|
||||
#define DROP_PARTY 0x83 /* drop party */
|
||||
#define DROP_PARTY_ACK 0x84 /* drop party ack */
|
||||
|
||||
/* Information Element Parameters in the signalling messages */
|
||||
#define CAUSE 0x08 /* cause */
|
||||
#define ENDPT_REF 0x54 /* endpoint reference */
|
||||
#define AAL_PARA 0x58 /* ATM adaptation layer parameters */
|
||||
#define TRAFF_DESCRIP 0x59 /* atm traffic descriptors */
|
||||
#define CONNECT_ID 0x5a /* connection identifier */
|
||||
#define QOS_PARA 0x5c /* quality of service parameters */
|
||||
#define B_HIGHER 0x5d /* broadband higher layer information */
|
||||
#define B_BEARER 0x5e /* broadband bearer capability */
|
||||
#define B_LOWER 0x5f /* broadband lower information */
|
||||
#define CALLING_PARTY 0x6c /* calling party number */
|
||||
#define CALLED_PARTY 0x70 /* called party nmber */
|
||||
|
||||
#define Q2931 0x09
|
||||
|
||||
/* Q.2931 signalling general messages format */
|
||||
#define PROTO_POS 0 /* offset of protocol discriminator */
|
||||
#define CALL_REF_POS 2 /* offset of call reference value */
|
||||
#define MSG_TYPE_POS 5 /* offset of message type */
|
||||
#define MSG_LEN_POS 7 /* offset of mesage length */
|
||||
#define IE_BEGIN_POS 9 /* offset of first information element */
|
||||
|
||||
/* format of signalling messages */
|
||||
#define TYPE_POS 0
|
||||
#define LEN_POS 2
|
||||
#define FIELD_BEGIN_POS 4
|
@ -1,69 +0,0 @@
|
||||
/* $NetBSD: bpf_dump.c,v 1.2 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993, 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.13.2.1 2003/11/15 23:26:37 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: bpf_dump.c,v 1.2 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
bpf_dump(struct bpf_program *p, int option)
|
||||
{
|
||||
struct bpf_insn *insn;
|
||||
int i;
|
||||
int n = p->bf_len;
|
||||
|
||||
insn = p->bf_insns;
|
||||
if (option > 2) {
|
||||
printf("%d\n", n);
|
||||
for (i = 0; i < n; ++insn, ++i) {
|
||||
printf("%u %u %u %u\n", insn->code,
|
||||
insn->jt, insn->jf, insn->k);
|
||||
}
|
||||
return ;
|
||||
}
|
||||
if (option > 1) {
|
||||
for (i = 0; i < n; ++insn, ++i)
|
||||
printf("{ 0x%x, %d, %d, 0x%08x },\n",
|
||||
insn->code, insn->jt, insn->jf, insn->k);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < n; ++insn, ++i) {
|
||||
#ifdef BDEBUG
|
||||
extern int bids[];
|
||||
printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1);
|
||||
#endif
|
||||
puts(bpf_image(insn, i));
|
||||
}
|
||||
}
|
@ -1,265 +0,0 @@
|
||||
/* $NetBSD: bpf_image.c,v 1.8 2006/02/07 20:13:22 wiz Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/bpf_image.c,v 1.25.2.1 2003/11/15 23:26:38 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: bpf_image.c,v 1.8 2006/02/07 20:13:22 wiz Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
char *
|
||||
bpf_image(p, n)
|
||||
struct bpf_insn *p;
|
||||
int n;
|
||||
{
|
||||
int v;
|
||||
char *op;
|
||||
static char image[256];
|
||||
char operand[64];
|
||||
|
||||
operand[0] = 0;
|
||||
|
||||
v = p->k;
|
||||
switch (p->code) {
|
||||
|
||||
default:
|
||||
op = "unimp";
|
||||
snprintf(operand, sizeof operand, "0x%x", p->code);
|
||||
break;
|
||||
|
||||
case BPF_RET|BPF_K:
|
||||
op = "ret";
|
||||
goto immediate;
|
||||
|
||||
case BPF_RET|BPF_A:
|
||||
op = "ret";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_ABS:
|
||||
op = "ld";
|
||||
abs:
|
||||
snprintf(operand, sizeof operand, "[%d]", v);
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_ABS:
|
||||
op = "ldh";
|
||||
goto abs;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_ABS:
|
||||
op = "ldb";
|
||||
goto abs;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_LEN:
|
||||
op = "ld";
|
||||
strlcpy(operand, "#pktlen", sizeof(operand));
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_IND:
|
||||
op = "ld";
|
||||
offset:
|
||||
snprintf(operand, sizeof(operand), "[x + %d]", v);
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_IND:
|
||||
op = "ldh";
|
||||
goto offset;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_IND:
|
||||
op = "ldb";
|
||||
goto offset;
|
||||
|
||||
case BPF_LD|BPF_IMM:
|
||||
op = "ld";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_LDX|BPF_IMM:
|
||||
op = "ldx";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_LDX|BPF_MSH|BPF_B:
|
||||
op = "ldxb";
|
||||
snprintf(operand, sizeof(operand), "4*([%d]&0xf)", v);
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_MEM:
|
||||
op = "ld";
|
||||
mem:
|
||||
snprintf(operand, sizeof(operand), "M[%d]", v);
|
||||
break;
|
||||
|
||||
case BPF_LDX|BPF_MEM:
|
||||
op = "ldx";
|
||||
goto mem;
|
||||
|
||||
case BPF_ST:
|
||||
op = "st";
|
||||
goto mem;
|
||||
|
||||
case BPF_STX:
|
||||
op = "stx";
|
||||
goto mem;
|
||||
|
||||
case BPF_JMP|BPF_JA:
|
||||
op = "ja";
|
||||
snprintf(operand, sizeof(operand), "%d", n + 1 + p->k);
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_K:
|
||||
op = "jgt";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_K:
|
||||
op = "jge";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_K:
|
||||
op = "jeq";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_K:
|
||||
op = "jset";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_X:
|
||||
op = "jgt";
|
||||
x:
|
||||
strlcpy(operand, "x", sizeof(operand));
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_X:
|
||||
op = "jge";
|
||||
goto x;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_X:
|
||||
op = "jeq";
|
||||
goto x;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_X:
|
||||
op = "jset";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_X:
|
||||
op = "add";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_X:
|
||||
op = "sub";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_X:
|
||||
op = "mul";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_X:
|
||||
op = "div";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_X:
|
||||
op = "and";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_X:
|
||||
op = "or";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_X:
|
||||
op = "lsh";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_X:
|
||||
op = "rsh";
|
||||
goto x;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_K:
|
||||
op = "add";
|
||||
goto immediate;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_K:
|
||||
op = "sub";
|
||||
goto immediate;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_K:
|
||||
op = "mul";
|
||||
goto immediate;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_K:
|
||||
op = "div";
|
||||
immediate:
|
||||
snprintf(operand, sizeof operand, "#%d", v);
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_K:
|
||||
op = "and";
|
||||
goto immediate_hex;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_K:
|
||||
op = "or";
|
||||
immediate_hex:
|
||||
snprintf(operand, sizeof operand, "#0x%x", v);
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_K:
|
||||
op = "lsh";
|
||||
goto immediate;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_K:
|
||||
op = "rsh";
|
||||
goto immediate;
|
||||
|
||||
case BPF_ALU|BPF_NEG:
|
||||
op = "neg";
|
||||
break;
|
||||
|
||||
case BPF_MISC|BPF_TAX:
|
||||
op = "tax";
|
||||
break;
|
||||
|
||||
case BPF_MISC|BPF_TXA:
|
||||
op = "txa";
|
||||
break;
|
||||
}
|
||||
(void)snprintf(image, sizeof image,
|
||||
(BPF_CLASS(p->code) == BPF_JMP &&
|
||||
BPF_OP(p->code) != BPF_JA) ?
|
||||
"(%03d) %-8s %-16s jt %d\tjf %d"
|
||||
: "(%03d) %-8s %s",
|
||||
n, op, operand, n + 1 + p->jt, n + 1 + p->jf);
|
||||
return image;
|
||||
}
|
33
lib/libpcap/config.h
Normal file
33
lib/libpcap/config.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* $NetBSD: config.h,v 1.1 2006/04/25 18:36:44 drochner Exp $ */
|
||||
|
||||
#define HAVE_DECL_ETHER_HOSTTON 1
|
||||
#define HAVE_ETHER_HOSTTON 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_MEMORY_H 1
|
||||
#define HAVE_NETINET_IF_ETHER_H 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_SOCKADDR_SA_LEN 1
|
||||
#define HAVE_SOCKADDR_STORAGE 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRERROR 1
|
||||
#define HAVE_STRINGS_H 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_STRLCPY 1
|
||||
#define HAVE_SYS_IOCCOM_H 1
|
||||
#define HAVE_SYS_SOCKIO_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define HAVE_VERSION_H 1
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#define HAVE___ATTRIBUTE__ 1
|
||||
/* INET6 handled by Makefile */
|
||||
#define NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
#define PACKAGE_NAME ""
|
||||
#define PACKAGE_STRING ""
|
||||
#define PACKAGE_TARNAME ""
|
||||
#define PACKAGE_VERSION ""
|
||||
#define STDC_HEADERS 1
|
@ -1,169 +0,0 @@
|
||||
/* $NetBSD: etherent.c,v 1.5 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993, 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/etherent.c,v 1.21.6.1 2003/11/15 23:26:38 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: etherent.c,v 1.5 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static __inline int xdtoi(int);
|
||||
static __inline int skip_space(FILE *);
|
||||
static __inline int skip_line(FILE *);
|
||||
|
||||
/* Hex digit to integer. */
|
||||
static __inline int
|
||||
xdtoi(c)
|
||||
register int c;
|
||||
{
|
||||
if (isdigit(c))
|
||||
return c - '0';
|
||||
else if (islower(c))
|
||||
return c - 'a' + 10;
|
||||
else
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
static __inline int
|
||||
skip_space(f)
|
||||
FILE *f;
|
||||
{
|
||||
int c;
|
||||
|
||||
do {
|
||||
c = getc(f);
|
||||
} while (isspace(c) && c != '\n');
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static __inline int
|
||||
skip_line(f)
|
||||
FILE *f;
|
||||
{
|
||||
int c;
|
||||
|
||||
do
|
||||
c = getc(f);
|
||||
while (c != '\n' && c != EOF);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
struct pcap_etherent *
|
||||
pcap_next_etherent(FILE *fp)
|
||||
{
|
||||
register int c, d, i;
|
||||
char *bp;
|
||||
static struct pcap_etherent e;
|
||||
|
||||
memset((char *)&e, 0, sizeof(e));
|
||||
do {
|
||||
/* Find addr */
|
||||
c = skip_space(fp);
|
||||
if (c == '\n')
|
||||
continue;
|
||||
|
||||
/* If this is a comment, or first thing on line
|
||||
cannot be etehrnet address, skip the line. */
|
||||
if (!isxdigit(c)) {
|
||||
c = skip_line(fp);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* must be the start of an address */
|
||||
for (i = 0; i < 6; i += 1) {
|
||||
d = xdtoi(c);
|
||||
c = getc(fp);
|
||||
if (isxdigit(c)) {
|
||||
d <<= 4;
|
||||
d |= xdtoi(c);
|
||||
c = getc(fp);
|
||||
}
|
||||
e.addr[i] = d;
|
||||
if (c != ':')
|
||||
break;
|
||||
c = getc(fp);
|
||||
}
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
/* Must be whitespace */
|
||||
if (!isspace(c)) {
|
||||
c = skip_line(fp);
|
||||
continue;
|
||||
}
|
||||
c = skip_space(fp);
|
||||
|
||||
/* hit end of line... */
|
||||
if (c == '\n')
|
||||
continue;
|
||||
|
||||
if (c == '#') {
|
||||
c = skip_line(fp);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* pick up name */
|
||||
bp = e.name;
|
||||
/* Use 'd' to prevent buffer overflow. */
|
||||
d = sizeof(e.name) - 1;
|
||||
do {
|
||||
*bp++ = c;
|
||||
c = getc(fp);
|
||||
} while (!isspace(c) && c != EOF && --d > 0);
|
||||
*bp = '\0';
|
||||
|
||||
/* Eat trailing junk */
|
||||
if (c != '\n')
|
||||
(void)skip_line(fp);
|
||||
|
||||
return &e;
|
||||
|
||||
} while (c != EOF);
|
||||
|
||||
return (NULL);
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/* $NetBSD: ethertype.h,v 1.7 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.12 2001/01/14 21:26:52 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ethernet types.
|
||||
*
|
||||
* We wrap the declarations with #ifdef, so that if a file includes
|
||||
* <netinet/if_ether.h>, which may declare some of these, we don't
|
||||
* get a bunch of complaints from the C compiler about redefinitions
|
||||
* of these values.
|
||||
*
|
||||
* We declare all of them here so that no file has to include
|
||||
* <netinet/if_ether.h> if all it needs are ETHERTYPE_ values.
|
||||
*/
|
||||
|
||||
#ifndef ETHERTYPE_PUP
|
||||
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
|
||||
#endif
|
||||
#ifndef ETHERTYPE_IP
|
||||
#define ETHERTYPE_IP 0x0800 /* IP protocol */
|
||||
#endif
|
||||
#ifndef ETHERTYPE_ARP
|
||||
#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
|
||||
#endif
|
||||
#ifndef ETHERTYPE_REVARP
|
||||
#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
|
||||
#endif
|
||||
#ifndef ETHERTYPE_NS
|
||||
#define ETHERTYPE_NS 0x0600
|
||||
#endif
|
||||
#ifndef ETHERTYPE_SPRITE
|
||||
#define ETHERTYPE_SPRITE 0x0500
|
||||
#endif
|
||||
#ifndef ETHERTYPE_TRAIL
|
||||
#define ETHERTYPE_TRAIL 0x1000
|
||||
#endif
|
||||
#ifndef ETHERTYPE_MOPDL
|
||||
#define ETHERTYPE_MOPDL 0x6001
|
||||
#endif
|
||||
#ifndef ETHERTYPE_MOPRC
|
||||
#define ETHERTYPE_MOPRC 0x6002
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DN
|
||||
#define ETHERTYPE_DN 0x6003
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LAT
|
||||
#define ETHERTYPE_LAT 0x6004
|
||||
#endif
|
||||
#ifndef ETHERTYPE_SCA
|
||||
#define ETHERTYPE_SCA 0x6007
|
||||
#endif
|
||||
#ifndef ETHERTYPE_REVARP
|
||||
#define ETHERTYPE_REVARP 0x8035
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LANBRIDGE
|
||||
#define ETHERTYPE_LANBRIDGE 0x8038
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DECDNS
|
||||
#define ETHERTYPE_DECDNS 0x803c
|
||||
#endif
|
||||
#ifndef ETHERTYPE_DECDTS
|
||||
#define ETHERTYPE_DECDTS 0x803e
|
||||
#endif
|
||||
#ifndef ETHERTYPE_VEXP
|
||||
#define ETHERTYPE_VEXP 0x805b
|
||||
#endif
|
||||
#ifndef ETHERTYPE_VPROD
|
||||
#define ETHERTYPE_VPROD 0x805c
|
||||
#endif
|
||||
#ifndef ETHERTYPE_ATALK
|
||||
#define ETHERTYPE_ATALK 0x809b
|
||||
#endif
|
||||
#ifndef ETHERTYPE_AARP
|
||||
#define ETHERTYPE_AARP 0x80f3
|
||||
#endif
|
||||
#ifndef ETHERTYPE_8021Q
|
||||
#define ETHERTYPE_8021Q 0x8100
|
||||
#endif
|
||||
#ifndef ETHERTYPE_IPX
|
||||
#define ETHERTYPE_IPX 0x8137
|
||||
#endif
|
||||
#ifndef ETHERTYPE_IPV6
|
||||
#define ETHERTYPE_IPV6 0x86dd
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LOOPBACK
|
||||
#define ETHERTYPE_LOOPBACK 0x9000
|
||||
#endif
|
@ -1,250 +0,0 @@
|
||||
/* $NetBSD: fad-getad.c,v 1.2 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996, 1997, 1998
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/fad-getad.c,v 1.7.2.2 2004/03/11 23:04:52 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: fad-getad.c,v 1.2 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is fun.
|
||||
*
|
||||
* In older BSD systems, socket addresses were fixed-length, and
|
||||
* "sizeof (struct sockaddr)" gave the size of the structure.
|
||||
* All addresses fit within a "struct sockaddr".
|
||||
*
|
||||
* In newer BSD systems, the socket address is variable-length, and
|
||||
* there's an "sa_len" field giving the length of the structure;
|
||||
* this allows socket addresses to be longer than 2 bytes of family
|
||||
* and 14 bytes of data.
|
||||
*
|
||||
* Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
|
||||
* variant of the old BSD scheme (with "struct sockaddr_storage" rather
|
||||
* than "struct sockaddr"), and some use the new BSD scheme.
|
||||
*
|
||||
* Some versions of GNU libc use neither scheme, but has an "SA_LEN()"
|
||||
* macro that determines the size based on the address family. Other
|
||||
* versions don't have "SA_LEN()" (as it was in drafts of RFC 2553
|
||||
* but not in the final version). On the latter systems, we explicitly
|
||||
* check the AF_ type to determine the length; we assume that on
|
||||
* all those systems we have "struct sockaddr_storage".
|
||||
*/
|
||||
#ifndef SA_LEN
|
||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||
#define SA_LEN(addr) ((addr)->sa_len)
|
||||
#else /* HAVE_SOCKADDR_SA_LEN */
|
||||
#ifdef HAVE_SOCKADDR_STORAGE
|
||||
static size_t
|
||||
get_sa_len(struct sockaddr *addr)
|
||||
{
|
||||
switch (addr->sa_family) {
|
||||
|
||||
#ifdef AF_INET
|
||||
case AF_INET:
|
||||
return (sizeof (struct sockaddr_in));
|
||||
#endif
|
||||
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
return (sizeof (struct sockaddr_in6));
|
||||
#endif
|
||||
|
||||
default:
|
||||
return (sizeof (struct sockaddr));
|
||||
}
|
||||
}
|
||||
#define SA_LEN(addr) (get_sa_len(addr))
|
||||
#else /* HAVE_SOCKADDR_STORAGE */
|
||||
#define SA_LEN(addr) (sizeof (struct sockaddr))
|
||||
#endif /* HAVE_SOCKADDR_STORAGE */
|
||||
#endif /* HAVE_SOCKADDR_SA_LEN */
|
||||
#endif /* SA_LEN */
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This is the implementation used on platforms that have "getifaddrs()".
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
pcap_if_t *devlist = NULL;
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
struct sockaddr *addr, *netmask, *broadaddr, *dstaddr;
|
||||
size_t addr_size, broadaddr_size, dstaddr_size;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* 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.)
|
||||
*
|
||||
* LAN interfaces will probably have link-layer
|
||||
* addresses; I don't know whether all implementations
|
||||
* of "getifaddrs()" now, or in the future, will return
|
||||
* those.
|
||||
*/
|
||||
if (getifaddrs(&ifap) != 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"getifaddrs: %s", pcap_strerror(errno));
|
||||
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.
|
||||
*/
|
||||
if (ifa->ifa_addr != NULL) {
|
||||
addr = ifa->ifa_addr;
|
||||
addr_size = SA_LEN(addr);
|
||||
netmask = ifa->ifa_netmask;
|
||||
} else {
|
||||
addr = NULL;
|
||||
addr_size = 0;
|
||||
netmask = NULL;
|
||||
}
|
||||
if (ifa->ifa_flags & IFF_BROADCAST &&
|
||||
ifa->ifa_broadaddr != NULL) {
|
||||
broadaddr = ifa->ifa_broadaddr;
|
||||
broadaddr_size = SA_LEN(broadaddr);
|
||||
} else {
|
||||
broadaddr = NULL;
|
||||
broadaddr_size = 0;
|
||||
}
|
||||
if (ifa->ifa_flags & IFF_POINTOPOINT &&
|
||||
ifa->ifa_dstaddr != NULL) {
|
||||
dstaddr = ifa->ifa_dstaddr;
|
||||
dstaddr_size = SA_LEN(ifa->ifa_dstaddr);
|
||||
} else {
|
||||
dstaddr = NULL;
|
||||
dstaddr_size = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_iflist(&devlist, ifa->ifa_name,
|
||||
ifa->ifa_flags, addr, addr_size, netmask, addr_size,
|
||||
broadaddr, broadaddr_size, dstaddr, dstaddr_size,
|
||||
errbuf) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifap);
|
||||
|
||||
if (ret != -1) {
|
||||
/*
|
||||
* We haven't had any errors yet; do any platform-specific
|
||||
* operations to add devices.
|
||||
*/
|
||||
if (pcap_platform_finddevs(&devlist, errbuf) < 0)
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (ret == -1) {
|
||||
/*
|
||||
* We had an error; free the list we've been constructing.
|
||||
*/
|
||||
if (devlist != NULL) {
|
||||
pcap_freealldevs(devlist);
|
||||
devlist = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*alldevsp = devlist;
|
||||
return (ret);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,312 +0,0 @@
|
||||
/* $NetBSD: gencode.h,v 1.14 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.58.2.1 2004/03/28 21:45:31 fenner Exp (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* ATM support:
|
||||
*
|
||||
* Copyright (c) 1997 Yen Yen Lim and North Dakota State University
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Yen Yen Lim and
|
||||
* North Dakota State University
|
||||
* 4. 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 AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
/* Address qualifiers. */
|
||||
|
||||
#define Q_HOST 1
|
||||
#define Q_NET 2
|
||||
#define Q_PORT 3
|
||||
#define Q_GATEWAY 4
|
||||
#define Q_PROTO 5
|
||||
#define Q_PROTOCHAIN 6
|
||||
|
||||
/* Protocol qualifiers. */
|
||||
|
||||
#define Q_LINK 1
|
||||
#define Q_IP 2
|
||||
#define Q_ARP 3
|
||||
#define Q_RARP 4
|
||||
#define Q_SCTP 5
|
||||
#define Q_TCP 6
|
||||
#define Q_UDP 7
|
||||
#define Q_ICMP 8
|
||||
#define Q_IGMP 9
|
||||
#define Q_IGRP 10
|
||||
|
||||
|
||||
#define Q_ATALK 11
|
||||
#define Q_DECNET 12
|
||||
#define Q_LAT 13
|
||||
#define Q_SCA 14
|
||||
#define Q_MOPRC 15
|
||||
#define Q_MOPDL 16
|
||||
|
||||
|
||||
#define Q_IPV6 17
|
||||
#define Q_ICMPV6 18
|
||||
#define Q_AH 19
|
||||
#define Q_ESP 20
|
||||
|
||||
#define Q_PIM 21
|
||||
#define Q_VRRP 22
|
||||
|
||||
#define Q_AARP 23
|
||||
|
||||
#define Q_ISO 24
|
||||
#define Q_ESIS 25
|
||||
#define Q_ISIS 26
|
||||
#define Q_CLNP 27
|
||||
|
||||
#define Q_STP 28
|
||||
|
||||
#define Q_IPX 29
|
||||
|
||||
#define Q_NETBEUI 30
|
||||
|
||||
/* IS-IS Levels */
|
||||
#define Q_ISIS_L1 31
|
||||
#define Q_ISIS_L2 32
|
||||
/* PDU types */
|
||||
#define Q_ISIS_IIH 33
|
||||
#define Q_ISIS_LAN_IIH 34
|
||||
#define Q_ISIS_PTP_IIH 35
|
||||
#define Q_ISIS_SNP 36
|
||||
#define Q_ISIS_CSNP 37
|
||||
#define Q_ISIS_PSNP 38
|
||||
#define Q_ISIS_LSP 39
|
||||
|
||||
/* Directional qualifiers. */
|
||||
|
||||
#define Q_SRC 1
|
||||
#define Q_DST 2
|
||||
#define Q_OR 3
|
||||
#define Q_AND 4
|
||||
|
||||
#define Q_DEFAULT 0
|
||||
#define Q_UNDEF 255
|
||||
|
||||
/* ATM types */
|
||||
#define A_METAC 22 /* Meta signalling Circuit */
|
||||
#define A_BCC 23 /* Broadcast Circuit */
|
||||
#define A_OAMF4SC 24 /* Segment OAM F4 Circuit */
|
||||
#define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */
|
||||
#define A_SC 26 /* Signalling Circuit*/
|
||||
#define A_ILMIC 27 /* ILMI Circuit */
|
||||
#define A_OAM 28 /* OAM cells : F4 only */
|
||||
#define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */
|
||||
#define A_LANE 30 /* LANE traffic */
|
||||
#define A_LLC 31 /* LLC-encapsulated traffic */
|
||||
|
||||
/* Based on Q.2931 signalling protocol */
|
||||
#define A_SETUP 41 /* Setup message */
|
||||
#define A_CALLPROCEED 42 /* Call proceeding message */
|
||||
#define A_CONNECT 43 /* Connect message */
|
||||
#define A_CONNECTACK 44 /* Connect Ack message */
|
||||
#define A_RELEASE 45 /* Release message */
|
||||
#define A_RELEASE_DONE 46 /* Release message */
|
||||
|
||||
/* ATM field types */
|
||||
#define A_VPI 51
|
||||
#define A_VCI 52
|
||||
#define A_PROTOTYPE 53
|
||||
#define A_MSGTYPE 54
|
||||
#define A_CALLREFTYPE 55
|
||||
|
||||
#define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for
|
||||
establishing and destroying switched
|
||||
virtual connection */
|
||||
#define A_METACONNECT 71 /* returns Q.2931 signalling messages for
|
||||
establishing and destroying predefined
|
||||
virtual circuits, such as broadcast
|
||||
circuit, oamf4 segment circuit, oamf4
|
||||
end-to-end circuits, ILMI circuits or
|
||||
connection signalling circuit. */
|
||||
|
||||
struct slist;
|
||||
|
||||
struct stmt {
|
||||
int code;
|
||||
struct slist *jt; /*only for relative jump in block*/
|
||||
struct slist *jf; /*only for relative jump in block*/
|
||||
bpf_int32 k;
|
||||
};
|
||||
|
||||
struct slist {
|
||||
struct stmt s;
|
||||
struct slist *next;
|
||||
};
|
||||
|
||||
/*
|
||||
* A bit vector to represent definition sets. We assume TOT_REGISTERS
|
||||
* is smaller than 8*sizeof(atomset).
|
||||
*/
|
||||
typedef bpf_u_int32 atomset;
|
||||
#define ATOMMASK(n) (1 << (n))
|
||||
#define ATOMELEM(d, n) (d & ATOMMASK(n))
|
||||
|
||||
/*
|
||||
* An unbounded set.
|
||||
*/
|
||||
typedef bpf_u_int32 *uset;
|
||||
|
||||
/*
|
||||
* Total number of atomic entities, including accumulator (A) and index (X).
|
||||
* We treat all these guys similarly during flow analysis.
|
||||
*/
|
||||
#define N_ATOMS (BPF_MEMWORDS+2)
|
||||
|
||||
struct edge {
|
||||
int id;
|
||||
int code;
|
||||
uset edom;
|
||||
struct block *succ;
|
||||
struct block *pred;
|
||||
struct edge *next; /* link list of incoming edges for a node */
|
||||
};
|
||||
|
||||
struct block {
|
||||
int id;
|
||||
struct slist *stmts; /* side effect stmts */
|
||||
struct stmt s; /* branch stmt */
|
||||
int mark;
|
||||
int longjt; /* jt branch requires long jump */
|
||||
int longjf; /* jf branch requires long jump */
|
||||
int level;
|
||||
int offset;
|
||||
int sense;
|
||||
struct edge et;
|
||||
struct edge ef;
|
||||
struct block *head;
|
||||
struct block *link; /* link field used by optimizer */
|
||||
uset dom;
|
||||
uset closure;
|
||||
struct edge *in_edges;
|
||||
atomset def, kill;
|
||||
atomset in_use;
|
||||
atomset out_use;
|
||||
int oval;
|
||||
int val[N_ATOMS];
|
||||
};
|
||||
|
||||
struct arth {
|
||||
struct block *b; /* protocol checks */
|
||||
struct slist *s; /* stmt list */
|
||||
int regno; /* virtual register number of result */
|
||||
};
|
||||
|
||||
struct qual {
|
||||
unsigned char addr;
|
||||
unsigned char proto;
|
||||
unsigned char dir;
|
||||
unsigned char pad;
|
||||
};
|
||||
|
||||
struct arth *gen_loadi(int);
|
||||
struct arth *gen_load(int, struct arth *, int);
|
||||
struct arth *gen_loadlen(void);
|
||||
struct arth *gen_neg(struct arth *);
|
||||
struct arth *gen_arth(int, struct arth *, struct arth *);
|
||||
|
||||
void gen_and(struct block *, struct block *);
|
||||
void gen_or(struct block *, struct block *);
|
||||
void gen_not(struct block *);
|
||||
|
||||
struct block *gen_scode(const char *, struct qual);
|
||||
struct block *gen_ecode(const u_char *, struct qual);
|
||||
struct block *gen_acode(const u_char *, struct qual);
|
||||
struct block *gen_mcode(const char *, const char *, int, struct qual);
|
||||
#ifdef INET6
|
||||
struct block *gen_mcode6(const char *, const char *, u_int, struct qual);
|
||||
#endif
|
||||
struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
|
||||
struct block *gen_proto_abbrev(int);
|
||||
struct block *gen_relation(int, struct arth *, struct arth *, int);
|
||||
struct block *gen_less(int);
|
||||
struct block *gen_greater(int);
|
||||
struct block *gen_byteop(int, int, int);
|
||||
struct block *gen_broadcast(int);
|
||||
struct block *gen_multicast(int);
|
||||
struct block *gen_inbound(int);
|
||||
struct block *gen_vlan(int);
|
||||
|
||||
struct block *gen_vlan(int);
|
||||
|
||||
struct block *gen_atmfield_code(int atmfield, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse);
|
||||
struct block *gen_atmtype_abbrev(int type);
|
||||
struct block *gen_atmmulti_abbrev(int type);
|
||||
|
||||
struct block *gen_pf_ifname(const char *);
|
||||
struct block *gen_pf_rnr(int);
|
||||
struct block *gen_pf_srnr(int);
|
||||
struct block *gen_pf_ruleset(char *);
|
||||
struct block *gen_pf_reason(int);
|
||||
struct block *gen_pf_action(int);
|
||||
struct block *gen_pf_dir(int);
|
||||
|
||||
void bpf_optimize(struct block **);
|
||||
void bpf_error(const char *, ...)
|
||||
__attribute__((noreturn, format (printf, 1, 2)))
|
||||
;
|
||||
|
||||
void finish_parse(struct block *);
|
||||
char *sdup(const char *);
|
||||
|
||||
struct bpf_insn *icode_to_fcode(struct block *, int *);
|
||||
#ifndef YYRECOVERING
|
||||
int pcap_parse(void);
|
||||
#endif
|
||||
void lex_init(char *);
|
||||
void lex_cleanup(void);
|
||||
void sappend(struct slist *, struct slist *);
|
||||
|
||||
/* XXX */
|
||||
#define JT(b) ((b)->et.succ)
|
||||
#define JF(b) ((b)->ef.succ)
|
||||
|
||||
extern int no_optimize;
|
@ -1,445 +0,0 @@
|
||||
%{
|
||||
/* $NetBSD: grammar.y,v 1.11 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/grammar.y,v 1.79.2.3 2004/03/28 21:45:32 fenner Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: grammar.y,v 1.11 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#ifdef __NetBSD__
|
||||
#include <net/if.h>
|
||||
#include <net/if_ether.h>
|
||||
#else
|
||||
#include <netinet/if_ether.h>
|
||||
#endif
|
||||
|
||||
#include <net/pfvar.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#define QSET(q, p, d, a) (q).proto = (p),\
|
||||
(q).dir = (d),\
|
||||
(q).addr = (a)
|
||||
|
||||
int n_errors = 0;
|
||||
|
||||
static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
|
||||
|
||||
static void
|
||||
yyerror(char *msg)
|
||||
{
|
||||
++n_errors;
|
||||
bpf_error("%s", msg);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
#ifndef YYBISON
|
||||
int yyparse(void);
|
||||
|
||||
int
|
||||
pcap_parse()
|
||||
{
|
||||
return (yyparse());
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
int i;
|
||||
bpf_u_int32 h;
|
||||
u_char *e;
|
||||
char *s;
|
||||
struct stmt *stmt;
|
||||
struct arth *a;
|
||||
struct {
|
||||
struct qual q;
|
||||
int atmfieldtype;
|
||||
struct block *b;
|
||||
} blk;
|
||||
struct block *rblk;
|
||||
}
|
||||
|
||||
%type <blk> expr id nid pid term rterm qid
|
||||
%type <blk> head
|
||||
%type <i> pqual dqual aqual ndaqual
|
||||
%type <a> arth narth
|
||||
%type <i> byteop pname pnum relop irelop
|
||||
%type <blk> and or paren not null prog
|
||||
%type <rblk> other pfvar
|
||||
%type <i> atmtype atmmultitype
|
||||
%type <blk> atmfield
|
||||
%type <blk> atmfieldvalue atmvalue atmlistvalue
|
||||
|
||||
%token DST SRC HOST GATEWAY
|
||||
%token NET NETMASK PORT LESS GREATER PROTO PROTOCHAIN CBYTE
|
||||
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
|
||||
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
|
||||
%token TK_BROADCAST TK_MULTICAST
|
||||
%token NUM INBOUND OUTBOUND
|
||||
%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
|
||||
%token LINK
|
||||
%token GEQ LEQ NEQ
|
||||
%token ID EID HID HID6 AID
|
||||
%token LSH RSH
|
||||
%token LEN
|
||||
%token IPV6 ICMPV6 AH ESP
|
||||
%token VLAN
|
||||
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
|
||||
%token STP
|
||||
%token IPX
|
||||
%token NETBEUI
|
||||
%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
|
||||
%token OAM OAMF4 CONNECTMSG METACONNECT
|
||||
%token VPI VCI
|
||||
|
||||
%type <s> ID
|
||||
%type <e> EID
|
||||
%type <e> AID
|
||||
%type <s> HID HID6
|
||||
%type <i> NUM action reason
|
||||
|
||||
%left OR AND
|
||||
%nonassoc '!'
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left LSH RSH
|
||||
%left '+' '-'
|
||||
%left '*' '/'
|
||||
%nonassoc UMINUS
|
||||
%%
|
||||
prog: null expr
|
||||
{
|
||||
finish_parse($2.b);
|
||||
}
|
||||
| null
|
||||
;
|
||||
null: /* null */ { $$.q = qerr; }
|
||||
;
|
||||
expr: term
|
||||
| expr and term { gen_and($1.b, $3.b); $$ = $3; }
|
||||
| expr and id { gen_and($1.b, $3.b); $$ = $3; }
|
||||
| expr or term { gen_or($1.b, $3.b); $$ = $3; }
|
||||
| expr or id { gen_or($1.b, $3.b); $$ = $3; }
|
||||
;
|
||||
and: AND { $$ = $<blk>0; }
|
||||
;
|
||||
or: OR { $$ = $<blk>0; }
|
||||
;
|
||||
id: nid
|
||||
| pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
|
||||
$$.q = $<blk>0.q); }
|
||||
| paren pid ')' { $$ = $2; }
|
||||
;
|
||||
nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
|
||||
| HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
|
||||
$$.q = $<blk>0.q); }
|
||||
| HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
|
||||
$$.q = $<blk>0.q); }
|
||||
| HID {
|
||||
/* Decide how to parse HID based on proto */
|
||||
$$.q = $<blk>0.q;
|
||||
$$.b = gen_ncode($1, 0, $$.q);
|
||||
}
|
||||
| HID6 '/' NUM {
|
||||
#ifdef INET6
|
||||
$$.b = gen_mcode6($1, NULL,
|
||||
(u_int)$3, /* XXX */
|
||||
$$.q = $<blk>0.q);
|
||||
#else
|
||||
bpf_error("'ip6addr/prefixlen' not supported "
|
||||
"in this configuration");
|
||||
#endif /*INET6*/
|
||||
}
|
||||
| HID6 {
|
||||
#ifdef INET6
|
||||
$$.b = gen_mcode6($1, 0, 128,
|
||||
$$.q = $<blk>0.q);
|
||||
#else
|
||||
bpf_error("'ip6addr' not supported "
|
||||
"in this configuration");
|
||||
#endif /*INET6*/
|
||||
}
|
||||
| EID {
|
||||
$$.b = gen_ecode($1, $$.q = $<blk>0.q);
|
||||
/*
|
||||
* $1 was allocated by "pcap_ether_aton()",
|
||||
* so we must free it now that we're done
|
||||
* with it.
|
||||
*/
|
||||
free($1);
|
||||
}
|
||||
| AID {
|
||||
$$.b = gen_acode($1, $$.q = $<blk>0.q);
|
||||
/*
|
||||
* $1 was allocated by "pcap_ether_aton()",
|
||||
* so we must free it now that we're done
|
||||
* with it.
|
||||
*/
|
||||
free($1);
|
||||
}
|
||||
| not id { gen_not($2.b); $$ = $2; }
|
||||
;
|
||||
not: '!' { $$ = $<blk>0; }
|
||||
;
|
||||
paren: '(' { $$ = $<blk>0; }
|
||||
;
|
||||
pid: nid
|
||||
| qid and id { gen_and($1.b, $3.b); $$ = $3; }
|
||||
| qid or id { gen_or($1.b, $3.b); $$ = $3; }
|
||||
;
|
||||
qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
|
||||
$$.q = $<blk>0.q); }
|
||||
| pid
|
||||
;
|
||||
term: rterm
|
||||
| not term { gen_not($2.b); $$ = $2; }
|
||||
;
|
||||
head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
|
||||
| pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
|
||||
| pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
|
||||
| pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
|
||||
| pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
|
||||
| pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
|
||||
;
|
||||
rterm: head id { $$ = $2; }
|
||||
| paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
|
||||
| pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
|
||||
| arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
|
||||
$$.q = qerr; }
|
||||
| arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
|
||||
$$.q = qerr; }
|
||||
| other { $$.b = $1; $$.q = qerr; }
|
||||
| atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
|
||||
| atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
|
||||
| atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
|
||||
;
|
||||
/* protocol level qualifiers */
|
||||
pqual: pname
|
||||
| { $$ = Q_DEFAULT; }
|
||||
;
|
||||
/* 'direction' qualifiers */
|
||||
dqual: SRC { $$ = Q_SRC; }
|
||||
| DST { $$ = Q_DST; }
|
||||
| SRC OR DST { $$ = Q_OR; }
|
||||
| DST OR SRC { $$ = Q_OR; }
|
||||
| SRC AND DST { $$ = Q_AND; }
|
||||
| DST AND SRC { $$ = Q_AND; }
|
||||
;
|
||||
/* address type qualifiers */
|
||||
aqual: HOST { $$ = Q_HOST; }
|
||||
| NET { $$ = Q_NET; }
|
||||
| PORT { $$ = Q_PORT; }
|
||||
;
|
||||
/* non-directional address type qualifiers */
|
||||
ndaqual: GATEWAY { $$ = Q_GATEWAY; }
|
||||
;
|
||||
pname: LINK { $$ = Q_LINK; }
|
||||
| IP { $$ = Q_IP; }
|
||||
| ARP { $$ = Q_ARP; }
|
||||
| RARP { $$ = Q_RARP; }
|
||||
| SCTP { $$ = Q_SCTP; }
|
||||
| TCP { $$ = Q_TCP; }
|
||||
| UDP { $$ = Q_UDP; }
|
||||
| ICMP { $$ = Q_ICMP; }
|
||||
| IGMP { $$ = Q_IGMP; }
|
||||
| IGRP { $$ = Q_IGRP; }
|
||||
| PIM { $$ = Q_PIM; }
|
||||
| VRRP { $$ = Q_VRRP; }
|
||||
| ATALK { $$ = Q_ATALK; }
|
||||
| AARP { $$ = Q_AARP; }
|
||||
| DECNET { $$ = Q_DECNET; }
|
||||
| LAT { $$ = Q_LAT; }
|
||||
| SCA { $$ = Q_SCA; }
|
||||
| MOPDL { $$ = Q_MOPDL; }
|
||||
| MOPRC { $$ = Q_MOPRC; }
|
||||
| IPV6 { $$ = Q_IPV6; }
|
||||
| ICMPV6 { $$ = Q_ICMPV6; }
|
||||
| AH { $$ = Q_AH; }
|
||||
| ESP { $$ = Q_ESP; }
|
||||
| ISO { $$ = Q_ISO; }
|
||||
| ESIS { $$ = Q_ESIS; }
|
||||
| ISIS { $$ = Q_ISIS; }
|
||||
| L1 { $$ = Q_ISIS_L1; }
|
||||
| L2 { $$ = Q_ISIS_L2; }
|
||||
| IIH { $$ = Q_ISIS_IIH; }
|
||||
| LSP { $$ = Q_ISIS_LSP; }
|
||||
| SNP { $$ = Q_ISIS_SNP; }
|
||||
| PSNP { $$ = Q_ISIS_PSNP; }
|
||||
| CSNP { $$ = Q_ISIS_CSNP; }
|
||||
| CLNP { $$ = Q_CLNP; }
|
||||
| STP { $$ = Q_STP; }
|
||||
| IPX { $$ = Q_IPX; }
|
||||
| NETBEUI { $$ = Q_NETBEUI; }
|
||||
;
|
||||
other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
|
||||
| pqual TK_MULTICAST { $$ = gen_multicast($1); }
|
||||
| LESS NUM { $$ = gen_less($2); }
|
||||
| GREATER NUM { $$ = gen_greater($2); }
|
||||
| CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
|
||||
| INBOUND { $$ = gen_inbound(0); }
|
||||
| OUTBOUND { $$ = gen_inbound(1); }
|
||||
| VLAN pnum { $$ = gen_vlan($2); }
|
||||
| VLAN { $$ = gen_vlan(-1); }
|
||||
| pfvar { $$ = $1; }
|
||||
;
|
||||
|
||||
pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
|
||||
| PF_RSET ID { $$ = gen_pf_ruleset($2); }
|
||||
| PF_RNR NUM { $$ = gen_pf_rnr($2); }
|
||||
| PF_SRNR NUM { $$ = gen_pf_srnr($2); }
|
||||
| PF_REASON reason { $$ = gen_pf_reason($2); }
|
||||
| PF_ACTION action { $$ = gen_pf_action($2); }
|
||||
;
|
||||
|
||||
reason: NUM { $$ = $1; }
|
||||
| ID { const char *reasons[] = PFRES_NAMES;
|
||||
int i;
|
||||
for (i = 0; reasons[i]; i++) {
|
||||
if (pcap_strcasecmp($1, reasons[i]) == 0) {
|
||||
$$ = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (reasons[i] == NULL)
|
||||
bpf_error("unknown PF reason");
|
||||
}
|
||||
;
|
||||
|
||||
action: ID { if (pcap_strcasecmp($1, "pass") == 0 ||
|
||||
pcap_strcasecmp($1, "accept") == 0)
|
||||
$$ = PF_PASS;
|
||||
else if (pcap_strcasecmp($1, "drop") == 0 ||
|
||||
pcap_strcasecmp($1, "block") == 0)
|
||||
$$ = PF_DROP;
|
||||
else
|
||||
bpf_error("unknown PF action");
|
||||
}
|
||||
;
|
||||
|
||||
relop: '>' { $$ = BPF_JGT; }
|
||||
| GEQ { $$ = BPF_JGE; }
|
||||
| '=' { $$ = BPF_JEQ; }
|
||||
;
|
||||
irelop: LEQ { $$ = BPF_JGT; }
|
||||
| '<' { $$ = BPF_JGE; }
|
||||
| NEQ { $$ = BPF_JEQ; }
|
||||
;
|
||||
arth: pnum { $$ = gen_loadi($1); }
|
||||
| narth
|
||||
;
|
||||
narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
|
||||
| pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
|
||||
| arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
|
||||
| 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_AND, $1, $3); }
|
||||
| arth '|' arth { $$ = gen_arth(BPF_OR, $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); }
|
||||
| paren narth ')' { $$ = $2; }
|
||||
| LEN { $$ = gen_loadlen(); }
|
||||
;
|
||||
byteop: '&' { $$ = '&'; }
|
||||
| '|' { $$ = '|'; }
|
||||
| '<' { $$ = '<'; }
|
||||
| '>' { $$ = '>'; }
|
||||
| '=' { $$ = '='; }
|
||||
;
|
||||
pnum: NUM
|
||||
| paren pnum ')' { $$ = $2; }
|
||||
;
|
||||
atmtype: LANE { $$ = A_LANE; }
|
||||
| LLC { $$ = A_LLC; }
|
||||
| METAC { $$ = A_METAC; }
|
||||
| BCC { $$ = A_BCC; }
|
||||
| OAMF4EC { $$ = A_OAMF4EC; }
|
||||
| OAMF4SC { $$ = A_OAMF4SC; }
|
||||
| SC { $$ = A_SC; }
|
||||
| ILMIC { $$ = A_ILMIC; }
|
||||
;
|
||||
atmmultitype: OAM { $$ = A_OAM; }
|
||||
| OAMF4 { $$ = A_OAMF4; }
|
||||
| CONNECTMSG { $$ = A_CONNECTMSG; }
|
||||
| METACONNECT { $$ = A_METACONNECT; }
|
||||
;
|
||||
/* ATM field types quantifier */
|
||||
atmfield: VPI { $$.atmfieldtype = A_VPI; }
|
||||
| VCI { $$.atmfieldtype = A_VCI; }
|
||||
;
|
||||
atmvalue: atmfieldvalue
|
||||
| relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (u_int)$2, (u_int)$1, 0); }
|
||||
| irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (u_int)$2, (u_int)$1, 1); }
|
||||
| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
|
||||
;
|
||||
atmfieldvalue: NUM {
|
||||
$$.atmfieldtype = $<blk>0.atmfieldtype;
|
||||
if ($$.atmfieldtype == A_VPI ||
|
||||
$$.atmfieldtype == A_VCI)
|
||||
$$.b = gen_atmfield_code($$.atmfieldtype, (u_int) $1, BPF_JEQ, 0);
|
||||
}
|
||||
;
|
||||
atmlistvalue: atmfieldvalue
|
||||
| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
|
||||
;
|
||||
%%
|
@ -1,700 +0,0 @@
|
||||
/* $NetBSD: inet.c,v 1.11 2005/02/11 06:21:21 simonb Exp $ */
|
||||
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996, 1997, 1998
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/inet.c,v 1.58.2.1 2003/11/15 23:26:41 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet.c,v 1.11 2005/02/11 06:21:21 simonb Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
#include <sys/time.h> /* concession to AIX */
|
||||
|
||||
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||
struct rtentry; /* declarations in <net/if.h> */
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif /* WIN32 */
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#else
|
||||
#define INT_MAX 2147483647
|
||||
#endif
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/* Not all systems have IFF_LOOPBACK */
|
||||
#ifdef IFF_LOOPBACK
|
||||
#define ISLOOPBACK(name, flags) ((flags) & IFF_LOOPBACK)
|
||||
#else
|
||||
#define ISLOOPBACK(name, flags) ((name)[0] == 'l' && (name)[1] == 'o' && \
|
||||
(isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
|
||||
#endif
|
||||
|
||||
struct sockaddr *
|
||||
dup_sockaddr(struct sockaddr *sa, size_t sa_length)
|
||||
{
|
||||
struct sockaddr *newsa;
|
||||
|
||||
if ((newsa = malloc(sa_length)) == NULL)
|
||||
return (NULL);
|
||||
return (memcpy(newsa, sa, sa_length));
|
||||
}
|
||||
|
||||
static int
|
||||
get_instance(const char *name)
|
||||
{
|
||||
const char *cp, *endcp;
|
||||
int n;
|
||||
|
||||
if (strcmp(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;
|
||||
}
|
||||
|
||||
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;
|
||||
return (n);
|
||||
}
|
||||
|
||||
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_if_t *curdev, *prevdev, *nextdev;
|
||||
int this_instance;
|
||||
|
||||
/*
|
||||
* Is there already an entry in the list for this interface?
|
||||
*/
|
||||
for (curdev = *alldevs; curdev != NULL; curdev = curdev->next) {
|
||||
if (strcmp(name, curdev->name) == 0)
|
||||
break; /* yes, we found it */
|
||||
}
|
||||
if (curdev == NULL) {
|
||||
/*
|
||||
* No, we didn't find it.
|
||||
* Allocate a new entry.
|
||||
*/
|
||||
curdev = malloc(sizeof(pcap_if_t));
|
||||
if (curdev == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in the entry.
|
||||
*/
|
||||
curdev->next = NULL;
|
||||
curdev->name = malloc(strlen(name) + 1);
|
||||
strcpy(curdev->name, name);
|
||||
if (description != NULL) {
|
||||
/*
|
||||
* We have a description for this interface.
|
||||
*/
|
||||
curdev->description = malloc(strlen(description) + 1);
|
||||
strcpy(curdev->description, description);
|
||||
} else {
|
||||
/*
|
||||
* We don't.
|
||||
*/
|
||||
curdev->description = NULL;
|
||||
}
|
||||
curdev->addresses = NULL; /* list starts out as empty */
|
||||
curdev->flags = 0;
|
||||
if (ISLOOPBACK(name, flags))
|
||||
curdev->flags |= PCAP_IF_LOOPBACK;
|
||||
|
||||
/*
|
||||
* Add it to the list, in the appropriate location.
|
||||
* First, get the instance number of this interface.
|
||||
*/
|
||||
this_instance = get_instance(name);
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* We start with "prevdev" being NULL, meaning we're before
|
||||
* the first element in the list.
|
||||
*/
|
||||
prevdev = NULL;
|
||||
for (;;) {
|
||||
/*
|
||||
* Get the interface after this one.
|
||||
*/
|
||||
if (prevdev == NULL) {
|
||||
/*
|
||||
* The next element is the first element.
|
||||
*/
|
||||
nextdev = *alldevs;
|
||||
} else
|
||||
nextdev = prevdev->next;
|
||||
|
||||
/*
|
||||
* Are we at the end of the list?
|
||||
*/
|
||||
if (nextdev == NULL) {
|
||||
/*
|
||||
* Yes - we have to put the new entry
|
||||
* after "prevdev".
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Is the new interface a non-loopback interface
|
||||
* and the next interface a loopback 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))) {
|
||||
/*
|
||||
* Yes - we should put the new entry
|
||||
* before "nextdev", i.e. after "prevdev".
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
prevdev = nextdev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert before "nextdev".
|
||||
*/
|
||||
curdev->next = nextdev;
|
||||
|
||||
/*
|
||||
* Insert after "prevdev" - unless "prevdev" is null,
|
||||
* in which case this is the first interface.
|
||||
*/
|
||||
if (prevdev == NULL) {
|
||||
/*
|
||||
* This is the first interface. Pass back a
|
||||
* pointer to it, and put "curdev" before
|
||||
* "nextdev".
|
||||
*/
|
||||
*alldevs = curdev;
|
||||
} else
|
||||
prevdev->next = curdev;
|
||||
}
|
||||
|
||||
*curdev_ret = curdev;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
add_addr_to_iflist(pcap_if_t **alldevs, 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)
|
||||
{
|
||||
pcap_if_t *curdev;
|
||||
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
|
||||
|
||||
if (add_or_find_if(&curdev, alldevs, name, flags, NULL, errbuf) == -1) {
|
||||
/*
|
||||
* Error - give up.
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
if (curdev == NULL) {
|
||||
/*
|
||||
* Device wasn't added because it can't be opened.
|
||||
* Not a fatal error.
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* "curdev" is an entry for this interface; add an entry for this
|
||||
* address to its list of addresses.
|
||||
*
|
||||
* Allocate the new entry and fill it in.
|
||||
*/
|
||||
curaddr = 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 = dup_sockaddr(addr, addr_size);
|
||||
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 = dup_sockaddr(netmask, netmask_size);
|
||||
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 = dup_sockaddr(broadaddr, broadaddr_size);
|
||||
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 = dup_sockaddr(dstaddr, dstaddr_size);
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_add_if(pcap_if_t **devlist, char *name, u_int flags,
|
||||
const char *description, char *errbuf)
|
||||
{
|
||||
pcap_if_t *curdev;
|
||||
|
||||
return (add_or_find_if(&curdev, devlist, name, flags, description,
|
||||
errbuf));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Free a list of interfaces.
|
||||
*/
|
||||
void
|
||||
pcap_freealldevs(pcap_if_t *alldevs)
|
||||
{
|
||||
pcap_if_t *curdev, *nextdev;
|
||||
pcap_addr_t *curaddr, *nextaddr;
|
||||
|
||||
for (curdev = alldevs; curdev != NULL; curdev = nextdev) {
|
||||
nextdev = curdev->next;
|
||||
|
||||
/*
|
||||
* Free all addresses.
|
||||
*/
|
||||
for (curaddr = curdev->addresses; curaddr != NULL; curaddr = nextaddr) {
|
||||
nextaddr = curaddr->next;
|
||||
if (curaddr->addr)
|
||||
free(curaddr->addr);
|
||||
if (curaddr->netmask)
|
||||
free(curaddr->netmask);
|
||||
if (curaddr->broadaddr)
|
||||
free(curaddr->broadaddr);
|
||||
if (curaddr->dstaddr)
|
||||
free(curaddr->dstaddr);
|
||||
free(curaddr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the name string.
|
||||
*/
|
||||
free(curdev->name);
|
||||
|
||||
/*
|
||||
* Free the description string, if any.
|
||||
*/
|
||||
if (curdev->description != NULL)
|
||||
free(curdev->description);
|
||||
|
||||
/*
|
||||
* Free the interface.
|
||||
*/
|
||||
free(curdev);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
/*
|
||||
* Return the name of a network interface attached to the system, or NULL
|
||||
* if none can be found. The interface must be configured up; the
|
||||
* lowest unit number is preferred; loopback is ignored.
|
||||
*/
|
||||
char *
|
||||
pcap_lookupdev(errbuf)
|
||||
register char *errbuf;
|
||||
{
|
||||
pcap_if_t *alldevs;
|
||||
/* for old BSD systems, including bsdi3 */
|
||||
#ifndef IF_NAMESIZE
|
||||
#define IF_NAMESIZE IFNAMSIZ
|
||||
#endif
|
||||
static char device[IF_NAMESIZE + 1];
|
||||
char *ret;
|
||||
|
||||
if (pcap_findalldevs(&alldevs, errbuf) == -1)
|
||||
return (NULL);
|
||||
|
||||
if (alldevs == NULL || (alldevs->flags & PCAP_IF_LOOPBACK)) {
|
||||
/*
|
||||
* There are no devices on the list, or the first device
|
||||
* on the list is a loopback device, which means there
|
||||
* are no non-loopback devices on the list. This means
|
||||
* we can't return any device.
|
||||
*
|
||||
* XXX - why not return a loopback device? If we can't
|
||||
* capture on it, it won't be on the list, and if it's
|
||||
* on the list, there aren't any non-loopback devices,
|
||||
* so why not just supply it as the default device?
|
||||
*/
|
||||
(void)strlcpy(errbuf, "no suitable device found",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
ret = NULL;
|
||||
} else {
|
||||
/*
|
||||
* Return the name of the first device on the list.
|
||||
*/
|
||||
(void)strlcpy(device, alldevs->name, sizeof(device));
|
||||
ret = device;
|
||||
}
|
||||
|
||||
pcap_freealldevs(alldevs);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_lookupnet(device, netp, maskp, errbuf)
|
||||
register const char *device;
|
||||
register bpf_u_int32 *netp, *maskp;
|
||||
register char *errbuf;
|
||||
{
|
||||
register int fd;
|
||||
register struct sockaddr_in *sin;
|
||||
struct ifreq ifr;
|
||||
|
||||
/*
|
||||
* The pseudo-device "any" listens on all interfaces and therefore
|
||||
* has the network address and -mask "0.0.0.0" therefore catching
|
||||
* all traffic. Using NULL for the interface is the same as "any".
|
||||
*/
|
||||
if (!device || strcmp(device, "any") == 0
|
||||
#ifdef HAVE_DAG_API
|
||||
|| strstr(device, "dag") != NULL
|
||||
#endif
|
||||
) {
|
||||
*netp = *maskp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
#ifdef linux
|
||||
/* XXX Work around Linux kernel bug */
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
#endif
|
||||
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"%s: no IPv4 address assigned", device);
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFADDR: %s: %s",
|
||||
device, pcap_strerror(errno));
|
||||
}
|
||||
(void)close(fd);
|
||||
return (-1);
|
||||
}
|
||||
sin = (struct sockaddr_in *)&ifr.ifr_addr;
|
||||
*netp = sin->sin_addr.s_addr;
|
||||
if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));
|
||||
(void)close(fd);
|
||||
return (-1);
|
||||
}
|
||||
(void)close(fd);
|
||||
*maskp = sin->sin_addr.s_addr;
|
||||
if (*maskp == 0) {
|
||||
if (IN_CLASSA(*netp))
|
||||
*maskp = IN_CLASSA_NET;
|
||||
else if (IN_CLASSB(*netp))
|
||||
*maskp = IN_CLASSB_NET;
|
||||
else if (IN_CLASSC(*netp))
|
||||
*maskp = IN_CLASSC_NET;
|
||||
else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"inet class for 0x%x unknown", *netp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
*netp &= *maskp;
|
||||
return (0);
|
||||
}
|
||||
|
||||
#else /* WIN32 */
|
||||
|
||||
/*
|
||||
* Return the name of a network interface attached to the system, or NULL
|
||||
* if none can be found. The interface must be configured up; the
|
||||
* lowest unit number is preferred; loopback is ignored.
|
||||
*/
|
||||
char *
|
||||
pcap_lookupdev(errbuf)
|
||||
register char *errbuf;
|
||||
{
|
||||
DWORD dwVersion;
|
||||
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];
|
||||
|
||||
PacketGetAdapterNames(AdaptersName,&NameLength);
|
||||
|
||||
return (AdaptersName);
|
||||
} else {
|
||||
/*
|
||||
* Windows NT (NT 4.0, W2K, WXP). Convert the names to UNICODE for backward compatibility
|
||||
*/
|
||||
ULONG NameLength = 8192;
|
||||
static WCHAR AdaptersName[8192];
|
||||
char *tAstr;
|
||||
WCHAR *tUstr;
|
||||
WCHAR *TAdaptersName = (WCHAR*)malloc(8192 * sizeof(WCHAR));
|
||||
int NAdapts = 0;
|
||||
|
||||
if(TAdaptersName == NULL)
|
||||
{
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "memory allocation failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PacketGetAdapterNames((PTSTR)TAdaptersName,&NameLength);
|
||||
|
||||
tAstr = (char*)TAdaptersName;
|
||||
tUstr = (WCHAR*)AdaptersName;
|
||||
|
||||
/*
|
||||
* Convert and copy the device names
|
||||
*/
|
||||
while(sscanf(tAstr, "%S", tUstr) > 0)
|
||||
{
|
||||
tAstr += strlen(tAstr) + 1;
|
||||
tUstr += wcslen(tUstr) + 1;
|
||||
NAdapts++;
|
||||
}
|
||||
|
||||
tAstr++;
|
||||
*tUstr = 0;
|
||||
tUstr++;
|
||||
|
||||
/*
|
||||
* Copy the descriptions
|
||||
*/
|
||||
while(NAdapts--)
|
||||
{
|
||||
strcpy((char*)tUstr, tAstr);
|
||||
(char*)tUstr += strlen(tAstr) + 1;;
|
||||
tAstr += strlen(tAstr) + 1;
|
||||
}
|
||||
|
||||
return (char *)(AdaptersName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pcap_lookupnet(device, netp, maskp, errbuf)
|
||||
const register char *device;
|
||||
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)
|
||||
*/
|
||||
npf_if_addr if_addrs[MAX_NETWORK_ADDRESSES];
|
||||
LONG if_addr_size = 1;
|
||||
struct sockaddr_in *t_addr;
|
||||
unsigned int i;
|
||||
|
||||
if (!PacketGetNetInfoEx((void *)device, if_addrs, &if_addr_size)) {
|
||||
*netp = *maskp = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
for(i=0; i<MAX_NETWORK_ADDRESSES; i++)
|
||||
{
|
||||
if(if_addrs[i].IPAddress.ss_family == AF_INET)
|
||||
{
|
||||
t_addr = (struct sockaddr_in *) &(if_addrs[i].IPAddress);
|
||||
*netp = t_addr->sin_addr.S_un.S_addr;
|
||||
t_addr = (struct sockaddr_in *) &(if_addrs[i].SubnetMask);
|
||||
*maskp = t_addr->sin_addr.S_un.S_addr;
|
||||
|
||||
*netp &= *maskp;
|
||||
return (0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*netp = *maskp = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
@ -1,71 +0,0 @@
|
||||
/* $NetBSD: llc.h,v 1.1.1.2 2004/09/19 21:57:55 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/*
|
||||
* 802.2 LLC SAP values.
|
||||
*/
|
||||
|
||||
#ifndef LLCSAP_NULL
|
||||
#define LLCSAP_NULL 0x00
|
||||
#endif
|
||||
#ifndef LLCSAP_GLOBAL
|
||||
#define LLCSAP_GLOBAL 0xff
|
||||
#endif
|
||||
#ifndef LLCSAP_8021B
|
||||
#define LLCSAP_8021B_I 0x02
|
||||
#endif
|
||||
#ifndef LLCSAP_8021B
|
||||
#define LLCSAP_8021B_G 0x03
|
||||
#endif
|
||||
#ifndef LLCSAP_IP
|
||||
#define LLCSAP_IP 0x06
|
||||
#endif
|
||||
#ifndef LLCSAP_PROWAYNM
|
||||
#define LLCSAP_PROWAYNM 0x0e
|
||||
#endif
|
||||
#ifndef LLCSAP_8021D
|
||||
#define LLCSAP_8021D 0x42
|
||||
#endif
|
||||
#ifndef LLCSAP_RS511
|
||||
#define LLCSAP_RS511 0x4e
|
||||
#endif
|
||||
#ifndef LLCSAP_ISO8208
|
||||
#define LLCSAP_ISO8208 0x7e
|
||||
#endif
|
||||
#ifndef LLCSAP_PROWAY
|
||||
#define LLCSAP_PROWAY 0x8e
|
||||
#endif
|
||||
#ifndef LLCSAP_SNAP
|
||||
#define LLCSAP_SNAP 0xaa
|
||||
#endif
|
||||
#ifndef LLCSAP_IPX
|
||||
#define LLCSAP_IPX 0xe0
|
||||
#endif
|
||||
#ifndef LLCSAP_NETBEUI
|
||||
#define LLCSAP_NETBEUI 0xf0
|
||||
#endif
|
||||
#ifndef LLCSAP_ISONS
|
||||
#define LLCSAP_ISONS 0xfe
|
||||
#endif
|
@ -1,454 +0,0 @@
|
||||
/* $NetBSD: nametoaddr.c,v 1.14 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*
|
||||
* Name to id translation routines used by the scanner.
|
||||
* These functions are not time critical.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.68.2.3 2003/11/19 18:13:48 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: nametoaddr.c,v 1.14 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
|
||||
#else /* WIN32 */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h> /* concession to AIX */
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* XXX - why was this included even on UNIX?
|
||||
*/
|
||||
#ifdef __MINGW32__
|
||||
#include "IP6_misc.h"
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef HAVE_ETHER_HOSTTON
|
||||
#ifdef HAVE_NETINET_IF_ETHER_H
|
||||
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||
struct rtentry; /* declarations in <net/if.h> */
|
||||
#include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
|
||||
#include <netinet/if_ether.h>
|
||||
#endif /* HAVE_NETINET_IF_ETHER_H */
|
||||
#endif /* HAVE_ETHER_HOSTTON */
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#endif /* WIN32 */
|
||||
#ifdef INET6
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#endif /*INET6*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifndef NTOHL
|
||||
#define NTOHL(x) (x) = ntohl(x)
|
||||
#define NTOHS(x) (x) = ntohs(x)
|
||||
#endif
|
||||
|
||||
static __inline int xdtoi(int);
|
||||
|
||||
/*
|
||||
* Convert host name to internet address.
|
||||
* Return 0 upon failure.
|
||||
*/
|
||||
bpf_u_int32 **
|
||||
pcap_nametoaddr(const char *name)
|
||||
{
|
||||
#ifndef h_addr
|
||||
static bpf_u_int32 *hlist[2];
|
||||
#endif
|
||||
bpf_u_int32 **p;
|
||||
struct hostent *hp;
|
||||
|
||||
if ((hp = gethostbyname(name)) != NULL) {
|
||||
#ifndef h_addr
|
||||
hlist[0] = (bpf_u_int32 *)hp->h_addr;
|
||||
NTOHL(hp->h_addr);
|
||||
return hlist;
|
||||
#else
|
||||
for (p = (bpf_u_int32 **)hp->h_addr_list; *p; ++p)
|
||||
NTOHL(**p);
|
||||
return (bpf_u_int32 **)hp->h_addr_list;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef INET6
|
||||
struct addrinfo *
|
||||
pcap_nametoaddrinfo(const char *name)
|
||||
{
|
||||
struct addrinfo hints, *res;
|
||||
int error;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM; /*not really*/
|
||||
error = getaddrinfo(name, NULL, &hints, &res);
|
||||
if (error)
|
||||
return NULL;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
#endif /*INET6*/
|
||||
|
||||
/*
|
||||
* Convert net name to internet address.
|
||||
* Return 0 upon failure.
|
||||
*/
|
||||
bpf_u_int32
|
||||
pcap_nametonetaddr(const char *name)
|
||||
{
|
||||
#ifndef WIN32
|
||||
struct netent *np;
|
||||
|
||||
if ((np = getnetbyname(name)) != NULL)
|
||||
return np->n_net;
|
||||
else
|
||||
return 0;
|
||||
#else
|
||||
/*
|
||||
* There's no "getnetbyname()" on Windows.
|
||||
*/
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a port name to its port and protocol numbers.
|
||||
* We assume only TCP or UDP.
|
||||
* Return 0 upon failure.
|
||||
*/
|
||||
int
|
||||
pcap_nametoport(const char *name, int *port, int *proto)
|
||||
{
|
||||
struct servent *sp;
|
||||
int tcp_port = -1;
|
||||
int udp_port = -1;
|
||||
|
||||
/*
|
||||
* We need to check /etc/services for ambiguous entries.
|
||||
* If we find the ambiguous entry, and it has the
|
||||
* same port number, change the proto to PROTO_UNDEF
|
||||
* so both TCP and UDP will be checked.
|
||||
*/
|
||||
sp = getservbyname(name, "tcp");
|
||||
if (sp != NULL) tcp_port = ntohs(sp->s_port);
|
||||
sp = getservbyname(name, "udp");
|
||||
if (sp != NULL) udp_port = ntohs(sp->s_port);
|
||||
if (tcp_port >= 0) {
|
||||
*port = tcp_port;
|
||||
*proto = IPPROTO_TCP;
|
||||
if (udp_port >= 0) {
|
||||
if (udp_port == tcp_port)
|
||||
*proto = PROTO_UNDEF;
|
||||
#ifdef notdef
|
||||
else
|
||||
/* Can't handle ambiguous names that refer
|
||||
to different port numbers. */
|
||||
warning("ambiguous port %s in /etc/services",
|
||||
name);
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (udp_port >= 0) {
|
||||
*port = udp_port;
|
||||
*proto = IPPROTO_UDP;
|
||||
return 1;
|
||||
}
|
||||
#if defined(ultrix) || defined(__osf__)
|
||||
/* Special hack in case NFS isn't in /etc/services */
|
||||
if (strcmp(name, "nfs") == 0) {
|
||||
*port = 2049;
|
||||
*proto = PROTO_UNDEF;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pcap_nametoproto(const char *str)
|
||||
{
|
||||
struct protoent *p;
|
||||
|
||||
p = getprotobyname(str);
|
||||
if (p != 0)
|
||||
return p->p_proto;
|
||||
else
|
||||
return PROTO_UNDEF;
|
||||
}
|
||||
|
||||
#include "ethertype.h"
|
||||
|
||||
struct eproto {
|
||||
char *s;
|
||||
u_short p;
|
||||
};
|
||||
|
||||
/* Static data base of ether protocol types. */
|
||||
struct eproto eproto_db[] = {
|
||||
{ "pup", ETHERTYPE_PUP },
|
||||
{ "xns", ETHERTYPE_NS },
|
||||
{ "ip", ETHERTYPE_IP },
|
||||
#ifdef INET6
|
||||
{ "ip6", ETHERTYPE_IPV6 },
|
||||
#endif
|
||||
{ "arp", ETHERTYPE_ARP },
|
||||
{ "rarp", ETHERTYPE_REVARP },
|
||||
{ "sprite", ETHERTYPE_SPRITE },
|
||||
{ "mopdl", ETHERTYPE_MOPDL },
|
||||
{ "moprc", ETHERTYPE_MOPRC },
|
||||
{ "decnet", ETHERTYPE_DN },
|
||||
{ "lat", ETHERTYPE_LAT },
|
||||
{ "sca", ETHERTYPE_SCA },
|
||||
{ "lanbridge", ETHERTYPE_LANBRIDGE },
|
||||
{ "vexp", ETHERTYPE_VEXP },
|
||||
{ "vprod", ETHERTYPE_VPROD },
|
||||
{ "atalk", ETHERTYPE_ATALK },
|
||||
{ "atalkarp", ETHERTYPE_AARP },
|
||||
{ "loopback", ETHERTYPE_LOOPBACK },
|
||||
{ "decdts", ETHERTYPE_DECDTS },
|
||||
{ "decdns", ETHERTYPE_DECDNS },
|
||||
{ (char *)0, 0 }
|
||||
};
|
||||
|
||||
int
|
||||
pcap_nametoeproto(const char *s)
|
||||
{
|
||||
struct eproto *p = eproto_db;
|
||||
|
||||
while (p->s != 0) {
|
||||
if (strcmp(p->s, s) == 0)
|
||||
return p->p;
|
||||
p += 1;
|
||||
}
|
||||
return PROTO_UNDEF;
|
||||
}
|
||||
|
||||
/* Hex digit to integer. */
|
||||
static __inline int
|
||||
xdtoi(c)
|
||||
register int c;
|
||||
{
|
||||
if (isdigit(c))
|
||||
return c - '0';
|
||||
else if (islower(c))
|
||||
return c - 'a' + 10;
|
||||
else
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
int
|
||||
__pcap_atoin(const char *s, bpf_u_int32 *addr)
|
||||
{
|
||||
u_int n;
|
||||
int len;
|
||||
|
||||
*addr = 0;
|
||||
len = 0;
|
||||
while (1) {
|
||||
n = 0;
|
||||
while (*s && *s != '.')
|
||||
n = n * 10 + *s++ - '0';
|
||||
*addr <<= 8;
|
||||
*addr |= n & 0xff;
|
||||
len += 8;
|
||||
if (*s == '\0')
|
||||
return len;
|
||||
++s;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int
|
||||
__pcap_atodn(const char *s, bpf_u_int32 *addr)
|
||||
{
|
||||
#define AREASHIFT 10
|
||||
#define AREAMASK 0176000
|
||||
#define NODEMASK 01777
|
||||
|
||||
u_int node, area;
|
||||
|
||||
if (sscanf((char *)s, "%d.%d", &area, &node) != 2)
|
||||
bpf_error("malformed decnet address '%s'", s);
|
||||
|
||||
*addr = (area << AREASHIFT) & AREAMASK;
|
||||
*addr |= (node & NODEMASK);
|
||||
|
||||
return(32);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert 's' which has the form "xx:xx:xx:xx:xx:xx" into a new
|
||||
* ethernet address. Assumes 's' is well formed.
|
||||
*/
|
||||
u_char *
|
||||
pcap_ether_aton(const char *s)
|
||||
{
|
||||
register u_char *ep, *e;
|
||||
register u_int d;
|
||||
|
||||
e = ep = (u_char *)malloc(6);
|
||||
|
||||
while (*s) {
|
||||
if (*s == ':')
|
||||
s += 1;
|
||||
d = xdtoi(*s++);
|
||||
if (isxdigit((unsigned char)*s)) {
|
||||
d <<= 4;
|
||||
d |= xdtoi(*s++);
|
||||
}
|
||||
*ep++ = d;
|
||||
}
|
||||
|
||||
return (e);
|
||||
}
|
||||
|
||||
#ifndef HAVE_ETHER_HOSTTON
|
||||
/* Roll our own */
|
||||
u_char *
|
||||
pcap_ether_hostton(const char *name)
|
||||
{
|
||||
register struct pcap_etherent *ep;
|
||||
register u_char *ap;
|
||||
static FILE *fp = NULL;
|
||||
static int init = 0;
|
||||
|
||||
if (!init) {
|
||||
fp = fopen(PCAP_ETHERS_FILE, "r");
|
||||
++init;
|
||||
if (fp == NULL)
|
||||
return (NULL);
|
||||
} else if (fp == NULL)
|
||||
return (NULL);
|
||||
else
|
||||
rewind(fp);
|
||||
|
||||
while ((ep = pcap_next_etherent(fp)) != NULL) {
|
||||
if (strcmp(ep->name, name) == 0) {
|
||||
ap = (u_char *)malloc(6);
|
||||
if (ap != NULL) {
|
||||
memcpy(ap, ep->addr, 6);
|
||||
return (ap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
#else
|
||||
|
||||
/*
|
||||
* XXX - perhaps this should, instead, be declared in "lbl/os-XXX.h" files,
|
||||
* for those OS versions that don't declare it, rather than being declared
|
||||
* here? That way, for example, we could declare it on FreeBSD 2.x (which
|
||||
* doesn't declare it), but not on FreeBSD 3.x (which declares it like
|
||||
* this) or FreeBSD 4.x (which declares it with its first argument as
|
||||
* "const char *", so no matter how we declare it here, it'll fail to
|
||||
* compile on one of 3.x or 4.x).
|
||||
*/
|
||||
#if !defined(sgi) && !defined(__NetBSD__) && !defined(__FreeBSD__) && \
|
||||
!defined(_UNICOSMP)
|
||||
extern int ether_hostton(char *, struct ether_addr *);
|
||||
#endif
|
||||
|
||||
/* Use the os supplied routines */
|
||||
u_char *
|
||||
pcap_ether_hostton(const char *name)
|
||||
{
|
||||
register u_char *ap;
|
||||
u_char a[6];
|
||||
|
||||
ap = NULL;
|
||||
if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) {
|
||||
ap = (u_char *)malloc(6);
|
||||
if (ap != NULL)
|
||||
memcpy((char *)ap, (char *)a, 6);
|
||||
}
|
||||
return (ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
u_short
|
||||
__pcap_nametodnaddr(const char *name)
|
||||
{
|
||||
#ifdef DECNETLIB
|
||||
struct nodeent *getnodebyname();
|
||||
struct nodeent *nep;
|
||||
unsigned short res;
|
||||
|
||||
nep = getnodebyname(name);
|
||||
if (nep == ((struct nodeent *)0))
|
||||
bpf_error("unknown decnet host name '%s'\n", name);
|
||||
|
||||
memcpy((char *)&res, (char *)nep->n_addr, sizeof(unsigned short));
|
||||
return(res);
|
||||
#else
|
||||
bpf_error("decnet name support not included, '%s' cannot be translated\n",
|
||||
name);
|
||||
/* NOTREACHED */
|
||||
#ifdef lint
|
||||
/*
|
||||
* Arguably, lint should assume that functions which don't return
|
||||
* (i.e. that contain no return statements and whose ends are
|
||||
* unreachable) actually return a value, so callers won't get
|
||||
* warnings for using that value (since they won't actually
|
||||
* be doing so). However, most lints don't seem to do that...
|
||||
*/
|
||||
return (0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
* Juniper Networks, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution. The name of Juniper Networks may not
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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: /cvsroot/src/lib/libpcap/Attic/nlpid.h,v 1.1 2004/09/27 23:03:15 dyoung Exp $ (Juniper)
|
||||
*/
|
||||
|
||||
/* Types missing from some systems */
|
||||
|
||||
/*
|
||||
* Network layer prototocol identifiers
|
||||
*/
|
||||
#ifndef ISO8473_CLNP
|
||||
#define ISO8473_CLNP 0x81
|
||||
#endif
|
||||
#ifndef ISO9542_ESIS
|
||||
#define ISO9542_ESIS 0x82
|
||||
#endif
|
||||
#ifndef ISO9542X25_ESIS
|
||||
#define ISO9542X25_ESIS 0x8a
|
||||
#endif
|
||||
#ifndef ISO10589_ISIS
|
||||
#define ISO10589_ISIS 0x83
|
||||
#endif
|
||||
/*
|
||||
* this does not really belong in the nlpid.h file
|
||||
* however we need it for generating nice
|
||||
* IS-IS related BPF filters
|
||||
*/
|
||||
#define ISIS_L1_LAN_IIH 15
|
||||
#define ISIS_L2_LAN_IIH 16
|
||||
#define ISIS_PTP_IIH 17
|
||||
#define ISIS_L1_LSP 18
|
||||
#define ISIS_L2_LSP 20
|
||||
#define ISIS_L1_CSNP 24
|
||||
#define ISIS_L2_CSNP 25
|
||||
#define ISIS_L1_PSNP 26
|
||||
#define ISIS_L2_PSNP 27
|
||||
|
||||
#ifndef ISO8878A_CONS
|
||||
#define ISO8878A_CONS 0x84
|
||||
#endif
|
||||
#ifndef ISO10747_IDRP
|
||||
#define ISO10747_IDRP 0x85
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,967 +0,0 @@
|
||||
/* $NetBSD: pcap-bpf.c,v 1.16 2006/02/24 22:14:10 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1998
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.67.2.4 2003/11/22 00:06:28 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: pcap-bpf.c,v 1.16 2006/02/24 22:14:10 drochner Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <paths.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#ifdef _AIX
|
||||
|
||||
/*
|
||||
* Make "pcap.h" not include "pcap-bpf.h"; we are going to include the
|
||||
* native OS version, as we need "struct bpf_config" from it.
|
||||
*/
|
||||
#define PCAP_DONT_INCLUDE_PCAP_BPF_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* Prevent bpf.h from redefining the DLT_ values to their
|
||||
* IFT_ values, as we're going to return the standard libpcap
|
||||
* values, not IBM's non-standard IFT_ values.
|
||||
*/
|
||||
#undef _AIX
|
||||
#include <net/bpf.h>
|
||||
#define _AIX
|
||||
|
||||
#include <net/if_types.h> /* for IFT_ values */
|
||||
#include <sys/sysconfig.h>
|
||||
#include <sys/device.h>
|
||||
#include <odmi.h>
|
||||
#include <cf.h>
|
||||
|
||||
#ifdef __64BIT__
|
||||
#define domakedev makedev64
|
||||
#define getmajor major64
|
||||
#define bpf_hdr bpf_hdr32
|
||||
#else /* __64BIT__ */
|
||||
#define domakedev makedev
|
||||
#define getmajor major
|
||||
#endif /* __64BIT__ */
|
||||
|
||||
#define BPF_NAME "bpf"
|
||||
#define BPF_MINORS 4
|
||||
#define DRIVER_PATH "/usr/lib/drivers"
|
||||
#define BPF_NODE "/dev/bpf"
|
||||
static int bpfloadedflag = 0;
|
||||
static int odmlockid = 0;
|
||||
|
||||
#else /* _AIX */
|
||||
|
||||
#include <net/bpf.h>
|
||||
|
||||
#endif /* _AIX */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
#include "pcap-dag.h"
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#include "gencode.h" /* for "no_optimize" */
|
||||
|
||||
int __PCAP_MAX_BUFSIZE = (4*1024*1024);
|
||||
|
||||
static int pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp);
|
||||
static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
|
||||
|
||||
static int
|
||||
pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
struct bpf_stat s;
|
||||
|
||||
/*
|
||||
* "ps_recv" counts packets handed to the filter, not packets
|
||||
* that passed the filter. This includes packets later dropped
|
||||
* because we ran out of buffer space.
|
||||
*
|
||||
* "ps_drop" counts packets dropped inside the BPF device
|
||||
* because we ran out of buffer space. It doesn't count
|
||||
* packets dropped by the interface driver. It counts
|
||||
* only packets that passed the filter.
|
||||
*
|
||||
* Both statistics include packets not yet read from the kernel
|
||||
* by libpcap, and thus not yet seen by the application.
|
||||
*/
|
||||
if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) {
|
||||
(void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGSTATS: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ps->ps_recv = s.bs_recv;
|
||||
ps->ps_drop = s.bs_drop;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
int cc;
|
||||
int n = 0;
|
||||
register u_char *bp, *ep;
|
||||
struct bpf_insn *fcode;
|
||||
int pad;
|
||||
|
||||
fcode = p->md.use_bpf ? NULL : p->fcode.bf_insns;
|
||||
again:
|
||||
/*
|
||||
* Has "pcap_breakloop()" been called?
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
p->break_loop = 0;
|
||||
return (-2);
|
||||
}
|
||||
cc = p->cc;
|
||||
if (p->cc == 0) {
|
||||
cc = read(p->fd, (char *)p->buffer, p->bufsize);
|
||||
if (cc < 0) {
|
||||
/* Don't choke when we get ptraced */
|
||||
switch (errno) {
|
||||
|
||||
case EINTR:
|
||||
goto again;
|
||||
|
||||
#ifdef _AIX
|
||||
case EFAULT:
|
||||
/*
|
||||
* Sigh. More AIX wonderfulness.
|
||||
*
|
||||
* For some unknown reason the uiomove()
|
||||
* operation in the bpf kernel extension
|
||||
* used to copy the buffer into user
|
||||
* space sometimes returns EFAULT. I have
|
||||
* no idea why this is the case given that
|
||||
* a kernel debugger shows the user buffer
|
||||
* is correct. This problem appears to
|
||||
* be mostly mitigated by the memset of
|
||||
* the buffer before it is first used.
|
||||
* Very strange.... Shaun Clowes
|
||||
*
|
||||
* In any case this means that we shouldn't
|
||||
* treat EFAULT as a fatal error; as we
|
||||
* don't have an API for returning
|
||||
* a "some packets were dropped since
|
||||
* the last packet you saw" indication,
|
||||
* we just ignore EFAULT and keep reading.
|
||||
*/
|
||||
goto again;
|
||||
#endif
|
||||
|
||||
case EWOULDBLOCK:
|
||||
return (0);
|
||||
#if defined(sun) && !defined(BSD)
|
||||
/*
|
||||
* Due to a SunOS bug, after 2^31 bytes, the kernel
|
||||
* file offset overflows and read fails with EINVAL.
|
||||
* The lseek() to 0 will fix things.
|
||||
*/
|
||||
case EINVAL:
|
||||
if (lseek(p->fd, 0L, SEEK_CUR) +
|
||||
p->bufsize < 0) {
|
||||
(void)lseek(p->fd, 0L, SEEK_SET);
|
||||
goto again;
|
||||
}
|
||||
/* fall through */
|
||||
#endif
|
||||
}
|
||||
(void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
bp = p->buffer;
|
||||
} else
|
||||
bp = p->bp;
|
||||
|
||||
/*
|
||||
* Loop through each packet.
|
||||
*/
|
||||
#define bhp ((struct bpf_hdr *)bp)
|
||||
ep = bp + cc;
|
||||
while (bp < ep) {
|
||||
register int caplen, hdrlen;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
if (p->break_loop) {
|
||||
if (n == 0) {
|
||||
p->break_loop = 0;
|
||||
return (-2);
|
||||
} else {
|
||||
p->bp = bp;
|
||||
p->cc = ep - bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
|
||||
caplen = bhp->bh_caplen;
|
||||
hdrlen = bhp->bh_hdrlen;
|
||||
/*
|
||||
* Short-circuit evaluation: if using BPF filter
|
||||
* in kernel, no need to do it now.
|
||||
*/
|
||||
if (fcode == NULL ||
|
||||
bpf_filter(fcode, bp + hdrlen, bhp->bh_datalen, caplen)) {
|
||||
#ifdef _AIX
|
||||
/*
|
||||
* AIX's BPF returns seconds/nanoseconds time
|
||||
* stamps, not seconds/microseconds time stamps.
|
||||
*
|
||||
* XXX - I'm guessing here that it's a "struct
|
||||
* timestamp"; if not, this code won't compile,
|
||||
* but, if not, you want to send us a bug report
|
||||
* and fall back on using DLPI. It's not as if
|
||||
* BPF used to work right on AIX before this
|
||||
* change; this change attempts to fix the fact
|
||||
* that it didn't....
|
||||
*/
|
||||
bhp->bh_tstamp.tv_usec = bhp->bh_tstamp.tv_usec/1000;
|
||||
#endif
|
||||
if (p->linktype == DLT_FDDI) {
|
||||
if (bhp->bh_caplen > PCAP_FDDIPAD)
|
||||
bhp->bh_caplen -= PCAP_FDDIPAD;
|
||||
else
|
||||
bhp->bh_caplen = 0;
|
||||
if (bhp->bh_datalen > PCAP_FDDIPAD)
|
||||
bhp->bh_datalen -= PCAP_FDDIPAD;
|
||||
else
|
||||
bhp->bh_datalen = 0;
|
||||
pad = PCAP_FDDIPAD;
|
||||
} else
|
||||
pad = 0;
|
||||
/*
|
||||
* XXX A bpf_hdr matches a pcap_pkthdr.
|
||||
*/
|
||||
(*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen
|
||||
+ pad);
|
||||
bp += BPF_WORDALIGN(caplen + hdrlen);
|
||||
if (++n >= cnt && cnt > 0) {
|
||||
p->bp = bp;
|
||||
p->cc = ep - bp;
|
||||
return (n);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Skip this packet.
|
||||
*/
|
||||
bp += BPF_WORDALIGN(caplen + hdrlen);
|
||||
}
|
||||
}
|
||||
#undef bhp
|
||||
p->cc = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXXSCW: Temporary addition for the benefit of wpa_supplicant and hostapd,
|
||||
* until libpcap >= 0.9.3 is imported.
|
||||
*/
|
||||
static int
|
||||
pcap_inject_bpf(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = write(p->fd, buf, size);
|
||||
if (ret == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#ifdef _AIX
|
||||
static int
|
||||
bpf_odminit(char *errbuf)
|
||||
{
|
||||
char *errstr;
|
||||
|
||||
if (odm_initialize() == -1) {
|
||||
if (odm_err_msg(odmerrno, &errstr) == -1)
|
||||
errstr = "Unknown error";
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: odm_initialize failed: %s",
|
||||
errstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((odmlockid = odm_lock("/etc/objrepos/config_lock", ODM_WAIT)) == -1) {
|
||||
if (odm_err_msg(odmerrno, &errstr) == -1)
|
||||
errstr = "Unknown error";
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: odm_lock of /etc/objrepos/config_lock failed: %s",
|
||||
errstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bpf_odmcleanup(char *errbuf)
|
||||
{
|
||||
char *errstr;
|
||||
|
||||
if (odm_unlock(odmlockid) == -1) {
|
||||
if (odm_err_msg(odmerrno, &errstr) == -1)
|
||||
errstr = "Unknown error";
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: odm_unlock failed: %s",
|
||||
errstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (odm_terminate() == -1) {
|
||||
if (odm_err_msg(odmerrno, &errstr) == -1)
|
||||
errstr = "Unknown error";
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: odm_terminate failed: %s",
|
||||
errstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bpf_load(char *errbuf)
|
||||
{
|
||||
long major;
|
||||
int *minors;
|
||||
int numminors, i, rc;
|
||||
char buf[1024];
|
||||
struct stat sbuf;
|
||||
struct bpf_config cfg_bpf;
|
||||
struct cfg_load cfg_ld;
|
||||
struct cfg_kmod cfg_km;
|
||||
|
||||
/*
|
||||
* This is very very close to what happens in the real implementation
|
||||
* but I've fixed some (unlikely) bug situations.
|
||||
*/
|
||||
if (bpfloadedflag)
|
||||
return (0);
|
||||
|
||||
if (bpf_odminit(errbuf) != 0)
|
||||
return (-1);
|
||||
|
||||
major = genmajor(BPF_NAME);
|
||||
if (major == -1) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: genmajor failed: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
minors = getminor(major, &numminors, BPF_NAME);
|
||||
if (!minors) {
|
||||
minors = genminor("bpf", major, 0, BPF_MINORS, 1, 1);
|
||||
if (!minors) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: genminor failed: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (bpf_odmcleanup(errbuf))
|
||||
return (-1);
|
||||
|
||||
rc = stat(BPF_NODE "0", &sbuf);
|
||||
if (rc == -1 && errno != ENOENT) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: can't stat %s: %s",
|
||||
BPF_NODE "0", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (rc == -1 || getmajor(sbuf.st_rdev) != major) {
|
||||
for (i = 0; i < BPF_MINORS; i++) {
|
||||
sprintf(buf, "%s%d", BPF_NODE, i);
|
||||
unlink(buf);
|
||||
if (mknod(buf, S_IRUSR | S_IFCHR, domakedev(major, i)) == -1) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: can't mknod %s: %s",
|
||||
buf, pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the driver is loaded */
|
||||
memset(&cfg_ld, 0x0, sizeof(cfg_ld));
|
||||
cfg_ld.path = buf;
|
||||
sprintf(cfg_ld.path, "%s/%s", DRIVER_PATH, BPF_NAME);
|
||||
if ((sysconfig(SYS_QUERYLOAD, (void *)&cfg_ld, sizeof(cfg_ld)) == -1) ||
|
||||
(cfg_ld.kmid == 0)) {
|
||||
/* Driver isn't loaded, load it now */
|
||||
if (sysconfig(SYS_SINGLELOAD, (void *)&cfg_ld, sizeof(cfg_ld)) == -1) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: could not load driver: %s",
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure the driver */
|
||||
cfg_km.cmd = CFG_INIT;
|
||||
cfg_km.kmid = cfg_ld.kmid;
|
||||
cfg_km.mdilen = sizeof(cfg_bpf);
|
||||
cfg_km.mdiptr = (void *)&cfg_bpf;
|
||||
for (i = 0; i < BPF_MINORS; i++) {
|
||||
cfg_bpf.devno = domakedev(major, i);
|
||||
if (sysconfig(SYS_CFGKMOD, (void *)&cfg_km, sizeof(cfg_km)) == -1) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"bpf_load: could not configure driver: %s",
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
bpfloadedflag = 1;
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static __inline int
|
||||
bpf_open(pcap_t *p, char *errbuf)
|
||||
{
|
||||
int fd;
|
||||
#ifndef _PATH_BPF
|
||||
int flags, n, tries;
|
||||
char device[sizeof "/dev/bpf0000000000"];
|
||||
#else
|
||||
const char *device = _PATH_BPF;
|
||||
#endif
|
||||
|
||||
#ifdef _AIX
|
||||
/*
|
||||
* Load the bpf driver, if it isn't already loaded,
|
||||
* and create the BPF device entries, if they don't
|
||||
* already exist.
|
||||
*/
|
||||
if (bpf_load(errbuf) == -1)
|
||||
return (-1);
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_BPF
|
||||
/*
|
||||
* Go through all the minors and find one that isn't in use.
|
||||
*/
|
||||
for (tries = 0, flags = O_RDWR; tries < 2; tries++, flags = O_RDONLY) {
|
||||
n = 0;
|
||||
do {
|
||||
(void)snprintf(device, sizeof(device), "/dev/bpf%d",
|
||||
n++);
|
||||
fd = open(device, flags);
|
||||
} while (fd < 0 && (errno == EBUSY || errno == EACCES));
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX better message for all minors used
|
||||
*/
|
||||
if (fd < 0)
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"(no devices found) %s: %s", device, pcap_strerror(errno));
|
||||
#else
|
||||
if ((fd = open(device, O_RDWR)) == -1 &&
|
||||
(errno != EACCES || (fd = open(device, O_RDONLY)) == -1))
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"(cannot open device) %s: %s", device, pcap_strerror(errno));
|
||||
#endif
|
||||
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_close_bpf(pcap_t *p)
|
||||
{
|
||||
if (p->buffer != NULL)
|
||||
free(p->buffer);
|
||||
if (p->fd >= 0)
|
||||
close(p->fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX - on AIX, IBM's tcpdump (and perhaps the incompatible-with-everybody-
|
||||
* else's libpcap in AIX 5.1) appears to forcibly load the BPF driver
|
||||
* if it's not already loaded, and to create the BPF devices if they
|
||||
* don't exist.
|
||||
*
|
||||
* It'd be nice if we could do the same, although the code to do so
|
||||
* might be version-dependent, alas (the way to do it isn't necessarily
|
||||
* documented).
|
||||
*/
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
struct bpf_version bv;
|
||||
#ifdef BIOCGDLTLIST
|
||||
struct bpf_dltlist bdl;
|
||||
#endif
|
||||
u_int v;
|
||||
pcap_t *p;
|
||||
struct utsname osinfo;
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
if (strstr(device, "dag")) {
|
||||
return dag_open_live(device, snaplen, promisc, to_ms, ebuf);
|
||||
}
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
#ifdef BIOCGDLTLIST
|
||||
memset(&bdl, 0, sizeof(bdl));
|
||||
#endif
|
||||
|
||||
bzero(&bdl, sizeof(bdl));
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
|
||||
pcap_strerror(errno));
|
||||
return (NULL);
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
fd = bpf_open(p, ebuf);
|
||||
if (fd < 0)
|
||||
goto bad;
|
||||
|
||||
p->fd = fd;
|
||||
p->snapshot = snaplen;
|
||||
|
||||
if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCVERSION: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
if (bv.bv_major != BPF_MAJOR_VERSION ||
|
||||
bv.bv_minor < BPF_MINOR_VERSION) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"kernel bpf filter out of date");
|
||||
goto bad;
|
||||
}
|
||||
/*
|
||||
* Try finding a good size for the buffer; 32768 (or 4M) may be too
|
||||
* big, so keep cutting it in half until we find a size
|
||||
* that works, or run out of sizes to try.
|
||||
*
|
||||
* XXX - there should be a user-accessible hook to set the
|
||||
* initial buffer size.
|
||||
*/
|
||||
for (v = __PCAP_MAX_BUFSIZE; v != 0; v >>= 1) {
|
||||
/* Ignore the return value - this is because the call fails
|
||||
* on BPF systems that don't have kernel malloc. And if
|
||||
* the call fails, it's no big deal, we just continue to
|
||||
* use the standard buffer size.
|
||||
*/
|
||||
(void) ioctl(fd, BIOCSBLEN, (caddr_t)&v);
|
||||
|
||||
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0)
|
||||
break; /* that size worked; we're done */
|
||||
|
||||
if (errno != ENOBUFS) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s",
|
||||
device, pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
if (v == 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"BIOCSBLEN: %s: No buffer size worked", device);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* Get the data link layer type. */
|
||||
if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLT: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
#ifdef _AIX
|
||||
/*
|
||||
* AIX's BPF returns IFF_ types, not DLT_ types, in BIOCGDLT.
|
||||
*/
|
||||
switch (v) {
|
||||
|
||||
case IFT_ETHER:
|
||||
case IFT_ISO88023:
|
||||
v = DLT_EN10MB;
|
||||
break;
|
||||
|
||||
case IFT_FDDI:
|
||||
v = DLT_FDDI;
|
||||
break;
|
||||
|
||||
case IFT_ISO88025:
|
||||
v = DLT_IEEE802;
|
||||
break;
|
||||
|
||||
case IFT_LOOP:
|
||||
v = DLT_NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* We don't know what to map this to yet.
|
||||
*/
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "unknown interface type %u",
|
||||
v);
|
||||
goto bad;
|
||||
}
|
||||
#endif
|
||||
#if _BSDI_VERSION - 0 >= 199510
|
||||
/* The SLIP and PPP link layer header changed in BSD/OS 2.1 */
|
||||
switch (v) {
|
||||
|
||||
case DLT_SLIP:
|
||||
v = DLT_SLIP_BSDOS;
|
||||
break;
|
||||
|
||||
case DLT_PPP:
|
||||
v = DLT_PPP_BSDOS;
|
||||
break;
|
||||
|
||||
case 11: /*DLT_FR*/
|
||||
v = DLT_FRELAY;
|
||||
break;
|
||||
|
||||
case 12: /*DLT_C_HDLC*/
|
||||
v = DLT_CHDLC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
p->linktype = v;
|
||||
|
||||
#ifdef BIOCGDLTLIST
|
||||
/*
|
||||
* We know the default link type -- now determine all the DLTs
|
||||
* this interface supports. If this fails with EINVAL, it's
|
||||
* not fatal; we just don't get to use the feature later.
|
||||
*/
|
||||
if (ioctl(fd, BIOCGDLTLIST, (caddr_t)&bdl) == 0) {
|
||||
bdl.bfl_list = (u_int *) malloc(sizeof(u_int) * bdl.bfl_len);
|
||||
if (bdl.bfl_list == NULL) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (ioctl(fd, BIOCGDLTLIST, (caddr_t)&bdl) < 0) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"BIOCGDLTLIST: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
p->dlt_count = bdl.bfl_len;
|
||||
p->dlt_list = bdl.bfl_list;
|
||||
} else {
|
||||
if (errno != EINVAL) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"BIOCGDLTLIST: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set timeout */
|
||||
if (to_ms != 0) {
|
||||
/*
|
||||
* XXX - is this seconds/nanoseconds in AIX?
|
||||
* (Treating it as such doesn't fix the timeout
|
||||
* problem described below.)
|
||||
*/
|
||||
struct timeval to;
|
||||
to.tv_sec = to_ms / 1000;
|
||||
to.tv_usec = (to_ms * 1000) % 1000000;
|
||||
if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"BIOCSRTIMEOUT: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _AIX
|
||||
#ifdef BIOCIMMEDIATE
|
||||
/*
|
||||
* Darren Reed notes that
|
||||
*
|
||||
* On AIX (4.2 at least), if BIOCIMMEDIATE is not set, the
|
||||
* timeout appears to be ignored and it waits until the buffer
|
||||
* is filled before returning. The result of not having it
|
||||
* set is almost worse than useless if your BPF filter
|
||||
* 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.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 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.)
|
||||
*/
|
||||
v = 1;
|
||||
if (ioctl(p->fd, BIOCIMMEDIATE, &v) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCIMMEDIATE: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
#endif /* BIOCIMMEDIATE */
|
||||
#endif /* _AIX */
|
||||
|
||||
if (promisc) {
|
||||
/* set promiscuous mode, okay if it fails */
|
||||
if (ioctl(p->fd, BIOCPROMISC, NULL) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCPROMISC: %s",
|
||||
pcap_strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGBLEN: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->bufsize = v;
|
||||
p->buffer = (u_char *)malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
(void)snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
#ifdef _AIX
|
||||
/* For some strange reason this seems to prevent the EFAULT
|
||||
* problems we have experienced from AIX BPF. */
|
||||
memset(p->buffer, 0x0, p->bufsize);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* On most BPF platforms, either you can do a "select()" or
|
||||
* "poll()" on a BPF file descriptor and it works correctly,
|
||||
* or you can do it and it will return "readable" if the
|
||||
* hold buffer is full but not if the timeout expires *and*
|
||||
* a non-blocking read will, if the hold buffer is empty
|
||||
* but the store buffer isn't empty, rotate the buffers
|
||||
* and return what packets are available.
|
||||
*
|
||||
* In the latter case, the fact that a non-blocking read
|
||||
* will give you the available packets means you can work
|
||||
* around the failure of "select()" and "poll()" to wake up
|
||||
* and return "readable" when the timeout expires by using
|
||||
* the timeout as the "select()" or "poll()" timeout, putting
|
||||
* the BPF descriptor into non-blocking mode, and read from
|
||||
* it regardless of whether "select()" reports it as readable
|
||||
* or not.
|
||||
*
|
||||
* However, in FreeBSD 4.3 and 4.4, "select()" and "poll()"
|
||||
* won't wake up and return "readable" if the timer expires
|
||||
* and non-blocking reads return EWOULDBLOCK if the hold
|
||||
* buffer is empty, even if the store buffer is non-empty.
|
||||
*
|
||||
* This means the workaround in question won't work.
|
||||
*
|
||||
* Therefore, on FreeBSD 4.3 and 4.4, we set "p->selectable_fd"
|
||||
* to -1, which means "sorry, you can't use 'select()' or 'poll()'
|
||||
* here". On all other BPF platforms, we set it to the FD for
|
||||
* the BPF device; in NetBSD, OpenBSD, and Darwin, a non-blocking
|
||||
* read will, if the hold buffer is empty and the store buffer
|
||||
* isn't empty, rotate the buffers and return what packets are
|
||||
* there (and in sufficiently recent versions of OpenBSD
|
||||
* "select()" and "poll()" should work correctly).
|
||||
*
|
||||
* XXX - what about AIX?
|
||||
*/
|
||||
if (uname(&osinfo) == 0) {
|
||||
/*
|
||||
* We can check what OS this is.
|
||||
*/
|
||||
if (strcmp(osinfo.sysname, "FreeBSD") == 0 &&
|
||||
(strcmp(osinfo.release, "4.3") == 0 ||
|
||||
strcmp(osinfo.release, "4.4") == 0))
|
||||
p->selectable_fd = -1;
|
||||
else
|
||||
p->selectable_fd = p->fd;
|
||||
} else {
|
||||
/*
|
||||
* We can't find out what OS this is, so assume we can
|
||||
* do a "select()" or "poll()".
|
||||
*/
|
||||
p->selectable_fd = p->fd;
|
||||
}
|
||||
|
||||
p->read_op = pcap_read_bpf;
|
||||
p->inject_op = pcap_inject_bpf;
|
||||
p->setfilter_op = pcap_setfilter_bpf;
|
||||
p->set_datalink_op = pcap_set_datalink_bpf;
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_bpf;
|
||||
p->close_op = pcap_close_bpf;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
(void)close(fd);
|
||||
#ifdef BIOCGDLTLIST
|
||||
if (bdl.bfl_list != NULL)
|
||||
free(bdl.bfl_list);
|
||||
#endif
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
#ifdef HAVE_DAG_API
|
||||
if (dag_platform_finddevs(alldevsp, errbuf) < 0)
|
||||
return (-1);
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
/*
|
||||
* It looks that BPF code generated by gen_protochain() is not
|
||||
* compatible with some of kernel BPF code (for example BSD/OS 3.1).
|
||||
* Take a safer side for now.
|
||||
*/
|
||||
if (no_optimize) {
|
||||
/*
|
||||
* XXX - what if we already have a filter in the kernel?
|
||||
*/
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
p->md.use_bpf = 0; /* filtering in userland */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free any user-mode filter we might happen to have installed.
|
||||
*/
|
||||
pcap_freecode(&p->fcode);
|
||||
|
||||
/*
|
||||
* Try to install the kernel filter.
|
||||
*/
|
||||
if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
p->md.use_bpf = 1; /* filtering in the kernel */
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_set_datalink_bpf(pcap_t *p, int dlt)
|
||||
{
|
||||
#ifdef BIOCSDLT
|
||||
if (ioctl(p->fd, BIOCSDLT, &dlt) == -1) {
|
||||
(void) snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"Cannot set DLT %d: %s", dlt, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
return (0);
|
||||
}
|
@ -1,296 +0,0 @@
|
||||
/* $NetBSD: pcap-int.h,v 1.11 2005/10/01 09:55:01 scw Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: /tcpdump/master/libpcap/pcap-int.h,v 1.55.2.4 2003/12/15 01:42:24 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef pcap_int_h
|
||||
#define pcap_int_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <packet32.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* Savefile
|
||||
*/
|
||||
typedef enum {
|
||||
NOT_SWAPPED,
|
||||
SWAPPED,
|
||||
MAYBE_SWAPPED
|
||||
} swapped_type_t;
|
||||
|
||||
struct pcap_sf {
|
||||
FILE *rfile;
|
||||
int swapped;
|
||||
int hdrsize;
|
||||
swapped_type_t lengths_swapped;
|
||||
int version_major;
|
||||
int version_minor;
|
||||
u_char *base;
|
||||
};
|
||||
|
||||
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 */
|
||||
#ifdef linux
|
||||
int sock_packet; /* using Linux 2.0 compatible interface */
|
||||
int timeout; /* timeout specified to pcap_open_live */
|
||||
int clear_promisc; /* must clear promiscuous mode when we close */
|
||||
int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */
|
||||
int lo_ifindex; /* interface index of the loopback device */
|
||||
char *device; /* device name */
|
||||
struct pcap *next; /* list of open promiscuous sock_packet pcaps */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
void *dag_mem_base; /* DAG card memory base address */
|
||||
u_int dag_mem_bottom; /* DAG card current memory bottom pointer */
|
||||
u_int dag_mem_top; /* DAG card current memory top pointer */
|
||||
int dag_fcs_bits; /* Number of checksum bits from link layer */
|
||||
int dag_offset_flags; /* Flags to pass to dag_offset(). */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct pcap {
|
||||
#ifdef WIN32
|
||||
ADAPTER *adapter;
|
||||
LPPACKET Packet;
|
||||
int timeout;
|
||||
int nonblock;
|
||||
#else
|
||||
int fd;
|
||||
int selectable_fd;
|
||||
#endif /* WIN32 */
|
||||
int snapshot;
|
||||
int linktype;
|
||||
int tzoff; /* timezone offset */
|
||||
int offset; /* offset for proper alignment */
|
||||
|
||||
int break_loop; /* flag set to force break from packet-reading loop */
|
||||
|
||||
struct pcap_sf sf;
|
||||
struct pcap_md md;
|
||||
|
||||
/*
|
||||
* Read buffer.
|
||||
*/
|
||||
int bufsize;
|
||||
u_char *buffer;
|
||||
u_char *bp;
|
||||
int cc;
|
||||
|
||||
/*
|
||||
* Place holder for pcap_next().
|
||||
*/
|
||||
u_char *pkt;
|
||||
|
||||
/*
|
||||
* Methods.
|
||||
*/
|
||||
int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
|
||||
int (*inject_op)(pcap_t *, const void *buf, size_t);
|
||||
int (*setfilter_op)(pcap_t *, struct bpf_program *);
|
||||
int (*set_datalink_op)(pcap_t *, int);
|
||||
int (*getnonblock_op)(pcap_t *, char *);
|
||||
int (*setnonblock_op)(pcap_t *, int, char *);
|
||||
int (*stats_op)(pcap_t *, struct pcap_stat *);
|
||||
void (*close_op)(pcap_t *);
|
||||
|
||||
/*
|
||||
* Placeholder for filter code if bpf not in kernel.
|
||||
*/
|
||||
struct bpf_program fcode;
|
||||
|
||||
char errbuf[PCAP_ERRBUF_SIZE + 1];
|
||||
int dlt_count;
|
||||
int *dlt_list;
|
||||
|
||||
struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is a timeval as stored in disk in a dumpfile.
|
||||
* It has to use the same types everywhere, independent of the actual
|
||||
* `struct timeval'
|
||||
*/
|
||||
|
||||
struct pcap_timeval {
|
||||
bpf_int32 tv_sec; /* seconds */
|
||||
bpf_int32 tv_usec; /* microseconds */
|
||||
};
|
||||
|
||||
/*
|
||||
* How a `pcap_pkthdr' is actually stored in the dumpfile.
|
||||
*
|
||||
* Do not change the format of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure),
|
||||
* and do not make the time stamp anything other than seconds and
|
||||
* microseconds (e.g., seconds and nanoseconds). Instead:
|
||||
*
|
||||
* introduce a new structure for the new format;
|
||||
*
|
||||
* send mail to "tcpdump-workers@tcpdump.org", requesting a new
|
||||
* magic number for your new capture file format, and, when
|
||||
* you get the new magic number, put it in "savefile.c";
|
||||
*
|
||||
* use that magic number for save files with the changed record
|
||||
* header;
|
||||
*
|
||||
* make the code in "savefile.c" capable of reading files with
|
||||
* the old record header as well as files with the new record header
|
||||
* (using the magic number to determine the header format).
|
||||
*
|
||||
* Then supply the changes to "patches@tcpdump.org", so that future
|
||||
* versions of libpcap and programs that use it (such as tcpdump) will
|
||||
* be able to read your new capture file format.
|
||||
*/
|
||||
|
||||
struct pcap_sf_pkthdr {
|
||||
struct pcap_timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length this packet (off wire) */
|
||||
};
|
||||
|
||||
/*
|
||||
* How a `pcap_pkthdr' is actually stored in dumpfiles written
|
||||
* by some patched versions of libpcap (e.g. the ones in Red
|
||||
* Hat Linux 6.1 and 6.2).
|
||||
*
|
||||
* Do not change the format of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure).
|
||||
* Instead, introduce a new structure, as per the above.
|
||||
*/
|
||||
|
||||
struct pcap_sf_patched_pkthdr {
|
||||
struct pcap_timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length this packet (off wire) */
|
||||
int index;
|
||||
unsigned short protocol;
|
||||
unsigned char pkt_type;
|
||||
};
|
||||
|
||||
int yylex(void);
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
/* XXX should these be in pcap.h? */
|
||||
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
|
||||
|
||||
|
||||
/*
|
||||
* 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 NetBSD pad to make everything line up on a nice boundary.
|
||||
*/
|
||||
#if defined(ultrix) || defined(__osf__) || defined(__NetBSD__)
|
||||
#define PCAP_FDDIPAD 3
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
#define strlcpy(x, y, z) \
|
||||
(strncpy((x), (y), (z)), \
|
||||
((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \
|
||||
strlen((y)))
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if !defined(HAVE_SNPRINTF)
|
||||
#define snprintf pcap_snprintf
|
||||
extern int snprintf (char *, size_t, const char *, ...);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VSNPRINTF)
|
||||
#define vsnprintf pcap_vsnprintf
|
||||
extern int vsnprintf (char *, size_t, const char *, va_list ap);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Routines that most pcap implementations can use for non-blocking mode.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
int pcap_getnonblock_fd(pcap_t *, char *);
|
||||
int pcap_setnonblock_fd(pcap_t *p, int, char *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Internal interfaces for "pcap_findalldevs()".
|
||||
*
|
||||
* "pcap_platform_finddevs()" is a platform-dependent routine to
|
||||
* add devices not found by the "standard" mechanisms (SIOCGIFCONF,
|
||||
* "getifaddrs()", etc..
|
||||
*
|
||||
* "pcap_add_if()" adds an interface to the list of interfaces.
|
||||
*/
|
||||
int pcap_platform_finddevs(pcap_if_t **, char *);
|
||||
int add_addr_to_iflist(pcap_if_t **, char *, u_int, struct sockaddr *,
|
||||
size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
|
||||
struct sockaddr *, size_t, char *);
|
||||
int pcap_add_if(pcap_if_t **, 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 *);
|
||||
|
||||
#ifdef WIN32
|
||||
char *pcap_win32strerror(void);
|
||||
#endif
|
||||
|
||||
/* XXX */
|
||||
extern u_int pcap_fddipad;
|
||||
|
||||
int install_bpf_program(pcap_t *, struct bpf_program *);
|
||||
|
||||
int pcap_strcasecmp(const char *, const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,89 +0,0 @@
|
||||
/* $NetBSD: pcap-namedb.h,v 1.7 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.8 2000/07/29 07:36:43 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_ethers_h
|
||||
#define lib_pcap_ethers_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* As returned by the pcap_next_etherent()
|
||||
* XXX this stuff doesn't belong in this interface, but this
|
||||
* library already must do name to address translation, so
|
||||
* on systems that don't have support for /etc/ethers, we
|
||||
* export these hooks since they'll
|
||||
*/
|
||||
struct pcap_etherent {
|
||||
u_char addr[6];
|
||||
char name[122];
|
||||
};
|
||||
#ifndef PCAP_ETHERS_FILE
|
||||
#define PCAP_ETHERS_FILE "/etc/ethers"
|
||||
#endif
|
||||
struct pcap_etherent *pcap_next_etherent(FILE *);
|
||||
u_char *pcap_ether_hostton(const char*);
|
||||
u_char *pcap_ether_aton(const char *);
|
||||
|
||||
bpf_u_int32 **pcap_nametoaddr(const char *);
|
||||
#ifdef INET6
|
||||
struct addrinfo *pcap_nametoaddrinfo(const char *);
|
||||
#endif
|
||||
bpf_u_int32 pcap_nametonetaddr(const char *);
|
||||
|
||||
int pcap_nametoport(const char *, int *, int *);
|
||||
int pcap_nametoproto(const char *);
|
||||
int pcap_nametoeproto(const char *);
|
||||
/*
|
||||
* If a protocol is unknown, PROTO_UNDEF is returned.
|
||||
* Also, pcap_nametoport() returns the protocol along with the port number.
|
||||
* If there are ambiguous entried in /etc/services (i.e. domain
|
||||
* can be either tcp or udp) PROTO_UNDEF is returned.
|
||||
*/
|
||||
#define PROTO_UNDEF -1
|
||||
|
||||
/* XXX move these to pcap-int.h? */
|
||||
int __pcap_atodn(const char *, bpf_u_int32 *);
|
||||
int __pcap_atoin(const char *, bpf_u_int32 *);
|
||||
u_short __pcap_nametodnaddr(const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
1283
lib/libpcap/pcap.3
1283
lib/libpcap/pcap.3
File diff suppressed because it is too large
Load Diff
@ -1,789 +0,0 @@
|
||||
/* $NetBSD: pcap.c,v 1.11 2005/10/01 09:55:00 scw Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/pcap.c,v 1.63.2.9 2004/03/25 22:40:52 guy Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: pcap.c,v 1.11 2005/10/01 09:55:00 scw Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
#include <sys/types.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
#include <dagnew.h>
|
||||
#include <dagapi.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
|
||||
return p->read_op(p, cnt, callback, user);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX - is this necessary?
|
||||
*/
|
||||
int
|
||||
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
|
||||
return p->read_op(p, cnt, callback, user);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
register int n;
|
||||
|
||||
for (;;) {
|
||||
if (p->sf.rfile != NULL) {
|
||||
/*
|
||||
* 0 means EOF, so don't loop if we get 0.
|
||||
*/
|
||||
n = pcap_offline_read(p, cnt, callback, user);
|
||||
} else {
|
||||
/*
|
||||
* XXX keep reading until we get something
|
||||
* (or an error occurs)
|
||||
*/
|
||||
do {
|
||||
n = p->read_op(p, cnt, callback, user);
|
||||
} while (n == 0);
|
||||
}
|
||||
if (n <= 0)
|
||||
return (n);
|
||||
if (cnt > 0) {
|
||||
cnt -= n;
|
||||
if (cnt <= 0)
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct singleton {
|
||||
struct pcap_pkthdr *hdr;
|
||||
const u_char *pkt;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
pcap_oneshot(u_char *userData, const struct pcap_pkthdr *h, const u_char *pkt)
|
||||
{
|
||||
struct singleton *sp = (struct singleton *)userData;
|
||||
*sp->hdr = *h;
|
||||
sp->pkt = pkt;
|
||||
}
|
||||
|
||||
const u_char *
|
||||
pcap_next(pcap_t *p, struct pcap_pkthdr *h)
|
||||
{
|
||||
struct singleton s;
|
||||
|
||||
s.hdr = h;
|
||||
if (pcap_dispatch(p, 1, pcap_oneshot, (u_char*)&s) <= 0)
|
||||
return (0);
|
||||
return (s.pkt);
|
||||
}
|
||||
|
||||
struct pkt_for_fakecallback {
|
||||
struct pcap_pkthdr *hdr;
|
||||
const u_char **pkt;
|
||||
};
|
||||
|
||||
static void
|
||||
pcap_fakecallback(u_char *userData, const struct pcap_pkthdr *h,
|
||||
const u_char *pkt)
|
||||
{
|
||||
struct pkt_for_fakecallback *sp = (struct pkt_for_fakecallback *)userData;
|
||||
|
||||
*sp->hdr = *h;
|
||||
*sp->pkt = pkt;
|
||||
}
|
||||
|
||||
int
|
||||
pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
|
||||
const u_char **pkt_data)
|
||||
{
|
||||
struct pkt_for_fakecallback s;
|
||||
|
||||
s.hdr = &p->pcap_header;
|
||||
s.pkt = pkt_data;
|
||||
|
||||
/* Saves a pointer to the packet headers */
|
||||
*pkt_header= &p->pcap_header;
|
||||
|
||||
if (p->sf.rfile != NULL) {
|
||||
int status;
|
||||
|
||||
/* We are on an offline capture */
|
||||
status = pcap_offline_read(p, 1, pcap_fakecallback,
|
||||
(u_char *)&s);
|
||||
|
||||
/*
|
||||
* Return codes for pcap_offline_read() are:
|
||||
* - 0: EOF
|
||||
* - -1: error
|
||||
* - >1: OK
|
||||
* The first one ('0') conflicts with the return code of
|
||||
* 0 from pcap_read() meaning "no packets arrived before
|
||||
* the timeout expired", so we map it to -2 so you can
|
||||
* distinguish between an EOF from a savefile and a
|
||||
* "no packets arrived before the timeout expired, try
|
||||
* again" from a live capture.
|
||||
*/
|
||||
if (status == 0)
|
||||
return (-2);
|
||||
else
|
||||
return (status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return codes for pcap_read() are:
|
||||
* - 0: timeout
|
||||
* - -1: error
|
||||
* - -2: loop was broken out of with pcap_breakloop()
|
||||
* - >1: OK
|
||||
* The first one ('0') conflicts with the return code of 0 from
|
||||
* pcap_offline_read() meaning "end of file".
|
||||
*/
|
||||
return (p->read_op(p, 1, pcap_fakecallback, (u_char *)&s));
|
||||
}
|
||||
|
||||
/*
|
||||
* Force the loop in "pcap_read()" or "pcap_read_offline()" to terminate.
|
||||
*/
|
||||
void
|
||||
pcap_breakloop(pcap_t *p)
|
||||
{
|
||||
p->break_loop = 1;
|
||||
}
|
||||
|
||||
int
|
||||
pcap_datalink(pcap_t *p)
|
||||
{
|
||||
return (p->linktype);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
|
||||
{
|
||||
if (p->dlt_count == 0) {
|
||||
/*
|
||||
* We couldn't fetch the list of DLTs, which means
|
||||
* this platform doesn't support changing the
|
||||
* DLT for an interface. Return a list of DLTs
|
||||
* containing only the DLT this device supports.
|
||||
*/
|
||||
*dlt_buffer = (int*)malloc(sizeof(**dlt_buffer));
|
||||
if (*dlt_buffer == NULL) {
|
||||
(void)snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
**dlt_buffer = p->linktype;
|
||||
return (1);
|
||||
} else {
|
||||
*dlt_buffer = (int*)malloc(sizeof(**dlt_buffer) * p->dlt_count);
|
||||
if (*dlt_buffer == NULL) {
|
||||
(void)snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
(void)memcpy(*dlt_buffer, p->dlt_list,
|
||||
sizeof(**dlt_buffer) * p->dlt_count);
|
||||
return (p->dlt_count);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
pcap_set_datalink(pcap_t *p, int dlt)
|
||||
{
|
||||
int i;
|
||||
const char *dlt_name;
|
||||
|
||||
if (p->dlt_count == 0 || p->set_datalink_op == NULL) {
|
||||
/*
|
||||
* We couldn't fetch the list of DLTs, or we don't
|
||||
* have a "set datalink" operation, which means
|
||||
* this platform doesn't support changing the
|
||||
* DLT for an interface. Check whether the new
|
||||
* DLT is the one this interface supports.
|
||||
*/
|
||||
if (p->linktype != dlt)
|
||||
goto unsupported;
|
||||
|
||||
/*
|
||||
* It is, so there's nothing we need to do here.
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
for (i = 0; i < p->dlt_count; i++)
|
||||
if (p->dlt_list[i] == dlt)
|
||||
break;
|
||||
if (i >= p->dlt_count)
|
||||
goto unsupported;
|
||||
if (p->set_datalink_op(p, dlt) == -1)
|
||||
return (-1);
|
||||
p->linktype = dlt;
|
||||
return (0);
|
||||
|
||||
unsupported:
|
||||
dlt_name = pcap_datalink_val_to_name(dlt);
|
||||
if (dlt_name != NULL) {
|
||||
(void) snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"%s is not one of the DLTs supported by this device",
|
||||
dlt_name);
|
||||
} else {
|
||||
(void) snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"DLT %d is not one of the DLTs supported by this device",
|
||||
dlt);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
struct dlt_choice {
|
||||
const char *name;
|
||||
const char *description;
|
||||
int dlt;
|
||||
};
|
||||
|
||||
#define DLT_CHOICE(code, description) { #code, description, code }
|
||||
#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
|
||||
|
||||
static struct dlt_choice dlt_choices[] = {
|
||||
DLT_CHOICE(DLT_NULL, "BSD loopback"),
|
||||
DLT_CHOICE(DLT_EN10MB, "Ethernet"),
|
||||
DLT_CHOICE(DLT_IEEE802, "Token ring"),
|
||||
DLT_CHOICE(DLT_ARCNET, "ARCNET"),
|
||||
DLT_CHOICE(DLT_SLIP, "SLIP"),
|
||||
DLT_CHOICE(DLT_PPP, "PPP"),
|
||||
DLT_CHOICE(DLT_FDDI, "FDDI"),
|
||||
DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
|
||||
DLT_CHOICE(DLT_RAW, "Raw IP"),
|
||||
DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
|
||||
DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
|
||||
DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
|
||||
DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
|
||||
DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
|
||||
DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
|
||||
DLT_CHOICE(DLT_IEEE802_11, "802.11"),
|
||||
DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
|
||||
DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
|
||||
DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
|
||||
DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
|
||||
DLT_CHOICE(DLT_LTALK, "Localtalk"),
|
||||
DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
|
||||
DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
|
||||
DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
|
||||
DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
|
||||
DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus BSD radio information header"),
|
||||
DLT_CHOICE(DLT_APPLE_IP_OVER_IEEE1394, "Apple IP-over-IEEE 1394"),
|
||||
DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
|
||||
DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
|
||||
DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS, "802.11 plus AVS radio information header"),
|
||||
DLT_CHOICE_SENTINEL
|
||||
};
|
||||
|
||||
/*
|
||||
* This array is designed for mapping upper and lower case letter
|
||||
* together for a case independent comparison. The mappings are
|
||||
* based upon ascii character sequences.
|
||||
*/
|
||||
static const u_char charmap[] = {
|
||||
(u_char)'\000', (u_char)'\001', (u_char)'\002', (u_char)'\003',
|
||||
(u_char)'\004', (u_char)'\005', (u_char)'\006', (u_char)'\007',
|
||||
(u_char)'\010', (u_char)'\011', (u_char)'\012', (u_char)'\013',
|
||||
(u_char)'\014', (u_char)'\015', (u_char)'\016', (u_char)'\017',
|
||||
(u_char)'\020', (u_char)'\021', (u_char)'\022', (u_char)'\023',
|
||||
(u_char)'\024', (u_char)'\025', (u_char)'\026', (u_char)'\027',
|
||||
(u_char)'\030', (u_char)'\031', (u_char)'\032', (u_char)'\033',
|
||||
(u_char)'\034', (u_char)'\035', (u_char)'\036', (u_char)'\037',
|
||||
(u_char)'\040', (u_char)'\041', (u_char)'\042', (u_char)'\043',
|
||||
(u_char)'\044', (u_char)'\045', (u_char)'\046', (u_char)'\047',
|
||||
(u_char)'\050', (u_char)'\051', (u_char)'\052', (u_char)'\053',
|
||||
(u_char)'\054', (u_char)'\055', (u_char)'\056', (u_char)'\057',
|
||||
(u_char)'\060', (u_char)'\061', (u_char)'\062', (u_char)'\063',
|
||||
(u_char)'\064', (u_char)'\065', (u_char)'\066', (u_char)'\067',
|
||||
(u_char)'\070', (u_char)'\071', (u_char)'\072', (u_char)'\073',
|
||||
(u_char)'\074', (u_char)'\075', (u_char)'\076', (u_char)'\077',
|
||||
(u_char)'\100', (u_char)'\141', (u_char)'\142', (u_char)'\143',
|
||||
(u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
|
||||
(u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
|
||||
(u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
|
||||
(u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
|
||||
(u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
|
||||
(u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\133',
|
||||
(u_char)'\134', (u_char)'\135', (u_char)'\136', (u_char)'\137',
|
||||
(u_char)'\140', (u_char)'\141', (u_char)'\142', (u_char)'\143',
|
||||
(u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
|
||||
(u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
|
||||
(u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
|
||||
(u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
|
||||
(u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
|
||||
(u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\173',
|
||||
(u_char)'\174', (u_char)'\175', (u_char)'\176', (u_char)'\177',
|
||||
(u_char)'\200', (u_char)'\201', (u_char)'\202', (u_char)'\203',
|
||||
(u_char)'\204', (u_char)'\205', (u_char)'\206', (u_char)'\207',
|
||||
(u_char)'\210', (u_char)'\211', (u_char)'\212', (u_char)'\213',
|
||||
(u_char)'\214', (u_char)'\215', (u_char)'\216', (u_char)'\217',
|
||||
(u_char)'\220', (u_char)'\221', (u_char)'\222', (u_char)'\223',
|
||||
(u_char)'\224', (u_char)'\225', (u_char)'\226', (u_char)'\227',
|
||||
(u_char)'\230', (u_char)'\231', (u_char)'\232', (u_char)'\233',
|
||||
(u_char)'\234', (u_char)'\235', (u_char)'\236', (u_char)'\237',
|
||||
(u_char)'\240', (u_char)'\241', (u_char)'\242', (u_char)'\243',
|
||||
(u_char)'\244', (u_char)'\245', (u_char)'\246', (u_char)'\247',
|
||||
(u_char)'\250', (u_char)'\251', (u_char)'\252', (u_char)'\253',
|
||||
(u_char)'\254', (u_char)'\255', (u_char)'\256', (u_char)'\257',
|
||||
(u_char)'\260', (u_char)'\261', (u_char)'\262', (u_char)'\263',
|
||||
(u_char)'\264', (u_char)'\265', (u_char)'\266', (u_char)'\267',
|
||||
(u_char)'\270', (u_char)'\271', (u_char)'\272', (u_char)'\273',
|
||||
(u_char)'\274', (u_char)'\275', (u_char)'\276', (u_char)'\277',
|
||||
(u_char)'\300', (u_char)'\341', (u_char)'\342', (u_char)'\343',
|
||||
(u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
|
||||
(u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
|
||||
(u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
|
||||
(u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
|
||||
(u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
|
||||
(u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\333',
|
||||
(u_char)'\334', (u_char)'\335', (u_char)'\336', (u_char)'\337',
|
||||
(u_char)'\340', (u_char)'\341', (u_char)'\342', (u_char)'\343',
|
||||
(u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
|
||||
(u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
|
||||
(u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
|
||||
(u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
|
||||
(u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
|
||||
(u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\373',
|
||||
(u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
|
||||
};
|
||||
|
||||
int
|
||||
pcap_strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
register const u_char *cm = charmap,
|
||||
*us1 = (u_char *)s1,
|
||||
*us2 = (u_char *)s2;
|
||||
|
||||
while (cm[*us1] == cm[*us2++])
|
||||
if (*us1++ == '\0')
|
||||
return(0);
|
||||
return (cm[*us1] - cm[*--us2]);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_datalink_name_to_val(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
||||
if (pcap_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
|
||||
name) == 0)
|
||||
return (dlt_choices[i].dlt);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
const char *
|
||||
pcap_datalink_val_to_name(int dlt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
||||
if (dlt_choices[i].dlt == dlt)
|
||||
return (dlt_choices[i].name + sizeof("DLT_") - 1);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
pcap_datalink_val_to_description(int dlt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
||||
if (dlt_choices[i].dlt == dlt)
|
||||
return (dlt_choices[i].description);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_snapshot(pcap_t *p)
|
||||
{
|
||||
return (p->snapshot);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_is_swapped(pcap_t *p)
|
||||
{
|
||||
return (p->sf.swapped);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_major_version(pcap_t *p)
|
||||
{
|
||||
return (p->sf.version_major);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_minor_version(pcap_t *p)
|
||||
{
|
||||
return (p->sf.version_minor);
|
||||
}
|
||||
|
||||
FILE *
|
||||
pcap_file(pcap_t *p)
|
||||
{
|
||||
return (p->sf.rfile);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_fileno(pcap_t *p)
|
||||
{
|
||||
#ifndef WIN32
|
||||
return (p->fd);
|
||||
#else
|
||||
if (p->adapter != NULL)
|
||||
return ((int)(DWORD)p->adapter->hFile);
|
||||
else
|
||||
return (-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
int
|
||||
pcap_get_selectable_fd(pcap_t *p)
|
||||
{
|
||||
return (p->selectable_fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
pcap_perror(pcap_t *p, char *prefix)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", prefix, p->errbuf);
|
||||
}
|
||||
|
||||
char *
|
||||
pcap_geterr(pcap_t *p)
|
||||
{
|
||||
return (p->errbuf);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_getnonblock(pcap_t *p, char *errbuf)
|
||||
{
|
||||
return p->getnonblock_op(p, errbuf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the current non-blocking mode setting, under the assumption that
|
||||
* it's just the standard POSIX non-blocking flag.
|
||||
*
|
||||
* We don't look at "p->nonblock", in case somebody tweaked the FD
|
||||
* directly.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
int
|
||||
pcap_getnonblock_fd(pcap_t *p, char *errbuf)
|
||||
{
|
||||
int fdflags;
|
||||
|
||||
fdflags = fcntl(p->fd, F_GETFL, 0);
|
||||
if (fdflags == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (fdflags & O_NONBLOCK)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
return p->setnonblock_op(p, nonblock, errbuf);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* Set non-blocking mode, under the assumption that it's just the
|
||||
* standard POSIX non-blocking flag. (This can be called by the
|
||||
* per-platform non-blocking-mode routine if that routine also
|
||||
* needs to do some additional work.)
|
||||
*/
|
||||
int
|
||||
pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
int fdflags;
|
||||
|
||||
fdflags = fcntl(p->fd, F_GETFL, 0);
|
||||
if (fdflags == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (nonblock)
|
||||
fdflags |= O_NONBLOCK;
|
||||
else
|
||||
fdflags &= ~O_NONBLOCK;
|
||||
if (fcntl(p->fd, F_SETFL, fdflags) == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_SETFL: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* 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()
|
||||
*/
|
||||
char *
|
||||
pcap_win32strerror(void)
|
||||
{
|
||||
DWORD error;
|
||||
static char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||
int errlen;
|
||||
|
||||
error = GetLastError();
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
|
||||
PCAP_ERRBUF_SIZE, NULL);
|
||||
|
||||
/*
|
||||
* "FormatMessage()" "helpfully" sticks CR/LF at the end of the
|
||||
* message. Get rid of it.
|
||||
*/
|
||||
errlen = strlen(errbuf);
|
||||
if (errlen >= 2) {
|
||||
errbuf[errlen - 1] = '\0';
|
||||
errbuf[errlen - 2] = '\0';
|
||||
}
|
||||
return (errbuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Not all systems have strerror().
|
||||
*/
|
||||
const char *
|
||||
pcap_strerror(int errnum)
|
||||
{
|
||||
#ifdef HAVE_STRERROR
|
||||
return (strerror(errnum));
|
||||
#else
|
||||
extern int sys_nerr;
|
||||
extern const char *const sys_errlist[];
|
||||
static char ebuf[20];
|
||||
|
||||
if ((unsigned int)errnum < sys_nerr)
|
||||
return ((char *)sys_errlist[errnum]);
|
||||
(void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
|
||||
return(ebuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
return p->setfilter_op(p, fp);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_stats(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
return p->stats_op(p, ps);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_stats_dead(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Statistics aren't available from a pcap_open_dead pcap_t");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_close_dead(pcap_t *p)
|
||||
{
|
||||
/* Nothing to do. */
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_open_dead(int linktype, int snaplen)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
memset (p, 0, sizeof(*p));
|
||||
p->snapshot = snaplen;
|
||||
p->linktype = linktype;
|
||||
p->stats_op = pcap_stats_dead;
|
||||
p->close_op = pcap_close_dead;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
pcap_close(pcap_t *p)
|
||||
{
|
||||
p->close_op(p);
|
||||
if (p->dlt_list != NULL)
|
||||
free(p->dlt_list);
|
||||
pcap_freecode(&p->fcode);
|
||||
free(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* We make the version string static, and return a pointer to it, rather
|
||||
* than exporting the version string directly. On at least some UNIXes,
|
||||
* if you import data from a shared library into an program, the data is
|
||||
* bound into the program binary, so if the string in the version of the
|
||||
* library with which the program was linked isn't the same as the
|
||||
* string in the version of the library with which the program is being
|
||||
* run, various undesirable things may happen (warnings, the string
|
||||
* being the one from the version of the library with which the program
|
||||
* was linked, or even weirder things, such as the string being the one
|
||||
* from the library but being truncated).
|
||||
*/
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* XXX - it'd be nice if we could somehow generate the WinPcap and libpcap
|
||||
* version numbers when building WinPcap. (It'd be nice to do so for
|
||||
* the packet.dll version number as well.)
|
||||
*/
|
||||
static const char wpcap_version_string[] = "3.0";
|
||||
static const char pcap_version_string_fmt[] =
|
||||
"WinPcap version %s, based on libpcap version 0.8";
|
||||
static const char pcap_version_string_packet_dll_fmt[] =
|
||||
"WinPcap version %s (packet.dll version %s), based on libpcap version 0.8";
|
||||
static char *pcap_version_string;
|
||||
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
char *packet_version_string;
|
||||
size_t pcap_version_string_len;
|
||||
|
||||
if (pcap_version_string == NULL) {
|
||||
/*
|
||||
* Generate the version string.
|
||||
*/
|
||||
packet_version_string = PacketGetVersion();
|
||||
if (strcmp(wpcap_version_string, packet_version_string) == 0) {
|
||||
/*
|
||||
* WinPcap version string and packet.dll version
|
||||
* string are the same; just report the WinPcap
|
||||
* version.
|
||||
*/
|
||||
pcap_version_string_len =
|
||||
(sizeof pcap_version_string_fmt - 2) +
|
||||
strlen(wpcap_version_string);
|
||||
pcap_version_string = malloc(pcap_version_string_len);
|
||||
sprintf(pcap_version_string, pcap_version_string_fmt,
|
||||
wpcap_version_string);
|
||||
} else {
|
||||
/*
|
||||
* WinPcap version string and packet.dll version
|
||||
* string are different; that shouldn't be the
|
||||
* case (the two libraries should come from the
|
||||
* same version of WinPcap), so we report both
|
||||
* versions.
|
||||
*/
|
||||
pcap_version_string_len =
|
||||
(sizeof pcap_version_string_packet_dll_fmt - 4) +
|
||||
strlen(wpcap_version_string) +
|
||||
strlen(packet_version_string);
|
||||
pcap_version_string = malloc(pcap_version_string_len);
|
||||
sprintf(pcap_version_string,
|
||||
pcap_version_string_packet_dll_fmt,
|
||||
wpcap_version_string, packet_version_string);
|
||||
}
|
||||
}
|
||||
return (pcap_version_string);
|
||||
}
|
||||
#else
|
||||
#include "version.h"
|
||||
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
return (pcap_version_string);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXXSCW: Temporary addition for the benefit of wpa_supplicant and hostapd,
|
||||
* until libpcap >= 0.9.3 is imported.
|
||||
*/
|
||||
int
|
||||
pcap_inject(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
return (p->inject_op(p, buf, size));
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
/* $NetBSD: pcap.h,v 1.12 2005/10/01 09:55:00 scw Exp $ */
|
||||
|
||||
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the Computer Systems
|
||||
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: /tcpdump/master/libpcap/pcap.h,v 1.45.2.4 2004/01/27 22:56:20 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_h
|
||||
#define lib_pcap_h
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PCAP_VERSION_MAJOR 2
|
||||
#define PCAP_VERSION_MINOR 4
|
||||
|
||||
#define PCAP_ERRBUF_SIZE 256
|
||||
|
||||
/*
|
||||
* Compatibility for systems that have a bpf.h that
|
||||
* predates the bpf typedefs for 64-bit support.
|
||||
*/
|
||||
#if BPF_RELEASE - 0 < 199406
|
||||
typedef int32_t bpf_int32;
|
||||
typedef u_int32_t bpf_u_int32;
|
||||
#endif
|
||||
|
||||
typedef struct pcap pcap_t;
|
||||
typedef struct pcap_dumper pcap_dumper_t;
|
||||
typedef struct pcap_if pcap_if_t;
|
||||
typedef struct pcap_addr pcap_addr_t;
|
||||
|
||||
/*
|
||||
* The first record in the file contains saved values for some
|
||||
* of the flags used in the printout phases of tcpdump.
|
||||
* Many fields here are 32 bit ints so compilers won't insert unwanted
|
||||
* padding; these files need to be interchangeable across architectures.
|
||||
*
|
||||
* Do not change the layout of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure).
|
||||
*
|
||||
* Also, do not change the interpretation of any of the members of this
|
||||
* structure, in any way (this includes using values other than
|
||||
* LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
|
||||
* field).
|
||||
*
|
||||
* Instead:
|
||||
*
|
||||
* introduce a new structure for the new format, if the layout
|
||||
* of the structure changed;
|
||||
*
|
||||
* send mail to "tcpdump-workers@tcpdump.org", requesting a new
|
||||
* magic number for your new capture file format, and, when
|
||||
* you get the new magic number, put it in "savefile.c";
|
||||
*
|
||||
* use that magic number for save files with the changed file
|
||||
* header;
|
||||
*
|
||||
* make the code in "savefile.c" capable of reading files with
|
||||
* the old file header as well as files with the new file header
|
||||
* (using the magic number to determine the header format).
|
||||
*
|
||||
* Then supply the changes to "patches@tcpdump.org", so that future
|
||||
* versions of libpcap and programs that use it (such as tcpdump) will
|
||||
* be able to read your new capture file format.
|
||||
*/
|
||||
struct pcap_file_header {
|
||||
bpf_u_int32 magic;
|
||||
u_short version_major;
|
||||
u_short version_minor;
|
||||
bpf_int32 thiszone; /* gmt to local correction */
|
||||
bpf_u_int32 sigfigs; /* accuracy of timestamps */
|
||||
bpf_u_int32 snaplen; /* max length saved portion of each pkt */
|
||||
bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
|
||||
};
|
||||
|
||||
/*
|
||||
* Each packet in the dump file is prepended with this generic header.
|
||||
* This gets around the problem of different headers for different
|
||||
* packet interfaces.
|
||||
*/
|
||||
struct pcap_pkthdr {
|
||||
struct timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length this packet (off wire) */
|
||||
};
|
||||
|
||||
/*
|
||||
* As returned by the pcap_stats()
|
||||
*/
|
||||
struct pcap_stat {
|
||||
u_int ps_recv; /* number of packets received */
|
||||
u_int ps_drop; /* number of packets dropped */
|
||||
u_int ps_ifdrop; /* drops by interface XXX not yet supported */
|
||||
#ifdef WIN32
|
||||
u_int bs_capt; /* number of packets that reach the application */
|
||||
#endif /* WIN32 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Item in a list of interfaces.
|
||||
*/
|
||||
struct pcap_if {
|
||||
struct pcap_if *next;
|
||||
char *name; /* name to hand to "pcap_open_live()" */
|
||||
char *description; /* textual description of interface, or NULL */
|
||||
struct pcap_addr *addresses;
|
||||
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
|
||||
};
|
||||
|
||||
#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
|
||||
|
||||
/*
|
||||
* Representation of an interface address.
|
||||
*/
|
||||
struct pcap_addr {
|
||||
struct pcap_addr *next;
|
||||
struct sockaddr *addr; /* address */
|
||||
struct sockaddr *netmask; /* netmask for that address */
|
||||
struct sockaddr *broadaddr; /* broadcast address for that address */
|
||||
struct sockaddr *dstaddr; /* P2P destination address for that address */
|
||||
};
|
||||
|
||||
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
|
||||
const u_char *);
|
||||
|
||||
char *pcap_lookupdev(char *);
|
||||
int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
|
||||
pcap_t *pcap_open_live(const char *, int, int, int, char *);
|
||||
pcap_t *pcap_open_dead(int, int);
|
||||
pcap_t *pcap_open_offline(const char *, char *);
|
||||
void pcap_close(pcap_t *);
|
||||
int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
|
||||
int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
|
||||
const u_char*
|
||||
pcap_next(pcap_t *, struct pcap_pkthdr *);
|
||||
int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
|
||||
void pcap_breakloop(pcap_t *);
|
||||
int pcap_stats(pcap_t *, struct pcap_stat *);
|
||||
int pcap_setfilter(pcap_t *, struct bpf_program *);
|
||||
int pcap_getnonblock(pcap_t *, char *);
|
||||
int pcap_setnonblock(pcap_t *, int, char *);
|
||||
void pcap_perror(pcap_t *, char *);
|
||||
const char*
|
||||
pcap_strerror(int);
|
||||
char *pcap_geterr(pcap_t *);
|
||||
int pcap_compile(pcap_t *, struct bpf_program *, char *, int,
|
||||
bpf_u_int32);
|
||||
int pcap_compile_nopcap(int, int, struct bpf_program *,
|
||||
char *, int, bpf_u_int32, char *errbuf);
|
||||
void pcap_freecode(struct bpf_program *);
|
||||
int pcap_datalink(pcap_t *);
|
||||
int pcap_list_datalinks(pcap_t *, int **);
|
||||
int pcap_set_datalink(pcap_t *, int);
|
||||
int pcap_datalink_name_to_val(const char *);
|
||||
const char *pcap_datalink_val_to_name(int);
|
||||
const char *pcap_datalink_val_to_description(int);
|
||||
int pcap_snapshot(pcap_t *);
|
||||
int pcap_is_swapped(pcap_t *);
|
||||
int pcap_major_version(pcap_t *);
|
||||
int pcap_minor_version(pcap_t *);
|
||||
|
||||
/* XXX */
|
||||
FILE *pcap_file(pcap_t *);
|
||||
int pcap_fileno(pcap_t *);
|
||||
|
||||
pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
|
||||
int pcap_dump_flush(pcap_dumper_t *);
|
||||
void pcap_dump_close(pcap_dumper_t *);
|
||||
void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
FILE *pcap_dump_file(pcap_dumper_t *);
|
||||
|
||||
int pcap_findalldevs(pcap_if_t **, char *);
|
||||
void pcap_freealldevs(pcap_if_t *);
|
||||
|
||||
const char *pcap_lib_version(void);
|
||||
|
||||
#ifdef notdef
|
||||
/* XXX this guy lives in the bpf tree */
|
||||
u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
|
||||
#endif
|
||||
int bpf_validate(struct bpf_insn *f, int len);
|
||||
char *bpf_image(struct bpf_insn *, int);
|
||||
void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
/*
|
||||
* XXXSCW: Temporary addition for the benefit of wpa_supplicant and hostapd,
|
||||
* until libpcap >= 0.9.3 is imported.
|
||||
*/
|
||||
int pcap_inject(pcap_t *, const void *, size_t);
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* Win32 definitions
|
||||
*/
|
||||
|
||||
int pcap_setbuff(pcap_t *p, int dim);
|
||||
int pcap_setmode(pcap_t *p, int mode);
|
||||
int pcap_sendpacket(pcap_t *p, u_char *buf, int size);
|
||||
int pcap_setmintocopy(pcap_t *p, int size);
|
||||
|
||||
#ifdef WPCAP
|
||||
/* Include file with the wpcap-specific extensions */
|
||||
#include <Win32-Extensions.h>
|
||||
#endif
|
||||
|
||||
#define MODE_CAPT 0
|
||||
#define MODE_STAT 1
|
||||
#define MODE_MON 2
|
||||
|
||||
#else
|
||||
/*
|
||||
* UN*X definitions
|
||||
*/
|
||||
|
||||
int pcap_get_selectable_fd(pcap_t *);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,288 +0,0 @@
|
||||
#!/usr/local/bin/perl
|
||||
#
|
||||
# $NetBSD: pcap2netbsd,v 1.6 2004/09/22 19:35:47 dyoung Exp $
|
||||
#
|
||||
# Perl script to convert a standard distribution directory for am-utils into
|
||||
# a NetBSD source tree.
|
||||
#
|
||||
# This is done as a script so that as each distribution is released,
|
||||
# only changes from the previous one need to be dealt with as
|
||||
# modifications to this script and related files. This should
|
||||
# reduce the cost of updating from a new release of xntp by an
|
||||
# order of magnitude (or more?)
|
||||
#
|
||||
# This script requires two environment variables set:
|
||||
# SRCDIR - libpcap source directory
|
||||
# TARGETDIR - name of the high level directory to make
|
||||
#
|
||||
# Written by Christos Zoulas Oct 2nd, 1997 for libpcap-0.4a3
|
||||
#
|
||||
# Modified by David Young Sep 19th, 2004 for libpcap-0.8.3
|
||||
#
|
||||
|
||||
$version = "0.8.3";
|
||||
|
||||
# definitions ...
|
||||
|
||||
@subdirs = ("lib/libpcap");
|
||||
|
||||
|
||||
|
||||
@libpcapf = ("bpf_dump.c", "bpf_image.c", "etherent.c", "fad-getad.c",
|
||||
"gencode.c", "grammar.y", "inet.c", "nametoaddr.c", "optimize.c",
|
||||
"pcap-bpf.c", "pcap.c", "savefile.c", "scanner.l");
|
||||
|
||||
@libpcaphf = ("pcap.h", "pcap-namedb.h");
|
||||
@libpcapmf = ("pcap.3");
|
||||
@libpcapdf = ("CHANGES", "README", "atmuni31.h", "llc.h", "pcap-bpf.h",
|
||||
"pcap-int.h", "pcap-stdinc.h", "gencode.h", "ethertype.h",
|
||||
"ppp.h", "sunatmpos.h");
|
||||
|
||||
# sed edit list: file, sed-program
|
||||
%sedlist = (
|
||||
"lib/libpcap/scanner.l", "'s/tokdefs.h/grammar.h/g'"
|
||||
);
|
||||
|
||||
#
|
||||
# Utility Subroutines
|
||||
#
|
||||
|
||||
sub makedir {
|
||||
system("mkdir -p @_");
|
||||
}
|
||||
|
||||
# &fixrcs (fromfile, tofile);
|
||||
sub fixrcs
|
||||
{
|
||||
my ($f, $t) = @_;
|
||||
my @keywords = ("Author", "Date", "Header", "Id", "Locker", "Log",
|
||||
"Name", "RCSfile", "Revision", "Source", "State");
|
||||
my $state = 0;
|
||||
my $hdr = 0;
|
||||
|
||||
open(IFILE, "<$f") || die "Cannot open $f";
|
||||
open(OFILE, ">$t") || die "Cannot create $t";
|
||||
|
||||
if ($t =~ /.*\.[0-9]$/) {
|
||||
print OFILE '.\\" $', 'NetBSD', '$', "\n.\\", "\n";
|
||||
}
|
||||
elsif ($t =~ /.*\.[ch]$/) {
|
||||
print OFILE "/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
|
||||
}
|
||||
elsif ($t =~ /.*\.[yl]$/) {
|
||||
$hdr = 1;
|
||||
}
|
||||
else {
|
||||
print OFILE '$', 'NetBSD', '$', "\n";
|
||||
}
|
||||
while (<IFILE>) {
|
||||
if ($hdr == 1) {
|
||||
if (/%{/) {
|
||||
print OFILE "%{\n/*\t", '$', 'NetBSD', '$', "\t*/\n\n";
|
||||
$hdr = 0;
|
||||
next;
|
||||
}
|
||||
}
|
||||
if ($state == 2) {
|
||||
if (/#endif/) {
|
||||
print OFILE "#else\n__RCSID(", '"$', 'NetBSD', '$"',
|
||||
");\n#endif\n";
|
||||
$state = 0;
|
||||
}
|
||||
}
|
||||
if ($state == 1) {
|
||||
print OFILE "#if 0\n";
|
||||
$state = 2;
|
||||
}
|
||||
if (/#ifndef lint/) {
|
||||
print OFILE "#include <sys/cdefs.h>\n";
|
||||
$state = 1;
|
||||
}
|
||||
foreach $key (@keywords) {
|
||||
s/\$$key\$/$key/g;
|
||||
s/\$$key:(.*)\$/$key:$1/g;
|
||||
}
|
||||
print OFILE $_;
|
||||
}
|
||||
close(IFILE) || die "closing input file";
|
||||
close(OFILE) || die "closing output file";
|
||||
}
|
||||
|
||||
# ©files (fromdir, todir, list of files);
|
||||
sub copyfiles {
|
||||
local ($fdir, $tdir, @list) = @_;
|
||||
local ($f);
|
||||
|
||||
foreach $f (@list) {
|
||||
print " $fdir/$f --> $tdir/$f\n";
|
||||
&fixrcs("$fdir/$f", "$tdir/$f");
|
||||
}
|
||||
}
|
||||
|
||||
# ©file (fromfile, tofile);
|
||||
sub copyfile {
|
||||
local ($f, $t) = @_;
|
||||
|
||||
print " $f --> $t\n";
|
||||
system ("cp $f $t");
|
||||
}
|
||||
|
||||
sub uniq {
|
||||
local (@inlist) = @_;
|
||||
local (@outlist);
|
||||
|
||||
@outlist = ($inlist[0]);
|
||||
for ( $i=1; $i < @inlist; $i++ ) {
|
||||
if ($inlist[$i] ne $inlist[$i-1]) {
|
||||
push (@outlist, $inlist[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
@outlist;
|
||||
}
|
||||
|
||||
sub dumpsrcs {
|
||||
local (@names) = @_;
|
||||
local ($count);
|
||||
|
||||
$count = 0;
|
||||
while ($f = pop(@names)) {
|
||||
print ODATA "$f ";
|
||||
if ($count == 5 && @names > 0) {
|
||||
print ODATA "\\\n";
|
||||
$count = 0;
|
||||
} else {
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
if ($count != 0) {
|
||||
print ODATA "\n";
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Main progarm.
|
||||
#
|
||||
|
||||
$srcdir = $ENV{'SRCDIR'};
|
||||
$targetdir = $ENV{'TARGETDIR'};
|
||||
$incdirs = "-I. -I$srcdir/config -I$srcdir";
|
||||
|
||||
if (!$srcdir | !targetdir) {
|
||||
die "You must define the environment variables SRCDIR and TARGETDIR.\n"
|
||||
}
|
||||
print "Making the NetBSD directory tree.\n";
|
||||
foreach $f (@subdirs) {
|
||||
print " -->$f\n";
|
||||
makedir ("$targetdir/$f");
|
||||
}
|
||||
|
||||
print "Populating the lib/libpcap directory.\n";
|
||||
©files ("$srcdir", "$targetdir/lib/libpcap", @libpcapf, @libpcaphf, @libpcapdf, @libpcapmf);
|
||||
|
||||
#
|
||||
# Build makefiles
|
||||
#
|
||||
|
||||
$first = "True";
|
||||
while ($line = <DATA>) {
|
||||
chop ($line);
|
||||
if (substr($line,0,2) eq "%%") {
|
||||
@cmd = split (/ /,$line);
|
||||
if ($cmd[1] eq "file") {
|
||||
print "Building $targetdir/$cmd[2]\n";
|
||||
if ($first eq "") {
|
||||
close (ODATA);
|
||||
} else {
|
||||
$first = "";
|
||||
}
|
||||
open (ODATA, ">$targetdir/$cmd[2]") ||
|
||||
die "Could not create $targetdir/$cmd[2]";
|
||||
} elsif ($cmd[1] eq "srcs") {
|
||||
print " Defining SRCS\n";
|
||||
if ($first) {
|
||||
die "Data file must start with a %% file!";
|
||||
}
|
||||
print ODATA "SRCS=\t";
|
||||
&dumpsrcs (@libpcapf);
|
||||
} elsif ($cmd[1] eq "incs") {
|
||||
print " Defining INCS\n";
|
||||
if ($first) {
|
||||
die "Data file must start with a %% file!";
|
||||
}
|
||||
print ODATA "INCS=\t";
|
||||
&dumpsrcs (@libpcaphf);
|
||||
} elsif ($cmd[1] eq "man") {
|
||||
print " Defining MAN\n";
|
||||
if ($first) {
|
||||
die "Data file must start with a %% file!";
|
||||
}
|
||||
print ODATA "MAN=\t";
|
||||
&dumpsrcs (@libpcapmf);
|
||||
} elsif ($cmd[1] eq "version") {
|
||||
print " Defining VERSION\n";
|
||||
print ODATA "char pcap_version[] = \"$version\";";
|
||||
} elsif ($cmd[1] eq "NetBSD") {
|
||||
if ($first) {
|
||||
die "Data section must start with a %% file!";
|
||||
}
|
||||
print ODATA "$cmd[2] \$"."NetBSD".": \$ $cmd[3]\n";
|
||||
}
|
||||
} else {
|
||||
if ($first) {
|
||||
die "Data file must start with a %% file!";
|
||||
}
|
||||
print ODATA "$line\n";
|
||||
}
|
||||
}
|
||||
close (ODATA);
|
||||
|
||||
#
|
||||
# Sed transformations of files
|
||||
#
|
||||
foreach $n (keys(%sedlist)) {
|
||||
print "Modifying $n\n";
|
||||
system ("cd $targetdir; sed $sedlist{$n} $n > tmp; mv -f tmp $n");
|
||||
}
|
||||
|
||||
#
|
||||
# end of the script
|
||||
#
|
||||
|
||||
# what follows is the data for makefiles and other special files
|
||||
# that need to be created.
|
||||
|
||||
__END__
|
||||
%% file lib/libpcap/Makefile
|
||||
%% NetBSD #
|
||||
|
||||
LIB= pcap
|
||||
%% man
|
||||
|
||||
LEX= flex
|
||||
|
||||
CFLAGS+=-I. -I${.CURDIR} -DYYBISON
|
||||
CFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_IOCCOM_H=1 -DHAVE_SYS_SOCKIO_H=1
|
||||
CFLAGS+=-DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_SOCKADDR_SA_LEN=1
|
||||
CFLAGS+=-DLBL_ALIGN=1
|
||||
LFLAGS+=-olex.yy.c -Ppcap_
|
||||
YFLAGS+=-ppcap_
|
||||
YHEADER=1
|
||||
|
||||
%% srcs
|
||||
SRCS+= bpf_filter.c version.c
|
||||
|
||||
.PATH: ${.CURDIR}/../../sys/net
|
||||
|
||||
%% incs
|
||||
INCSDIR=/usr/include
|
||||
|
||||
scanner.c: grammar.h
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
%% file lib/libpcap/shlib_version
|
||||
major=0
|
||||
minor=0
|
||||
%% file lib/libpcap/version.c
|
||||
%% NetBSD /* */
|
||||
%% version
|
@ -1,54 +0,0 @@
|
||||
/* $NetBSD: ppp.h,v 1.3 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/* @(#) Header: /tcpdump/master/libpcap/ppp.h,v 1.8 1999/10/19 15:18:31 itojun Exp (LBL) */
|
||||
/*
|
||||
* Point to Point Protocol (PPP) RFC1331
|
||||
*
|
||||
* Copyright 1989 by Carnegie Mellon.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this program for any
|
||||
* purpose and without fee is hereby granted, provided that this copyright
|
||||
* and permission notice appear on all copies and supporting documentation,
|
||||
* the name of Carnegie Mellon not be used in advertising or publicity
|
||||
* pertaining to distribution of the program without specific prior
|
||||
* permission, and notice be given in supporting documentation that copying
|
||||
* and distribution is by permission of Carnegie Mellon and Stanford
|
||||
* University. Carnegie Mellon makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
#define PPP_ADDRESS 0xff /* The address byte value */
|
||||
#define PPP_CONTROL 0x03 /* The control byte value */
|
||||
|
||||
/* Protocol numbers */
|
||||
#define PPP_IP 0x0021 /* Raw IP */
|
||||
#define PPP_OSI 0x0023 /* OSI Network Layer */
|
||||
#define PPP_NS 0x0025 /* Xerox NS IDP */
|
||||
#define PPP_DECNET 0x0027 /* DECnet Phase IV */
|
||||
#define PPP_APPLE 0x0029 /* Appletalk */
|
||||
#define PPP_IPX 0x002b /* Novell IPX */
|
||||
#define PPP_VJC 0x002d /* Van Jacobson Compressed TCP/IP */
|
||||
#define PPP_VJNC 0x002f /* Van Jacobson Uncompressed TCP/IP */
|
||||
#define PPP_BRPDU 0x0031 /* Bridging PDU */
|
||||
#define PPP_STII 0x0033 /* Stream Protocol (ST-II) */
|
||||
#define PPP_VINES 0x0035 /* Banyan Vines */
|
||||
#define PPP_IPV6 0x0057 /* Internet Protocol version 6 */
|
||||
|
||||
#define PPP_HELLO 0x0201 /* 802.1d Hello Packets */
|
||||
#define PPP_LUXCOM 0x0231 /* Luxcom */
|
||||
#define PPP_SNS 0x0233 /* Sigma Network Systems */
|
||||
|
||||
#define PPP_IPCP 0x8021 /* IP Control Protocol */
|
||||
#define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */
|
||||
#define PPP_NSCP 0x8025 /* Xerox NS IDP Control Protocol */
|
||||
#define PPP_DECNETCP 0x8027 /* DECnet Control Protocol */
|
||||
#define PPP_APPLECP 0x8029 /* Appletalk Control Protocol */
|
||||
#define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */
|
||||
#define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */
|
||||
#define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */
|
||||
#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
|
||||
|
||||
#define PPP_LCP 0xc021 /* Link Control Protocol */
|
||||
#define PPP_PAP 0xc023 /* Password Authentication Protocol */
|
||||
#define PPP_LQM 0xc025 /* Link Quality Monitoring */
|
||||
#define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */
|
File diff suppressed because it is too large
Load Diff
@ -1,434 +0,0 @@
|
||||
%{
|
||||
/* $NetBSD: scanner.l,v 1.17 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char rcsid[] =
|
||||
"@(#) Header: /tcpdump/master/libpcap/scanner.l,v 1.95.2.3 2004/03/28 21:45:33 fenner Exp (LBL)";
|
||||
#else
|
||||
__RCSID("$NetBSD: scanner.l,v 1.17 2004/09/27 23:02:53 dyoung Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#ifdef INET6
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include "IP6_misc.h"
|
||||
#endif
|
||||
#else /* WIN32 */
|
||||
#include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
|
||||
#include <netdb.h> /* for "struct addrinfo" */
|
||||
#endif /* WIN32 */
|
||||
|
||||
/* Workaround for AIX 4.3 */
|
||||
#if !defined(AI_NUMERICHOST)
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#endif
|
||||
#endif /*INET6*/
|
||||
#include <pcap-namedb.h>
|
||||
#ifdef INET6
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <memory.h>
|
||||
#endif /*INET6*/
|
||||
#include "grammar.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static int stoi(char *);
|
||||
static inline int xdtoi(int);
|
||||
|
||||
#ifdef FLEX_SCANNER
|
||||
#define YY_NO_UNPUT
|
||||
static YY_BUFFER_STATE in_buffer;
|
||||
#else
|
||||
static char *in_buffer;
|
||||
|
||||
#undef getc
|
||||
#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
|
||||
#endif
|
||||
|
||||
#define yylval pcap_lval
|
||||
#ifdef notdef
|
||||
extern YYSTYPE yylval;
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
|
||||
B ([0-9A-Fa-f][0-9A-Fa-f]?)
|
||||
W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
|
||||
|
||||
%a 16000
|
||||
%o 19000
|
||||
%e 6000
|
||||
%k 4000
|
||||
%p 25000
|
||||
%n 2000
|
||||
|
||||
V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
|
||||
|
||||
V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
|
||||
V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
|
||||
V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
|
||||
V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
|
||||
V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
|
||||
V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
|
||||
V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
|
||||
V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
|
||||
|
||||
V660 ::{W}:{W}:{W}:{W}:{W}:{W}
|
||||
V661 {W}::{W}:{W}:{W}:{W}:{W}
|
||||
V662 {W}:{W}::{W}:{W}:{W}:{W}
|
||||
V663 {W}:{W}:{W}::{W}:{W}:{W}
|
||||
V664 {W}:{W}:{W}:{W}::{W}:{W}
|
||||
V665 {W}:{W}:{W}:{W}:{W}::{W}
|
||||
V666 {W}:{W}:{W}:{W}:{W}:{W}::
|
||||
|
||||
V650 ::{W}:{W}:{W}:{W}:{W}
|
||||
V651 {W}::{W}:{W}:{W}:{W}
|
||||
V652 {W}:{W}::{W}:{W}:{W}
|
||||
V653 {W}:{W}:{W}::{W}:{W}
|
||||
V654 {W}:{W}:{W}:{W}::{W}
|
||||
V655 {W}:{W}:{W}:{W}:{W}::
|
||||
|
||||
V640 ::{W}:{W}:{W}:{W}
|
||||
V641 {W}::{W}:{W}:{W}
|
||||
V642 {W}:{W}::{W}:{W}
|
||||
V643 {W}:{W}:{W}::{W}
|
||||
V644 {W}:{W}:{W}:{W}::
|
||||
|
||||
V630 ::{W}:{W}:{W}
|
||||
V631 {W}::{W}:{W}
|
||||
V632 {W}:{W}::{W}
|
||||
V633 {W}:{W}:{W}::
|
||||
|
||||
V620 ::{W}:{W}
|
||||
V621 {W}::{W}
|
||||
V622 {W}:{W}::
|
||||
|
||||
V610 ::{W}
|
||||
V611 {W}::
|
||||
|
||||
V600 ::
|
||||
|
||||
V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6104 ::{W}:{N}\.{N}\.{N}\.{N}
|
||||
V6114 {W}::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
V6004 ::{N}\.{N}\.{N}\.{N}
|
||||
|
||||
|
||||
V6 ({V680}|{V670}|{V671}|{V672}|{V673}|{V674}|{V675}|{V676}|{V677}|{V660}|{V661}|{V662}|{V663}|{V664}|{V665}|{V666}|{V650}|{V651}|{V652}|{V653}|{V654}|{V655}|{V640}|{V641}|{V642}|{V643}|{V644}|{V630}|{V631}|{V632}|{V633}|{V620}|{V621}|{V622}|{V610}|{V611}|{V600}|{V6604}|{V6504}|{V6514}|{V6524}|{V6534}|{V6544}|{V6554}|{V6404}|{V6414}|{V6424}|{V6434}|{V6444}|{V6304}|{V6314}|{V6324}|{V6334}|{V6204}|{V6214}|{V6224}|{V6104}|{V6114}|{V6004})
|
||||
|
||||
%%
|
||||
dst return DST;
|
||||
src return SRC;
|
||||
|
||||
link|ether|ppp|slip return LINK;
|
||||
fddi|tr|wlan return LINK;
|
||||
arp return ARP;
|
||||
rarp return RARP;
|
||||
ip return IP;
|
||||
sctp return SCTP;
|
||||
tcp return TCP;
|
||||
udp return UDP;
|
||||
icmp return ICMP;
|
||||
igmp return IGMP;
|
||||
igrp return IGRP;
|
||||
pim return PIM;
|
||||
vrrp return VRRP;
|
||||
|
||||
ip6 {
|
||||
#ifdef INET6
|
||||
return IPV6;
|
||||
#else
|
||||
bpf_error("%s not supported", yytext);
|
||||
#endif
|
||||
}
|
||||
icmp6 {
|
||||
#ifdef INET6
|
||||
return ICMPV6;
|
||||
#else
|
||||
bpf_error("%s not supported", yytext);
|
||||
#endif
|
||||
}
|
||||
ah return AH;
|
||||
esp return ESP;
|
||||
|
||||
atalk return ATALK;
|
||||
aarp return AARP;
|
||||
decnet return DECNET;
|
||||
lat return LAT;
|
||||
sca return SCA;
|
||||
moprc return MOPRC;
|
||||
mopdl return MOPDL;
|
||||
|
||||
iso return ISO;
|
||||
esis return ESIS;
|
||||
es-is return ESIS;
|
||||
isis return ISIS;
|
||||
is-is return ISIS;
|
||||
l1 return L1;
|
||||
l2 return L2;
|
||||
iih return IIH;
|
||||
lsp return LSP;
|
||||
snp return SNP;
|
||||
csnp return CSNP;
|
||||
psnp return PSNP;
|
||||
|
||||
clnp return CLNP;
|
||||
|
||||
stp return STP;
|
||||
|
||||
ipx return IPX;
|
||||
|
||||
netbeui return NETBEUI;
|
||||
|
||||
host return HOST;
|
||||
net return NET;
|
||||
mask return NETMASK;
|
||||
port return PORT;
|
||||
proto return PROTO;
|
||||
protochain {
|
||||
#ifdef NO_PROTOCHAIN
|
||||
bpf_error("%s not supported", yytext);
|
||||
#else
|
||||
return PROTOCHAIN;
|
||||
#endif
|
||||
}
|
||||
|
||||
gateway return GATEWAY;
|
||||
|
||||
less return LESS;
|
||||
greater return GREATER;
|
||||
byte return CBYTE;
|
||||
broadcast return TK_BROADCAST;
|
||||
multicast return TK_MULTICAST;
|
||||
|
||||
and|"&&" return AND;
|
||||
or|"||" return OR;
|
||||
not return '!';
|
||||
|
||||
len|length return LEN;
|
||||
inbound return INBOUND;
|
||||
outbound return OUTBOUND;
|
||||
|
||||
vlan return VLAN;
|
||||
|
||||
lane return LANE;
|
||||
llc return LLC;
|
||||
metac return METAC;
|
||||
bcc return BCC;
|
||||
oam return OAM;
|
||||
oamf4 return OAMF4;
|
||||
oamf4ec return OAMF4EC;
|
||||
oamf4sc return OAMF4SC;
|
||||
sc return SC;
|
||||
ilmic return ILMIC;
|
||||
vpi return VPI;
|
||||
vci return VCI;
|
||||
connectmsg return CONNECTMSG;
|
||||
metaconnect return METACONNECT;
|
||||
|
||||
on|ifname return PF_IFNAME;
|
||||
rset|ruleset return PF_RSET;
|
||||
rnr|rulenum return PF_RNR;
|
||||
srnr|subrulenum return PF_SRNR;
|
||||
reason return PF_REASON;
|
||||
action return PF_ACTION;
|
||||
|
||||
[ \r\n\t] ;
|
||||
[+\-*/:\[\]!<>()&|=] return yytext[0];
|
||||
">=" return GEQ;
|
||||
"<=" return LEQ;
|
||||
"!=" return NEQ;
|
||||
"==" return '=';
|
||||
"<<" return LSH;
|
||||
">>" return RSH;
|
||||
${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
|
||||
return AID; }
|
||||
{N} { yylval.i = stoi((char *)yytext); return NUM; }
|
||||
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
|
||||
yylval.s = sdup((char *)yytext); return HID; }
|
||||
{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
|
||||
return EID; }
|
||||
{V6} {
|
||||
#ifdef INET6
|
||||
struct addrinfo hints, *res;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET6;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if (getaddrinfo(yytext, NULL, &hints, &res))
|
||||
bpf_error("bogus IPv6 address %s", yytext);
|
||||
else {
|
||||
yylval.s = sdup((char *)yytext); return HID6;
|
||||
}
|
||||
#else
|
||||
bpf_error("IPv6 address %s not supported", yytext);
|
||||
#endif /*INET6*/
|
||||
}
|
||||
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
|
||||
icmptype { yylval.i = 0; return NUM; }
|
||||
icmpcode { yylval.i = 1; return NUM; }
|
||||
icmp-echoreply { yylval.i = 0; return NUM; }
|
||||
icmp-unreach { yylval.i = 3; return NUM; }
|
||||
icmp-sourcequench { yylval.i = 4; return NUM; }
|
||||
icmp-redirect { yylval.i = 5; return NUM; }
|
||||
icmp-echo { yylval.i = 8; return NUM; }
|
||||
icmp-routeradvert { yylval.i = 9; return NUM; }
|
||||
icmp-routersolicit { yylval.i = 10; return NUM; }
|
||||
icmp-timxceed { yylval.i = 11; return NUM; }
|
||||
icmp-paramprob { yylval.i = 12; return NUM; }
|
||||
icmp-tstamp { yylval.i = 13; return NUM; }
|
||||
icmp-tstampreply { yylval.i = 14; return NUM; }
|
||||
icmp-ireq { yylval.i = 15; return NUM; }
|
||||
icmp-ireqreply { yylval.i = 16; return NUM; }
|
||||
icmp-maskreq { yylval.i = 17; return NUM; }
|
||||
icmp-maskreply { yylval.i = 18; return NUM; }
|
||||
tcpflags { yylval.i = 13; return NUM; }
|
||||
tcp-fin { yylval.i = 0x01; return NUM; }
|
||||
tcp-syn { yylval.i = 0x02; return NUM; }
|
||||
tcp-rst { yylval.i = 0x04; return NUM; }
|
||||
tcp-push { yylval.i = 0x08; return NUM; }
|
||||
tcp-ack { yylval.i = 0x10; return NUM; }
|
||||
tcp-urg { yylval.i = 0x20; return NUM; }
|
||||
[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
|
||||
yylval.s = sdup((char *)yytext); return ID; }
|
||||
"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
|
||||
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
|
||||
bpf_error("illegal token: %s", yytext); }
|
||||
. { bpf_error("illegal char '%c'", *yytext); }
|
||||
%%
|
||||
void
|
||||
lex_init(buf)
|
||||
char *buf;
|
||||
{
|
||||
#ifdef FLEX_SCANNER
|
||||
in_buffer = yy_scan_string(buf);
|
||||
#else
|
||||
in_buffer = buf;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Do any cleanup necessary after parsing.
|
||||
*/
|
||||
void
|
||||
lex_cleanup()
|
||||
{
|
||||
#ifdef FLEX_SCANNER
|
||||
if (in_buffer != NULL)
|
||||
yy_delete_buffer(in_buffer);
|
||||
in_buffer = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Also define a yywrap. Note that if we're using flex, it will
|
||||
* define a macro to map this identifier to pcap_wrap.
|
||||
*/
|
||||
int
|
||||
yywrap()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Hex digit to integer. */
|
||||
static inline int
|
||||
xdtoi(c)
|
||||
register int c;
|
||||
{
|
||||
if (isdigit(c))
|
||||
return c - '0';
|
||||
else if (islower(c))
|
||||
return c - 'a' + 10;
|
||||
else
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert string to integer. Just like atoi(), but checks for
|
||||
* preceding 0x or 0 and uses hex or octal instead of decimal.
|
||||
*/
|
||||
static int
|
||||
stoi(s)
|
||||
char *s;
|
||||
{
|
||||
int base = 10;
|
||||
int n = 0;
|
||||
|
||||
if (*s == '0') {
|
||||
if (s[1] == 'x' || s[1] == 'X') {
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
else {
|
||||
base = 8;
|
||||
s += 1;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
n = n * base + xdtoi(*s++);
|
||||
|
||||
return n;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# $NetBSD: shlib_version,v 1.10 2005/10/01 09:55:27 scw Exp $
|
||||
# $NetBSD: shlib_version,v 1.11 2006/04/25 18:36:45 drochner Exp $
|
||||
# Remember to update distrib/sets/lists/base/shl.* when changing
|
||||
#
|
||||
major=1
|
||||
minor=5
|
||||
major=2
|
||||
minor=0
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from the Stanford/CMU enet packet filter,
|
||||
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
||||
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
||||
* Berkeley Laboratory.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/lib/libpcap/Attic/sll.h,v 1.1 2004/09/27 23:03:15 dyoung Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* For captures on Linux cooked sockets, we construct a fake header
|
||||
* that includes:
|
||||
*
|
||||
* a 2-byte "packet type" which is one of:
|
||||
*
|
||||
* LINUX_SLL_HOST packet was sent to us
|
||||
* LINUX_SLL_BROADCAST packet was broadcast
|
||||
* LINUX_SLL_MULTICAST packet was multicast
|
||||
* LINUX_SLL_OTHERHOST packet was sent to somebody else
|
||||
* LINUX_SLL_OUTGOING packet was sent *by* us;
|
||||
*
|
||||
* a 2-byte Ethernet protocol field;
|
||||
*
|
||||
* a 2-byte link-layer type;
|
||||
*
|
||||
* a 2-byte link-layer address length;
|
||||
*
|
||||
* an 8-byte source link-layer address, whose actual length is
|
||||
* specified by the previous value.
|
||||
*
|
||||
* All fields except for the link-layer address are in network byte order.
|
||||
*
|
||||
* DO NOT change the layout of this structure, or change any of the
|
||||
* LINUX_SLL_ values below. If you must change the link-layer header
|
||||
* for a "cooked" Linux capture, introduce a new DLT_ type (ask
|
||||
* "tcpdump-workers@tcpdump.org" for one, so that you don't give it a
|
||||
* value that collides with a value already being used), and use the
|
||||
* new header in captures of that type, so that programs that can
|
||||
* handle DLT_LINUX_SLL captures will continue to handle them correctly
|
||||
* without any change, and so that capture files with different headers
|
||||
* can be told apart and programs that read them can dissect the
|
||||
* packets in them.
|
||||
*/
|
||||
|
||||
/*
|
||||
* A DLT_LINUX_SLL fake link-layer header.
|
||||
*/
|
||||
#define SLL_HDR_LEN 16 /* total header length */
|
||||
#define SLL_ADDRLEN 8 /* length of address field */
|
||||
|
||||
struct sll_header {
|
||||
u_int16_t sll_pkttype; /* packet type */
|
||||
u_int16_t sll_hatype; /* link-layer address type */
|
||||
u_int16_t sll_halen; /* link-layer address length */
|
||||
u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */
|
||||
u_int16_t sll_protocol; /* protocol */
|
||||
};
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
|
||||
* PACKET_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux, and so that they
|
||||
* don't change even if the PACKET_ values change.
|
||||
*/
|
||||
#define LINUX_SLL_HOST 0
|
||||
#define LINUX_SLL_BROADCAST 1
|
||||
#define LINUX_SLL_MULTICAST 2
|
||||
#define LINUX_SLL_OTHERHOST 3
|
||||
#define LINUX_SLL_OUTGOING 4
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values for "sll_protocol"; these correspond to the
|
||||
* ETH_P_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux. We assume, for now,
|
||||
* that the ETH_P_ values won't change in Linux; if they do, then:
|
||||
*
|
||||
* if we don't translate them in "pcap-linux.c", capture files
|
||||
* won't necessarily be readable if captured on a system that
|
||||
* defines ETH_P_ values that don't match these values;
|
||||
*
|
||||
* if we do translate them in "pcap-linux.c", that makes life
|
||||
* unpleasant for the BPF code generator, as the values you test
|
||||
* for in the kernel aren't the values that you test for when
|
||||
* reading a capture file, so the fixup code run on BPF programs
|
||||
* handed to the kernel ends up having to do more work.
|
||||
*
|
||||
* Add other values here as necessary, for handling packet types that
|
||||
* might show up on non-Ethernet, non-802.x networks. (Not all the ones
|
||||
* in the Linux "if_ether.h" will, I suspect, actually show up in
|
||||
* captures.)
|
||||
*/
|
||||
#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */
|
||||
#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */
|
@ -1,47 +0,0 @@
|
||||
/* $NetBSD: sunatmpos.h,v 1.1.1.2 2004/09/19 21:57:55 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Yen Yen Lim and North Dakota State University
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Yen Yen Lim and
|
||||
North Dakota State University
|
||||
* 4. 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 AUTHOR ``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 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.
|
||||
*
|
||||
* @(#) Header: /tcpdump/master/libpcap/sunatmpos.h,v 1.1 2002/07/11 09:06:47 guy Exp (LBL)
|
||||
*/
|
||||
|
||||
/* SunATM header for ATM packet */
|
||||
#define SUNATM_DIR_POS 0
|
||||
#define SUNATM_VPI_POS 1
|
||||
#define SUNATM_VCI_POS 2
|
||||
#define SUNATM_PKT_BEGIN_POS 4 /* Start of ATM packet */
|
||||
|
||||
/* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
|
||||
#define PT_LANE 0x01 /* LANE */
|
||||
#define PT_LLC 0x02 /* LLC encapsulation */
|
||||
#define PT_ILMI 0x05 /* ILMI */
|
||||
#define PT_QSAAL 0x06 /* Q.SAAL */
|
@ -1,2 +0,0 @@
|
||||
/* $NetBSD: version.c,v 1.4 2004/09/27 23:02:53 dyoung Exp $ */
|
||||
char pcap_version[] = "0.8.3";
|
@ -1,2 +1,3 @@
|
||||
/* $NetBSD: version.h,v 1.1 2004/09/27 23:03:15 dyoung Exp $ */
|
||||
static const char pcap_version_string[] = "libpcap version 0.8.3";
|
||||
/* $NetBSD: version.h,v 1.2 2006/04/25 18:36:45 drochner Exp $ */
|
||||
|
||||
static const char pcap_version_string[] = "libpcap version 0.9.4";
|
||||
|
@ -1,9 +1,9 @@
|
||||
# $NetBSD: Makefile,v 1.2 2005/03/15 17:45:11 peter Exp $
|
||||
# $NetBSD: Makefile,v 1.3 2006/04/25 18:36:44 drochner Exp $
|
||||
# $OpenBSD: Makefile,v 1.6 2003/11/20 23:23:09 avsm Exp $
|
||||
|
||||
.include <bsd.own.mk> # for MKDYNAMICROOT definition
|
||||
|
||||
CPPFLAGS+=-I${NETBSDSRCDIR}/dist/pf/sbin/pflogd -I${NETBSDSRCDIR}/lib/libpcap
|
||||
CPPFLAGS+=-I${NETBSDSRCDIR}/dist/pf/sbin/pflogd -I${NETBSDSRCDIR}/dist/libpcap
|
||||
|
||||
LDADD+= -lpcap -lutil
|
||||
DPAPP+= ${LIBPCAP} ${LIBUTIL}
|
||||
|
Loading…
Reference in New Issue
Block a user