things moved to external.
This commit is contained in:
parent
1b84084183
commit
bbf28506fe
|
@ -1,13 +0,0 @@
|
|||
config.log
|
||||
config.cache
|
||||
config.status
|
||||
config.h
|
||||
.devel
|
||||
stamp-h
|
||||
stamp-h.in
|
||||
Makefile
|
||||
scanner.c
|
||||
grammar.c
|
||||
tokdefs.h
|
||||
version.c
|
||||
version.h
|
|
@ -1,406 +0,0 @@
|
|||
@(#) $Header: /cvsroot/src/dist/libpcap/Attic/CHANGES,v 1.1.1.1 2006/02/27 15:45:38 drochner Exp $ (LBL)
|
||||
|
||||
Mon. September 5, 2005. ken@xelerance.com. Summary for 0.9.4 libpcap release
|
||||
|
||||
Support for radiotap on Linux (Mike Kershaw)
|
||||
Fixes for HP-UX
|
||||
Support for additional Juniper link-layer types
|
||||
Fixes for filters on MPLS-encapsulated packets
|
||||
"vlan" filter fixed
|
||||
"pppoed" and "pppoes" filters added; the latter modifies later
|
||||
parts of the filter expression to look at the PPP headers and
|
||||
headers in the PPP payload
|
||||
|
||||
Tue. July 5, 2005. ken@xelerance.com. Summary for 0.9.3 libpcap release
|
||||
|
||||
Fixes for compiling on nearly every platform,
|
||||
including improved 64bit support
|
||||
MSDOS Support
|
||||
Add support for sending packets
|
||||
OpenBSD pf format support
|
||||
IrDA capture (Linux only)
|
||||
|
||||
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,101 +0,0 @@
|
|||
This file lists people who have contributed to libpcap:
|
||||
|
||||
The current maintainers:
|
||||
Bill Fenner <fenner@research.att.com>
|
||||
Fulvio Risso <risso@polito.it>
|
||||
Guy Harris <guy@alum.mit.edu>
|
||||
Hannes Gredler <hannes@juniper.net>
|
||||
Jun-ichiro itojun Hagino <itojun@iijlab.net>
|
||||
Michael Richardson <mcr@sandelman.ottawa.on.ca>
|
||||
|
||||
Additional people who have contributed patches:
|
||||
|
||||
Alan Bawden <Alan@LCS.MIT.EDU>
|
||||
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
|
||||
Albert Chin <china@thewrittenword.com>
|
||||
Andrew Brown <atatat@atatdot.net>
|
||||
Antti Kantee <pooka@netbsd.org>
|
||||
Arkadiusz Miskiewicz <misiek@pld.org.pl>
|
||||
Armando L. Caro Jr. <acaro@mail.eecis.udel.edu>
|
||||
Assar Westerlund <assar@sics.se>
|
||||
Brian Ginsbach <ginsbach@cray.com>
|
||||
Charles M. Hannum <mycroft@netbsd.org>
|
||||
Chris G. Demetriou <cgd@netbsd.org>
|
||||
Chris Lightfoot <cwrl@users.sourceforge.net>
|
||||
Chris Pepper <pepper@mail.reppep.com>
|
||||
Darren Reed <darrenr@reed.wattle.id.au>
|
||||
David Kaelbling <drk@sgi.com>
|
||||
David Young <dyoung@ojctech.com>
|
||||
Dean Gaudet <dean@arctic.org>
|
||||
Don Ebright <Don.Ebright@compuware.com>
|
||||
Dug Song <dugsong@monkey.org>
|
||||
Eric Anderson <anderse@hpl.hp.com>
|
||||
Erik de Castro Lopo <erik.de.castro.lopo@sensorynetworks.com>
|
||||
Franz Schaefer <schaefer@mond.at>
|
||||
Gianluca Varenni <varenni@netgroup-serv.polito.it>
|
||||
Gilbert Hoyek <gil_hoyek@hotmail.com>
|
||||
Gisle Vanem <giva@bgnett.no>
|
||||
Graeme Hewson <ghewson@cix.compulink.co.uk>
|
||||
Greg Stark <gsstark@mit.edu>
|
||||
Greg Troxel <gdt@ir.bbn.com>
|
||||
Guillaume Pelat <endymion_@users.sourceforge.net>
|
||||
Hyung Sik Yoon <hsyn@kr.ibm.com>
|
||||
Igor Khristophorov <igor@atdot.org>
|
||||
Jan-Philip Velders <jpv@veldersjes.net>
|
||||
Jason R. Thorpe <thorpej@netbsd.org>
|
||||
Javier Achirica <achirica@ttd.net>
|
||||
Jean Tourrilhes <jt@hpl.hp.com>
|
||||
Jefferson Ogata <jogata@nodc.noaa.gov>
|
||||
Jesper Peterson <jesper@endace.com>
|
||||
John Bankier <jbankier@rainfinity.com>
|
||||
Jon Lindgren <jonl@yubyub.net>
|
||||
Juergen Schoenwaelder <schoenw@ibr.cs.tu-bs.de>
|
||||
Kazushi Sugyo <sugyo@pb.jp.nec.com>
|
||||
Klaus Klein <kleink@netbsd.org>
|
||||
Koryn Grant <koryn@endace.com>
|
||||
Krzysztof Halasa <khc@pm.waw.pl>
|
||||
Lorenzo Cavallaro <sullivan@sikurezza.org>
|
||||
Loris Degioanni <loris@netgroup-serv.polito.it>
|
||||
Love Hörnquist-Åstrand <lha@stacken.kth.se>
|
||||
Maciej W. Rozycki <macro@ds2.pg.gda.pl>
|
||||
Marcus Felipe Pereira <marcus@task.com.br>
|
||||
Mark C. Brown <mbrown@hp.com>
|
||||
Mark Pizzolato <List-tcpdump-workers@subscriptions.pizzolato.net>
|
||||
Martin Husemann <martin@netbsd.org>
|
||||
Matthew Luckie <mjl@luckie.org.nz>
|
||||
Mike Kershaw <dragorn@kismetwireless.net>
|
||||
Mike Wiacek <mike@iroot.net>
|
||||
Monroe Williams <monroe@pobox.com>
|
||||
Nicolas Dade <ndade@nsd.dyndns.org>
|
||||
Octavian Cerna <tavy@ylabs.com>
|
||||
Olaf Kirch <okir@caldera.de>
|
||||
Onno van der Linden <onno@simplex.nl>
|
||||
Patrick Marie <mycroft@virgaria.org>
|
||||
Paul Mundt <lethal@linux-sh.org>
|
||||
Pavel Kankovsky <kan@dcit.cz>
|
||||
Pawel Pokrywka <publicpp@gmail.com>
|
||||
Peter Fales <peter@fales-lorenz.net>
|
||||
Peter Jeremy <peter.jeremy@alcatel.com.au>
|
||||
Phil Wood <cpw@lanl.gov>
|
||||
Rafal Maszkowski <rzm@icm.edu.pl>
|
||||
Rick Jones <raj@cup.hp.com>
|
||||
Scott Barron <sb125499@ohiou.edu>
|
||||
Scott Gifford <sgifford@tir.com>
|
||||
Sebastian Krahmer <krahmer@cs.uni-potsdam.de>
|
||||
Shaun Clowes <delius@progsoc.uts.edu.au>
|
||||
Solomon Peachy <pizza@shaftnet.org>
|
||||
Stefan Hudson <hudson@mbay.net>
|
||||
Takashi Yamamoto <yamt@mwd.biglobe.ne.jp>
|
||||
Tanaka Shin-ya <zstanaka@archer.livedoor.com>
|
||||
Tony Li <tli@procket.com>
|
||||
Torsten Landschoff <torsten@debian.org>
|
||||
Uns Lider <unslider@miranda.org>
|
||||
Uwe Girlich <Uwe.Girlich@philosys.de>
|
||||
Xianjie Zhang <xzhang@cup.hp.com>
|
||||
Yen Yen Lim
|
||||
Yoann Vandoorselaere <yoann@prelude-ids.org>
|
||||
|
||||
The original LBL crew:
|
||||
Steve McCanne
|
||||
Craig Leres
|
||||
Van Jacobson
|
|
@ -1,125 +0,0 @@
|
|||
CHANGES
|
||||
ChmodBPF/ChmodBPF
|
||||
ChmodBPF/StartupParameters.plist
|
||||
CREDITS
|
||||
FILES
|
||||
INSTALL.txt
|
||||
LICENSE
|
||||
Makefile.in
|
||||
README
|
||||
README.aix
|
||||
README.dag
|
||||
README.hpux
|
||||
README.linux
|
||||
README.macosx
|
||||
README.septel
|
||||
README.tru64
|
||||
README.Win32
|
||||
SUNOS4/nit_if.o.sparc
|
||||
SUNOS4/nit_if.o.sun3
|
||||
SUNOS4/nit_if.o.sun4c.4.0.3c
|
||||
TODO
|
||||
VERSION
|
||||
acconfig.h
|
||||
aclocal.m4
|
||||
arcnet.h
|
||||
atmuni31.h
|
||||
bpf/net/bpf_filter.c
|
||||
bpf_dump.c
|
||||
bpf_image.c
|
||||
config.guess
|
||||
config.h.in
|
||||
config.sub
|
||||
configure
|
||||
configure.in
|
||||
etherent.c
|
||||
ethertype.h
|
||||
fad-getad.c
|
||||
fad-gifc.c
|
||||
fad-glifc.c
|
||||
fad-null.c
|
||||
fad-win32.c
|
||||
gencode.c
|
||||
gencode.h
|
||||
grammar.y
|
||||
inet.c
|
||||
install-sh
|
||||
lbl/os-aix4.h
|
||||
lbl/os-hpux11.h
|
||||
lbl/os-osf4.h
|
||||
lbl/os-osf5.h
|
||||
lbl/os-solaris2.h
|
||||
lbl/os-sunos4.h
|
||||
lbl/os-ultrix4.h
|
||||
llc.h
|
||||
missing/snprintf.c
|
||||
mkdep
|
||||
msdos/bin2c.c
|
||||
msdos/common.dj
|
||||
msdos/makefile
|
||||
msdos/makefile.dj
|
||||
msdos/makefile.wc
|
||||
msdos/ndis2.c
|
||||
msdos/ndis2.h
|
||||
msdos/ndis_0.asm
|
||||
msdos/pkt_rx0.asm
|
||||
msdos/pkt_rx1.s
|
||||
msdos/pktdrvr.c
|
||||
msdos/pktdrvr.h
|
||||
msdos/readme.dos
|
||||
nametoaddr.c
|
||||
nlpid.h
|
||||
optimize.c
|
||||
packaging/pcap.spec
|
||||
packaging/pcap.spec.in
|
||||
pcap-bpf.c
|
||||
pcap-bpf.h
|
||||
pcap-dag.c
|
||||
pcap-dag.h
|
||||
pcap-dlpi.c
|
||||
pcap-dos.c
|
||||
pcap-dos.h
|
||||
pcap-enet.c
|
||||
pcap-int.h
|
||||
pcap-linux.c
|
||||
pcap-namedb.h
|
||||
pcap-nit.c
|
||||
pcap-nit.h
|
||||
pcap-null.c
|
||||
pcap-pf.c
|
||||
pcap-pf.h
|
||||
pcap-septel.c
|
||||
pcap-septel.h
|
||||
pcap-stdinc.h
|
||||
pcap-snit.c
|
||||
pcap-snoop.c
|
||||
pcap-win32.c
|
||||
pcap.3
|
||||
pcap.c
|
||||
pcap.h
|
||||
pf.h
|
||||
ppp.h
|
||||
savefile.c
|
||||
scanner.l
|
||||
sll.h
|
||||
sunatmpos.h
|
||||
Win32/Include/Gnuc.h
|
||||
Win32/Include/addrinfo.h
|
||||
Win32/Include/bittypes.h
|
||||
Win32/Include/cdecl_ext.h
|
||||
Win32/Include/inetprivate.h
|
||||
Win32/Include/ip6_misc.h
|
||||
Win32/Include/sockstorage.h
|
||||
Win32/Include/arpa/nameser.h
|
||||
Win32/Include/net/if.h
|
||||
Win32/Include/net/netdb.h
|
||||
Win32/Include/net/paths.h
|
||||
Win32/Src/ffs.c
|
||||
Win32/Src/getaddrinfo.c
|
||||
Win32/Src/getnetbynm.c
|
||||
Win32/Src/getnetent.c
|
||||
Win32/Src/getopt.c
|
||||
Win32/Src/getservent.c
|
||||
Win32/Src/inet_aton.c
|
||||
Win32/Src/inet_net.c
|
||||
Win32/Src/inet_pton.c
|
|
@ -1,383 +0,0 @@
|
|||
@(#) $Header: /cvsroot/src/dist/libpcap/Attic/INSTALL.txt,v 1.1.1.1 2006/02/27 15:45:39 drochner Exp $ (LBL)
|
||||
|
||||
To build libpcap, run "./configure" (a shell script). The configure
|
||||
script will determine your system attributes and generate an
|
||||
appropriate Makefile from Makefile.in. Next run "make". If everything
|
||||
goes well you can su to root and run "make install". However, you need
|
||||
not install libpcap if you just want to build tcpdump; just make sure
|
||||
the tcpdump and libpcap directory trees have the same parent
|
||||
directory.
|
||||
|
||||
If configure says:
|
||||
|
||||
configure: warning: cannot determine packet capture interface
|
||||
configure: warning: (see INSTALL for more info)
|
||||
|
||||
then your system either does not support packet capture or your system
|
||||
does support packet capture but libpcap does not support that
|
||||
particular type. (If you have HP-UX, see below.) If your system uses a
|
||||
packet capture not supported by libpcap, please send us patches; don't
|
||||
forget to include an autoconf fragment suitable for use in
|
||||
configure.in.
|
||||
|
||||
It is possible to override the default packet capture type, although
|
||||
the circumstance where this works are limited. For example if you have
|
||||
installed bpf under SunOS 4 and wish to build a snit libpcap:
|
||||
|
||||
./configure --with-pcap=snit
|
||||
|
||||
Another example is to force a supported packet capture type in the case
|
||||
where the configure scripts fails to detect it.
|
||||
|
||||
You will need an ANSI C compiler to build libpcap. The configure script
|
||||
will abort if your compiler is not ANSI compliant. If this happens, use
|
||||
the GNU C compiler, available via anonymous ftp:
|
||||
|
||||
ftp://ftp.gnu.org/pub/gnu/gcc/
|
||||
|
||||
If you use flex, you must use version 2.4.6 or higher. The configure
|
||||
script automatically detects the version of flex and will not use it
|
||||
unless it is new enough. You can use "flex -V" to see what version you
|
||||
have (unless it's really old). The current version of flex is available
|
||||
via anonymous ftp:
|
||||
|
||||
ftp://ftp.ee.lbl.gov/flex-*.tar.Z
|
||||
|
||||
As of this writing, the current version is 2.5.4.
|
||||
|
||||
If you use bison, you must use flex (and visa versa). The configure
|
||||
script automatically falls back to lex and yacc if both flex and bison
|
||||
are not found.
|
||||
|
||||
Sometimes the stock C compiler does not interact well with flex and
|
||||
bison. The list of problems includes undefined references for alloca.
|
||||
You can get around this by installing gcc or manually disabling flex
|
||||
and bison with:
|
||||
|
||||
./configure --without-flex --without-bison
|
||||
|
||||
If your system only has AT&T lex, this is okay unless your libpcap
|
||||
program uses other lex/yacc generated code. (Although it's possible to
|
||||
map the yy* identifiers with a script, we use flex and bison so we
|
||||
don't feel this is necessary.)
|
||||
|
||||
Some systems support the Berkeley Packet Filter natively; for example
|
||||
out of the box OSF and BSD/OS have bpf. If your system does not support
|
||||
bpf, you will need to pick up:
|
||||
|
||||
ftp://ftp.ee.lbl.gov/bpf-*.tar.Z
|
||||
|
||||
Note well: you MUST have kernel source for your operating system in
|
||||
order to install bpf. An exception is SunOS 4; the bpf distribution
|
||||
includes replacement kernel objects for some of the standard SunOS 4
|
||||
network device drivers. See the bpf INSTALL document for more
|
||||
information.
|
||||
|
||||
If you use Solaris, there is a bug with bufmod(7) that is fixed in
|
||||
Solaris 2.3.2 (aka SunOS 5.3.2). Setting a snapshot length with the
|
||||
broken bufmod(7) results in data be truncated from the FRONT of the
|
||||
packet instead of the end. The work around is to not set a snapshot
|
||||
length but this results in performance problems since the entire packet
|
||||
is copied to user space. If you must run an older version of Solaris,
|
||||
there is a patch available from Sun; ask for bugid 1149065. After
|
||||
installing the patch, use "setenv BUFMOD_FIXED" to enable use of
|
||||
bufmod(7). However, we recommend you run a more current release of
|
||||
Solaris.
|
||||
|
||||
If you use the SPARCompiler, you must be careful to not use the
|
||||
/usr/ucb/cc interface. If you do, you will get bogus warnings and
|
||||
perhaps errors. Either make sure your path has /opt/SUNWspro/bin
|
||||
before /usr/ucb or else:
|
||||
|
||||
setenv CC /opt/SUNWspro/bin/cc
|
||||
|
||||
before running configure. (You might have to do a "make distclean"
|
||||
if you already ran configure once).
|
||||
|
||||
Also note that "make depend" won't work; while all of the known
|
||||
universe uses -M, the SPARCompiler uses -xM to generate makefile
|
||||
dependencies.
|
||||
|
||||
If you are trying to do packet capture with a FORE ATM card, you may or
|
||||
may not be able to. They usually only release their driver in object
|
||||
code so unless their driver supports packet capture, there's not much
|
||||
libpcap can do.
|
||||
|
||||
If you get an error like:
|
||||
|
||||
tcpdump: recv_ack: bind error 0x???
|
||||
|
||||
when using DLPI, look for the DL_ERROR_ACK error return values, usually
|
||||
in /usr/include/sys/dlpi.h, and find the corresponding value.
|
||||
|
||||
Under {DEC OSF/1, Digital UNIX, Tru64 UNIX}, packet capture must be
|
||||
enabled before it can be used. For instructions on how to enable packet
|
||||
filter support, see:
|
||||
|
||||
ftp://ftp.digital.com/pub/Digital/dec-faq/Digital-UNIX
|
||||
|
||||
Look for the "How do I configure the Berkeley Packet Filter and capture
|
||||
tcpdump traces?" item.
|
||||
|
||||
Once you enable packet filter support, your OSF system will support bpf
|
||||
natively.
|
||||
|
||||
Under Ultrix, packet capture must be enabled before it can be used. For
|
||||
instructions on how to enable packet filter support, see:
|
||||
|
||||
ftp://ftp.digital.com/pub/Digital/dec-faq/ultrix
|
||||
|
||||
If you use HP-UX, you must have at least version 9 and either the
|
||||
version of cc that supports ANSI C (cc -Aa) or else use the GNU C
|
||||
compiler. You must also buy the optional streams package. If you don't
|
||||
have:
|
||||
|
||||
/usr/include/sys/dlpi.h
|
||||
/usr/include/sys/dlpi_ext.h
|
||||
|
||||
then you don't have the streams package. In addition, we believe you
|
||||
need to install the "9.X LAN and DLPI drivers cumulative" patch
|
||||
(PHNE_6855) to make the version 9 DLPI work with libpcap.
|
||||
|
||||
The DLPI streams package is standard starting with HP-UX 10.
|
||||
|
||||
The HP implementation of DLPI is a little bit eccentric. Unlike
|
||||
Solaris, you must attach /dev/dlpi instead of the specific /dev/*
|
||||
network pseudo device entry in order to capture packets. The PPA is
|
||||
based on the ifnet "index" number. Under HP-UX 9, it is necessary to
|
||||
read /dev/kmem and the kernel symbol file (/hp-ux). Under HP-UX 10,
|
||||
DLPI can provide information for determining the PPA. It does not seem
|
||||
to be possible to trace the loopback interface. Unlike other DLPI
|
||||
implementations, PHYS implies MULTI and SAP and you get an error if you
|
||||
try to enable more than one promiscuous mode at a time.
|
||||
|
||||
It is impossible to capture outbound packets on HP-UX 9. To do so on
|
||||
HP-UX 10, you will, apparently, need a late "LAN products cumulative
|
||||
patch" (at one point, it was claimed that this would be PHNE_18173 for
|
||||
s700/10.20; at another point, it was claimed that the required patches
|
||||
were PHNE_20892, PHNE_20725 and PHCO_10947, or newer patches), and to do
|
||||
so on HP-UX 11 you will, apparently, need the latest lancommon/DLPI
|
||||
patches and the latest driver patch for the interface(s) in use on HP-UX
|
||||
11 (at one point, it was claimed that patches PHNE_19766, PHNE_19826,
|
||||
PHNE_20008, and PHNE_20735 did the trick).
|
||||
|
||||
Furthermore, on HP-UX 10, you will need to turn on a kernel switch by
|
||||
doing
|
||||
|
||||
echo 'lanc_outbound_promisc_flag/W 1' | adb -w /stand/vmunix /dev/mem
|
||||
|
||||
You would have to arrange that this happen on reboots; the right way to
|
||||
do that would probably be to put it into an executable script file
|
||||
"/sbin/init.d/outbound_promisc" and making
|
||||
"/sbin/rc2.d/S350outbound_promisc" a symbolic link to that script.
|
||||
|
||||
Finally, testing shows that there can't be more than one simultaneous
|
||||
DLPI user per network interface.
|
||||
|
||||
If you use Linux, this version of libpcap is known to compile and run
|
||||
under Red Hat 4.0 with the 2.0.25 kernel. It may work with earlier 2.X
|
||||
versions but is guaranteed not to work with 1.X kernels. Running more
|
||||
than one libpcap program at a time, on a system with a 2.0.X kernel, can
|
||||
cause problems since promiscuous mode is implemented by twiddling the
|
||||
interface flags from the libpcap application; the packet capture
|
||||
mechanism in the 2.2 and later kernels doesn't have this problem. Also,
|
||||
packet timestamps aren't very good. This appears to be due to haphazard
|
||||
handling of the timestamp in the kernel.
|
||||
|
||||
Note well: there is rumoured to be a version of tcpdump floating around
|
||||
called 3.0.3 that includes libpcap and is supposed to support Linux.
|
||||
You should be advised that neither the Network Research Group at LBNL
|
||||
nor the Tcpdump Group ever generated a release with this version number.
|
||||
The LBNL Network Research Group notes with interest that a standard
|
||||
cracker trick to get people to install trojans is to distribute bogus
|
||||
packages that have a version number higher than the current release.
|
||||
They also noted with annoyance that 90% of the Linux related bug reports
|
||||
they got are due to changes made to unofficial versions of their page.
|
||||
If you are having trouble but aren't using a version that came from
|
||||
tcpdump.org, please try that before submitting a bug report!
|
||||
|
||||
On Linux, libpcap will not work if the kernel does not have the packet
|
||||
socket option enabled; see the README.linux file for information about
|
||||
this.
|
||||
|
||||
If you use AIX, you may not be able to build libpcap from this release.
|
||||
We do not have an AIX system in house so it's impossible for us to test
|
||||
AIX patches submitted to us. We are told that you must link against
|
||||
/lib/pse.exp, that you must use AIX cc or a GNU C compiler newer than
|
||||
2.7.2, and that you may need to run strload before running a libpcap
|
||||
application.
|
||||
|
||||
Read the README.aix file for information on installing libpcap and
|
||||
configuring your system to be able to support libpcap.
|
||||
|
||||
If you use NeXTSTEP, you will not be able to build libpcap from this
|
||||
release. We hope to support this operating system in some future
|
||||
release of libpcap.
|
||||
|
||||
If you use SINIX, you should be able to build libpcap from this
|
||||
release. It is known to compile and run on SINIX-Y/N 5.42 with the C-DS
|
||||
V1.0 or V1.1 compiler. But note that in some releases of SINIX, yacc
|
||||
emits incorrect code; if grammar.y fails to compile, change every
|
||||
occurence of:
|
||||
|
||||
#ifdef YYDEBUG
|
||||
|
||||
to:
|
||||
#if YYDEBUG
|
||||
|
||||
Another workaround is to use flex and bison.
|
||||
|
||||
If you use SCO, you might have trouble building libpcap from this
|
||||
release. We do not have a machine running SCO and have not had reports
|
||||
of anyone successfully building on it. Since SCO apparently supports
|
||||
DLPI, it's possible the current version works. Meanwhile, SCO provides
|
||||
a tcpdump binary as part of their "Network/Security Tools" package:
|
||||
|
||||
http://www.sco.com/technology/internet/goodies/#SECURITY
|
||||
|
||||
There is also a README that explains how to enable packet capture.
|
||||
|
||||
If you use UnixWare, you will not be able to build libpcap from this
|
||||
release. We hope to support this operating system in some future
|
||||
release of libpcap. Meanwhile, there appears to be an UnixWare port of
|
||||
libpcap 0.0 (and tcpdump 3.0) in:
|
||||
|
||||
ftp://ftp1.freebird.org/pub/mirror/freebird/internet/systools/
|
||||
|
||||
UnixWare appears to use a hacked version of DLPI.
|
||||
|
||||
If linking tcpdump fails with "Undefined: _alloca" when using bison on
|
||||
a Sun4, your version of bison is broken. In any case version 1.16 or
|
||||
higher is recommended (1.14 is known to cause problems 1.16 is known to
|
||||
work). Either pick up a current version from:
|
||||
|
||||
ftp://ftp.gnu.org/pub/gnu/bison
|
||||
|
||||
or hack around it by inserting the lines:
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#else
|
||||
#ifdef sparc
|
||||
#include <alloca.h>
|
||||
#else
|
||||
char *alloca ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
right after the (100 line!) GNU license comment in bison.simple, remove
|
||||
grammar.[co] and fire up make again.
|
||||
|
||||
If you use SunOS 4, your kernel must support streams NIT. If you run a
|
||||
libpcap program and it dies with:
|
||||
|
||||
/dev/nit: No such device
|
||||
|
||||
You must add streams NIT support to your kernel configuration, run
|
||||
config and boot the new kernel.
|
||||
|
||||
If you are running a version of SunOS earlier than 4.1, you will need
|
||||
to replace the Sun supplied /sys/sun{3,4,4c}/OBJ/nit_if.o with the
|
||||
appropriate version from this distribution's SUNOS4 subdirectory and
|
||||
build a new kernel:
|
||||
|
||||
nit_if.o.sun3-sunos4 (any flavor of sun3)
|
||||
nit_if.o.sun4c-sunos4.0.3c (SS1, SS1+, IPC, SLC, etc.)
|
||||
nit_if.o.sun4-sunos4 (Sun4's not covered by
|
||||
nit_if.o.sun4c-sunos4.0.3c)
|
||||
|
||||
These nit replacements fix a bug that makes nit essentially unusable in
|
||||
pre-SunOS 4.1. In addition, our sun4c-sunos4.0.3c nit gives you
|
||||
timestamps to the resolution of the SS-1 clock (1 us) rather than the
|
||||
lousy 20ms timestamps Sun gives you (tcpdump will print out the full
|
||||
timestamp resolution if it finds it's running on a SS-1).
|
||||
|
||||
FILES
|
||||
-----
|
||||
CHANGES - description of differences between releases
|
||||
ChmodBPF/* - Mac OS X startup item to set ownership and permissions
|
||||
on /dev/bpf*
|
||||
CREDITS - people that have helped libpcap along
|
||||
FILES - list of files exported as part of the distribution
|
||||
INSTALL.txt - this file
|
||||
LICENSE - the license under which tcpdump is distributed
|
||||
Makefile.in - compilation rules (input to the configure script)
|
||||
README - description of distribution
|
||||
README.aix - notes on using libpcap on AIX
|
||||
README.dag - notes on using libpcap to capture on Endace DAG devices
|
||||
README.hpux - notes on using libpcap on HP-UX
|
||||
README.linux - notes on using libpcap on Linux
|
||||
README.macosx - notes on using libpcap on Mac OS X
|
||||
README.septel - notes on using libpcap to capture on Intel/Septel devices
|
||||
README.tru64 - notes on using libpcap on Digital/Tru64 UNIX
|
||||
README.Win32 - notes on using libpcap on Win32 systems (with WinPcap)
|
||||
SUNOS4 - pre-SunOS 4.1 replacement kernel nit modules
|
||||
VERSION - version of this release
|
||||
acconfig.h - support for post-2.13 autoconf
|
||||
aclocal.m4 - autoconf macros
|
||||
arcnet.h - ARCNET definitions
|
||||
atmuni31.h - ATM Q.2931 definitions
|
||||
bpf/net - copy of bpf_filter.c
|
||||
bpf_dump.c - BPF program printing routines
|
||||
bpf_filter.c - symlink to bpf/net/bpf_filter.c
|
||||
bpf_image.c - BPF disassembly routine
|
||||
config.guess - autoconf support
|
||||
config.h.in - autoconf input
|
||||
config.sub - autoconf support
|
||||
configure - configure script (run this first)
|
||||
configure.in - configure script source
|
||||
etherent.c - /etc/ethers support routines
|
||||
ethertype.h - Ethernet protocol types and names definitions
|
||||
fad-getad.c - pcap_findalldevs() for systems with getifaddrs()
|
||||
fad-gifc.c - pcap_findalldevs() for systems with only SIOCGIFLIST
|
||||
fad-glifc.c - pcap_findalldevs() for systems with SIOCGLIFCONF
|
||||
fad-null.c - pcap_findalldevs() for systems without capture support
|
||||
fad-win32.c - pcap_findalldevs() for WinPcap
|
||||
gencode.c - BPF code generation routines
|
||||
gencode.h - BPF code generation definitions
|
||||
grammar.y - filter string grammar
|
||||
inet.c - network routines
|
||||
install-sh - BSD style install script
|
||||
lbl/os-*.h - OS-dependent defines and prototypes
|
||||
llc.h - 802.2 LLC SAP definitions
|
||||
missing/* - replacements for missing library functions
|
||||
mkdep - construct Makefile dependency list
|
||||
msdos/* - drivers for MS-DOS capture support
|
||||
nametoaddr.c - hostname to address routines
|
||||
nlpid.h - OSI network layer protocol identifier definitions
|
||||
net - symlink to bpf/net
|
||||
optimize.c - BPF optimization routines
|
||||
packaging - packaging information for building libpcap RPMs
|
||||
pcap-bpf.c - BSD Packet Filter support
|
||||
pcap-bpf.h - BPF definitions
|
||||
pcap-dag.c - Endace DAG device capture support
|
||||
pcap-dag.h - Endace DAG device capture support
|
||||
pcap-dlpi.c - Data Link Provider Interface support
|
||||
pcap-dos.c - MS-DOS capture support
|
||||
pcap-dos.h - headers for MS-DOS capture support
|
||||
pcap-enet.c - enet support
|
||||
pcap-int.h - internal libpcap definitions
|
||||
pcap-linux.c - Linux packet socket support
|
||||
pcap-namedb.h - public libpcap name database definitions
|
||||
pcap-nit.c - SunOS Network Interface Tap support
|
||||
pcap-nit.h - SunOS Network Interface Tap definitions
|
||||
pcap-null.c - dummy monitor support (allows offline use of libpcap)
|
||||
pcap-pf.c - Ultrix and Digital/Tru64 UNIX Packet Filter support
|
||||
pcap-pf.h - Ultrix and Digital/Tru64 UNIX Packet Filter definitions
|
||||
pcap-septel.c - INTEL/Septel device capture support
|
||||
pcap-septel.h - INTEL/Septel device capture support
|
||||
pcap-stdinc.h - includes and #defines for compiling on Win32 systems
|
||||
pcap-snit.c - SunOS 4.x STREAMS-based Network Interface Tap support
|
||||
pcap-snoop.c - IRIX Snoop network monitoring support
|
||||
pcap-win32.c - WinPcap capture support
|
||||
pcap.3 - manual entry
|
||||
pcap.c - pcap utility routines
|
||||
pcap.h - public libpcap definitions
|
||||
pf.h - OpenBSD DLT_PFLOG definitions
|
||||
ppp.h - Point to Point Protocol definitions
|
||||
rawss7.h - information on DLT_ types for SS7
|
||||
savefile.c - offline support
|
||||
scanner.l - filter string scanner
|
||||
sll.h - definitions for Linux cooked mode fake link-layer header
|
||||
sunatmpos.h - definitions for SunATM capturing
|
||||
Win32 - headers and routines for building on Win32 systems
|
|
@ -1,19 +0,0 @@
|
|||
License: BSD
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors 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.
|
|
@ -1,239 +0,0 @@
|
|||
# Copyright (c) 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: /cvsroot/src/dist/libpcap/Attic/Makefile.in,v 1.1.1.1 2006/02/27 15:45:39 drochner Exp $ (LBL)
|
||||
|
||||
#
|
||||
# Various configurable paths (remember to edit Makefile.in, not Makefile)
|
||||
#
|
||||
|
||||
# Top level hierarchy
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
# Pathname of directory to install the include files
|
||||
includedir = @includedir@
|
||||
# Pathname of directory to install the library
|
||||
libdir = @libdir@
|
||||
# Pathname of directory to install the man page
|
||||
mandir = @mandir@
|
||||
|
||||
# VPATH
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
#
|
||||
# You shouldn't need to edit anything below.
|
||||
#
|
||||
|
||||
CC = @CC@
|
||||
CCOPT = @V_CCOPT@
|
||||
INCLS = -I. @V_INCLS@
|
||||
DEFS = @DEFS@ @V_DEFS@
|
||||
LIBS = @V_LIBS@
|
||||
DYEXT = @DYEXT@
|
||||
|
||||
# Standard CFLAGS
|
||||
CFLAGS = $(CCOPT) $(INCLS) $(DEFS)
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
#
|
||||
# Flex and bison allow you to specify the prefixes of the global symbols
|
||||
# used by the generated parser. This allows programs to use lex/yacc
|
||||
# and link against libpcap. If you don't have flex or bison, get them.
|
||||
#
|
||||
LEX = @V_LEX@
|
||||
YACC = @V_YACC@
|
||||
|
||||
# Explicitly define compilation rule since SunOS 4's make doesn't like gcc.
|
||||
# Also, gcc does not remove the .o before forking 'as', which can be a
|
||||
# problem if you don't own the file but can write to the directory.
|
||||
.c.o:
|
||||
@rm -f $@
|
||||
$(CC) $(CFLAGS) -c $(srcdir)/$*.c
|
||||
|
||||
PSRC = pcap-@V_PCAP@.c
|
||||
FSRC = fad-@V_FINDALLDEVS@.c
|
||||
SSRC = @SSRC@
|
||||
CSRC = pcap.c inet.c gencode.c optimize.c nametoaddr.c \
|
||||
etherent.c savefile.c bpf_filter.c bpf_image.c bpf_dump.c
|
||||
GENSRC = scanner.c grammar.c version.c
|
||||
LIBOBJS = @LIBOBJS@
|
||||
|
||||
SRC = $(PSRC) $(FSRC) $(CSRC) $(SSRC) $(GENSRC)
|
||||
|
||||
# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
|
||||
# hack the extra indirection
|
||||
OBJ = $(PSRC:.c=.o) $(FSRC:.c=.o) $(CSRC:.c=.o) $(SSRC:.c=.o) $(GENSRC:.c=.o) $(LIBOBJS)
|
||||
HDR = pcap.h pcap-int.h pcap-namedb.h pcap-nit.h pcap-pf.h \
|
||||
ethertype.h gencode.h gnuc.h
|
||||
GENHDR = \
|
||||
tokdefs.h version.h
|
||||
|
||||
TAGHDR = \
|
||||
pcap-bpf.h
|
||||
|
||||
TAGFILES = \
|
||||
$(SRC) $(HDR) $(TAGHDR)
|
||||
|
||||
CLEANFILES = $(OBJ) libpcap.a $(GENSRC) $(GENHDR) lex.yy.c
|
||||
|
||||
all: libpcap.a
|
||||
|
||||
libpcap.a: $(OBJ)
|
||||
@rm -f $@
|
||||
ar rc $@ $(OBJ) $(LIBS)
|
||||
$(RANLIB) $@
|
||||
|
||||
shared: libpcap.$(DYEXT)
|
||||
|
||||
#
|
||||
# XXX - this works with GNU ld, but won't necessarily work with native
|
||||
# ld on, for example, various SVR4-flavored platforms, or Digital UNIX.
|
||||
#
|
||||
libpcap.so: $(OBJ)
|
||||
@rm -f $@
|
||||
ld -shared -o $@.`cat VERSION` $(OBJ)
|
||||
|
||||
# the following rule succeeds, but the result is untested.
|
||||
libpcap.dylib: $(OBJ)
|
||||
rm -f libpcap*.dylib
|
||||
$(CC) -dynamiclib -undefined error -o libpcap.`cat VERSION`.dylib $(OBJ) \
|
||||
-install_name $(libdir)/libpcap.0.dylib -compatibility_version `cat VERSION` \
|
||||
-current_version `cat VERSION`
|
||||
|
||||
|
||||
scanner.c: $(srcdir)/scanner.l
|
||||
@rm -f $@
|
||||
$(LEX) -t $< > $$$$.$@; mv $$$$.$@ $@
|
||||
|
||||
scanner.o: scanner.c tokdefs.h
|
||||
$(CC) $(CFLAGS) -c scanner.c
|
||||
|
||||
pcap.o: version.h
|
||||
|
||||
tokdefs.h: grammar.c
|
||||
grammar.c: $(srcdir)/grammar.y
|
||||
@rm -f grammar.c tokdefs.h
|
||||
$(YACC) -d $<
|
||||
mv y.tab.c grammar.c
|
||||
mv y.tab.h tokdefs.h
|
||||
|
||||
grammar.o: grammar.c
|
||||
@rm -f $@
|
||||
$(CC) $(CFLAGS) -Dyylval=pcap_lval -c grammar.c
|
||||
|
||||
version.o: version.c
|
||||
$(CC) $(CFLAGS) -c version.c
|
||||
|
||||
snprintf.o: $(srcdir)/missing/snprintf.c
|
||||
$(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
|
||||
|
||||
version.c: $(srcdir)/VERSION
|
||||
@rm -f $@
|
||||
sed -e 's/.*/char pcap_version[] = "&";/' $(srcdir)/VERSION > $@
|
||||
|
||||
#
|
||||
# NOTE: this really is supposed to be static; importing a string
|
||||
# from a shared library does not work very well on many
|
||||
# versions of UNIX (Solaris, Linux, and the BSDs, for example),
|
||||
# so we make the version string static and return it from
|
||||
# a function, which does work.
|
||||
#
|
||||
version.h: $(srcdir)/VERSION
|
||||
@rm -f $@
|
||||
sed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' $(srcdir)/VERSION > $@
|
||||
|
||||
bpf_filter.c: $(srcdir)/bpf/net/bpf_filter.c
|
||||
rm -f bpf_filter.c
|
||||
ln -s $(srcdir)/bpf/net/bpf_filter.c bpf_filter.c
|
||||
|
||||
bpf_filter.o: bpf_filter.c
|
||||
$(CC) $(CFLAGS) -c bpf_filter.c
|
||||
|
||||
install: libpcap.a
|
||||
[ -d $(DESTDIR)$(libdir) ] || \
|
||||
(mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
|
||||
$(INSTALL_DATA) libpcap.a $(DESTDIR)$(libdir)/libpcap.a
|
||||
$(RANLIB) $(DESTDIR)$(libdir)/libpcap.a
|
||||
[ -d $(DESTDIR)$(includedir) ] || \
|
||||
(mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
|
||||
$(INSTALL_DATA) $(srcdir)/pcap.h $(DESTDIR)$(includedir)/pcap.h
|
||||
$(INSTALL_DATA) $(srcdir)/pcap-bpf.h \
|
||||
$(DESTDIR)$(includedir)/pcap-bpf.h
|
||||
$(INSTALL_DATA) $(srcdir)/pcap-namedb.h \
|
||||
$(DESTDIR)$(includedir)/pcap-namedb.h
|
||||
[ -d $(DESTDIR)$(mandir)/man3 ] || \
|
||||
(mkdir -p $(DESTDIR)$(mandir)/man3; chmod 755 $(DESTDIR)$(mandir)/man3)
|
||||
$(INSTALL_DATA) $(srcdir)/pcap.3 \
|
||||
$(DESTDIR)$(mandir)/man3/pcap.3
|
||||
|
||||
install-shared: install-shared-$(DYEXT)
|
||||
install-shared-so: libpcap.so
|
||||
$(INSTALL_PROGRAM) libpcap.so.`cat VERSION` $(DESTDIR)$(libdir)/libpcap.so.`cat VERSION`
|
||||
install-shared-dylib: libpcap.dylib
|
||||
$(INSTALL_PROGRAM) libpcap.`cat VERSION`.dylib $(DESTDIR)$(libdir)/libpcap.`cat VERSION`.dylib
|
||||
VER=`cat VERSION`; cd $(DESTDIR)$(libdir) && ln -sf libpcap.$$VER.dylib libpcap.0.dylib; ln -sf libpcap.0.dylib libpcap.dylib
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(libdir)/libpcap.a
|
||||
rm -f $(DESTDIR)$(includedir)/pcap.h
|
||||
rm -f $(DESTDIR)$(includedir)/pcap-bpf.h
|
||||
rm -f $(DESTDIR)$(includedir)/pcap-namedb.h
|
||||
rm -f $(DESTDIR)$(mandir)/man3/pcap.3
|
||||
|
||||
clean:
|
||||
rm -f $(CLEANFILES) libpcap*.dylib libpcap.so*
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile config.cache config.log config.status \
|
||||
config.h gnuc.h os-proto.h bpf_filter.c stamp-h stamp-h.in
|
||||
rm -rf autom4te.cache
|
||||
|
||||
tags: $(TAGFILES)
|
||||
ctags -wtd $(TAGFILES)
|
||||
|
||||
packaging/pcap.spec: packaging/pcap.spec.in VERSION
|
||||
RPMVERSION=`cat VERSION | sed s/-.*//g`; \
|
||||
sed -e s/@VERSION@/$$RPMVERSION/ -e s/@NAME@/libpcap-`cat VERSION`/ $< > $@
|
||||
|
||||
tar: Makefile packaging/pcap.spec
|
||||
@cwd=`pwd` ; dir=`basename $$cwd` ; name=libpcap-`cat VERSION` ; \
|
||||
list="" ; tar="tar chf" ; \
|
||||
for i in `cat FILES` ; do list="$$list $$name/$$i" ; done; \
|
||||
echo \
|
||||
"rm -f ../$$name; ln -s $$dir ../$$name" ; \
|
||||
rm -f ../$$name; ln -s $$dir ../$$name ; \
|
||||
echo \
|
||||
"(cd .. ; $$tar - [lots of files]) | gzip -c > /tmp/$$name.tar.gz" ; \
|
||||
(cd .. ; $$tar - $$list) | gzip -c > /tmp/$$name.tar.gz ; \
|
||||
echo \
|
||||
"rm -f ../$$name" ; \
|
||||
rm -f ../$$name
|
||||
|
||||
depend: $(GENSRC) $(GENHDR) bpf_filter.c
|
||||
./mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC)
|
||||
|
||||
Makefile: Makefile.in config.status
|
||||
./config.status
|
||||
@echo your Makefile was out of date, now run $(MAKE) again
|
||||
exit 1
|
|
@ -1,94 +0,0 @@
|
|||
@(#) $Header: /cvsroot/src/dist/libpcap/Attic/README,v 1.1.1.1 2006/02/27 15:45:39 drochner Exp $ (LBL)
|
||||
|
||||
LIBPCAP 0.9
|
||||
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.9 of LIBPCAP can be retrieved with the CVS tag "libpcap_0_9rel1":
|
||||
cvs -d :pserver:tcpdump@cvs.tcpdump.org:/tcpdump/master checkout -r libpcap_0_9rel1 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 utilizes 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,46 +0,0 @@
|
|||
Under Win32, libpcap is integrated in the WinPcap packet capture system.
|
||||
WinPcap provides a framework that allows libpcap to capture the packets
|
||||
under Windows 95, Windows 98, Windows ME, Windows NT 4, Windows 2000
|
||||
and Windows XP.
|
||||
WinPcap binaries and source code can be found at http://winpcap.polito.it:
|
||||
they include also a developer's pack with all the necessary to compile
|
||||
libpcap-based applications under Windows.
|
||||
|
||||
How to compile libpcap with Visual Studio
|
||||
-----------------------------------------
|
||||
|
||||
In order to compile libpcap you will need:
|
||||
|
||||
- version 6 (or higher) of Microsoft Visual Studio
|
||||
- The November 2001 (or later) edition of Microsoft Platform
|
||||
Software Development Kit (SDK), that contains some necessary includes
|
||||
for IPv6 support. You can download it from http://www.microsoft.com/sdk
|
||||
- the latest WinPcap sources from http://winpcap.polito.it/install
|
||||
|
||||
The WinPcap source code already contains a recent (usually the latest
|
||||
stable) version of libpcap. If you need to compile a different one,
|
||||
simply download it from www.tcpdump.org and copy the sources in the
|
||||
winpcap\wpcap\libpcap folder of the WinPcap distribution. If you want to
|
||||
compile a libpcap source retrieved from the tcpdump.org CVS, you will
|
||||
have to create the scanner and the grammar by hand (with lex and yacc)
|
||||
or with the cygnus makefile, since The Visual Studio project is not able
|
||||
to build them.
|
||||
|
||||
Open the project file winpcap\wpcap\prj\wpcap.dsw with Visual Studio and
|
||||
build wpcap.dll. wpcap.lib, the library file to link with the applications,
|
||||
will be generated in winpcap\wpcap\lib\. wpcap.dll will be generated in
|
||||
winpcap\wpcap\prj\release or winpcap\wpcap\prj\debug depending on the type
|
||||
of binary that is being created.
|
||||
|
||||
How to compile libpcap with Cygnus
|
||||
----------------------------------
|
||||
|
||||
To build wpcap.dll, cd to the directory WPCAP/PRJ of the WinPcap source code
|
||||
distribution and type "make". libwpcap.a, the library file to link with the
|
||||
applications, will be generated in winpcap\wpcap\lib\. wpcap.dll will be
|
||||
generated in winpcap\wpcap\prj.
|
||||
|
||||
Remember, you CANNOT use the MSVC-generated .lib files with gcc, use
|
||||
libwpcap.a instead.
|
||||
|
||||
"make install" installs wpcap.dll in the Windows system folder.
|
|
@ -1,78 +0,0 @@
|
|||
Using BPF:
|
||||
|
||||
(1) AIX 4.x's version of BPF is undocumented and somewhat unstandard; the
|
||||
current BPF support code includes changes that should work around
|
||||
that; it appears to compile and work on at least one AIX 4.3.3
|
||||
machine.
|
||||
|
||||
Note that the BPF driver and the "/dev/bpf" devices might not exist
|
||||
on your machine; AIX's tcpdump loads the driver and creates the
|
||||
devices if they don't already exist. Our libpcap should do the
|
||||
same, and the configure script should detect that it's on an AIX
|
||||
system and choose BPF even if the devices aren't there.
|
||||
|
||||
(2) If libpcap doesn't compile on your machine when configured to use
|
||||
BPF, or if the workarounds fail to make it work correctly, you
|
||||
should send to tcpdump-workers@tcpdump.org a detailed bug report (if
|
||||
the compile fails, send us the compile error messages; if it
|
||||
compiles but fails to work correctly, send us as detailed as
|
||||
possible a description of the symptoms, including indications of the
|
||||
network link-layer type being wrong or time stamps being wrong).
|
||||
|
||||
If you fix the problems yourself, please send to patches@tcpdump.org
|
||||
a patch, so we can incorporate them into the next release.
|
||||
|
||||
If you don't fix the problems yourself, you can, as a workaround,
|
||||
make libpcap use DLPI instead of BPF.
|
||||
|
||||
This can be done by specifying the flag:
|
||||
|
||||
--with-pcap=dlpi
|
||||
|
||||
to the "configure" script for libpcap.
|
||||
|
||||
If you use DLPI:
|
||||
|
||||
(1) It is a good idea to have the latest version of the DLPI driver on
|
||||
your system, since certain versions may be buggy and cause your AIX
|
||||
system to crash. DLPI is included in the fileset bos.rte.tty. I
|
||||
found that the DLPI driver that came with AIX 4.3.2 was buggy, and
|
||||
had to upgrade to bos.rte.tty 4.3.2.4:
|
||||
|
||||
lslpp -l bos.rte.tty
|
||||
|
||||
bos.rte.tty 4.3.2.4 COMMITTED Base TTY Support and Commands
|
||||
|
||||
Updates for AIX filesets can be obtained from:
|
||||
ftp://service.software.ibm.com/aix/fixes/
|
||||
|
||||
These updates can be installed with the smit program.
|
||||
|
||||
(2) After compiling libpcap, you need to make sure that the DLPI driver
|
||||
is loaded. Type:
|
||||
|
||||
strload -q -d dlpi
|
||||
|
||||
If the result is:
|
||||
|
||||
dlpi: yes
|
||||
|
||||
then the DLPI driver is loaded correctly.
|
||||
|
||||
If it is:
|
||||
|
||||
dlpi: no
|
||||
|
||||
Then you need to type:
|
||||
|
||||
strload -f /etc/dlpi.conf
|
||||
|
||||
Check again with strload -q -d dlpi that the dlpi driver is loaded.
|
||||
|
||||
Alternatively, you can uncomment the lines for DLPI in
|
||||
/etc/pse.conf and reboot the machine; this way DLPI will always
|
||||
be loaded when you boot your system.
|
||||
|
||||
(3) There appears to be a problem in the DLPI code in some versions of
|
||||
AIX, causing a warning about DL_PROMISC_MULTI failing; this might
|
||||
be responsible for DLPI not being able to capture outgoing packets.
|
|
@ -1,93 +0,0 @@
|
|||
|
||||
The following instructions apply if you have a Linux or FreeBSD platform and
|
||||
want libpcap to support the DAG range of passive network monitoring cards from
|
||||
Endace (http://www.endace.com, see below for further contact details).
|
||||
|
||||
1) Install and build the DAG software distribution by following the
|
||||
instructions supplied with that package. Current Endace customers can download
|
||||
the DAG software distibution from https://www.endace.com
|
||||
|
||||
2) Configure libcap. To allow the 'configure' script to locate the DAG
|
||||
software distribution use the '--with-dag' option:
|
||||
|
||||
./configure --with-dag=DIR
|
||||
|
||||
Where DIR is the root of the DAG software distribution, for example
|
||||
/var/src/dag. If the DAG software is correctly detected 'configure' will
|
||||
report:
|
||||
|
||||
checking whether we have DAG API... yes
|
||||
|
||||
If 'configure' reports that there is no DAG API, the directory may have been
|
||||
incorrectly specified or the DAG software was not built before configuring
|
||||
libpcap.
|
||||
|
||||
See also the libpcap INSTALL.txt file for further libpcap configuration
|
||||
options.
|
||||
|
||||
Building libpcap at this stage will include support for both the native packet
|
||||
capture stream (linux or bpf) and for capturing from DAG cards. To build
|
||||
libpcap with only DAG support specify the capture type as 'dag' when
|
||||
configuring libpcap:
|
||||
|
||||
./configure --with-dag=DIR --with-pcap=dag
|
||||
|
||||
Applications built with libpcap configured in this way will only detect DAG
|
||||
cards and will not capture from the native OS packet stream.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Libpcap when built for DAG cards against dag-2.5.1 or later releases:
|
||||
|
||||
Timeouts are supported. pcap_dispatch() will return after to_ms milliseconds
|
||||
regardless of how many packets are received. If to_ms is zero pcap_dispatch()
|
||||
will block waiting for data indefinitely.
|
||||
|
||||
pcap_dispatch() will block on and process a minimum of 64kB of data (before
|
||||
filtering) for efficiency. This can introduce high latencies on quiet
|
||||
interfaces unless a timeout value is set. The timeout expiring will override
|
||||
the 64kB minimum causing pcap_dispatch() to process any available data and
|
||||
return.
|
||||
|
||||
pcap_setnonblock is supported. When nonblock is set, pcap_dispatch() will
|
||||
check once for available data, process any data available up to count, then
|
||||
return immediately.
|
||||
|
||||
pcap_findalldevs() is supported, e.g. dag0, dag1...
|
||||
|
||||
Some DAG cards can provide more than one 'stream' of received data.
|
||||
This can be data from different physical ports, or separated by filtering
|
||||
or load balancing mechanisms. Receive streams have even numbers, e.g.
|
||||
dag0:0, dag0:2 etc. Specifying transmit streams for capture is not supported.
|
||||
|
||||
pcap_setfilter() is supported, BPF programs run in userspace.
|
||||
|
||||
pcap_setdirection() is not supported. Only received traffic is captured.
|
||||
DAG cards normally do not have IP or link layer addresses assigned as
|
||||
they are used to passively monitor links.
|
||||
|
||||
pcap_breakloop() is supported.
|
||||
|
||||
pcap_datalink() and pcap_list_datalinks() are supported. The DAG card does
|
||||
not attempt to set the correct datalink type automatically where more than
|
||||
one type is possible.
|
||||
|
||||
pcap_stats() is supported. ps_drop is the number of packets dropped due to
|
||||
RX stream buffer overflow, this count is before filters are applied (it will
|
||||
include packets that would have been dropped by the filter). The RX stream
|
||||
buffer size is user configurable outside libpcap, typically 16-512MB.
|
||||
|
||||
pcap_get_selectable_fd() is not supported, DAG cards do not support
|
||||
poll/select methods.
|
||||
|
||||
pcap_inject() and pcap_sendpacket() are not supported.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Please submit bug reports via <support@endace.com>.
|
||||
|
||||
Please also visit our Web site at:
|
||||
|
||||
http://www.endace.com/
|
||||
|
||||
For more information about Endace DAG cards contact <sales@endace.com>.
|
|
@ -1,254 +0,0 @@
|
|||
For HP-UX 11i (11.11) and later, there are no known issues with
|
||||
promiscuous mode under HP-UX. If you are using a earlier version of
|
||||
HP-UX and cannot upgrade, please continue reading.
|
||||
|
||||
HP-UX patches to fix packet capture problems
|
||||
|
||||
Note that packet-capture programs such as tcpdump may, on HP-UX, not be
|
||||
able to see packets sent from the machine on which they're running.
|
||||
Some articles on groups.google.com discussing this are:
|
||||
|
||||
http://groups.google.com/groups?selm=82ld3v%2480i%241%40mamenchi.zrz.TU-Berlin.DE
|
||||
|
||||
which says:
|
||||
|
||||
Newsgroups: comp.sys.hp.hpux
|
||||
Subject: Re: Did someone made tcpdump working on 10.20 ?
|
||||
Date: 12/08/1999
|
||||
From: Lutz Jaenicke <jaenicke@emserv1.ee.TU-Berlin.DE>
|
||||
|
||||
In article <82ks5i$5vc$1@news1.dti.ne.jp>, mtsat <mtsat@iris.dti.ne.jp>
|
||||
wrote:
|
||||
>Hello,
|
||||
>
|
||||
>I downloaded and compiled tcpdump3.4 a couple of week ago. I tried to use
|
||||
>it, but I can only see incoming data, never outgoing.
|
||||
>Someone (raj) explained me that a patch was missing, and that this patch
|
||||
>must me "patched" (poked) in order to see outbound data in promiscuous mode.
|
||||
>Many things to do .... So the question is : did someone has already this
|
||||
>"ready to use" PHNE_**** patch ?
|
||||
|
||||
Two things:
|
||||
1. You do need a late "LAN products cumulative patch" (e.g. PHNE_18173
|
||||
for s700/10.20).
|
||||
2. You must use
|
||||
echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
|
||||
You can insert this e.g. into /sbin/init.d/lan
|
||||
|
||||
Best regards,
|
||||
Lutz
|
||||
|
||||
and
|
||||
|
||||
http://groups.google.com/groups?selm=88cf4t%24p03%241%40web1.cup.hp.com
|
||||
|
||||
which says:
|
||||
|
||||
Newsgroups: comp.sys.hp.hpux
|
||||
Subject: Re: tcpdump only shows incoming packets
|
||||
Date: 02/15/2000
|
||||
From: Rick Jones <foo@bar.baz.invalid>
|
||||
|
||||
Harald Skotnes <harald@cc.uit.no> wrote:
|
||||
> I am running HPUX 11.0 on a C200 hanging on a 100Mb switch. I have
|
||||
> compiled libpcap-0.4 an tcpdump-3.4 and it seems to work. But at a
|
||||
> closer look I only get to see the incoming packets not the
|
||||
> outgoing. I have tried tcpflow-0.12 which also uses libpcap and the
|
||||
> same thing happens. Could someone please give me a hint on how to
|
||||
> get this right?
|
||||
|
||||
Search/Read the archives ?-)
|
||||
|
||||
What you are seeing is expected, un-patched, behaviour for an HP-UX
|
||||
system. On 11.00, you need to install the latest lancommon/DLPI
|
||||
patches, and then the latest driver patch for the interface(s) in use.
|
||||
At that point, a miracle happens and you should start seeing outbound
|
||||
traffic.
|
||||
|
||||
[That article also mentions the patch that appears below.]
|
||||
|
||||
and
|
||||
|
||||
http://groups.google.com/groups?selm=38AA973E.96BE7DF7%40cc.uit.no
|
||||
|
||||
which says:
|
||||
|
||||
Newsgroups: comp.sys.hp.hpux
|
||||
Subject: Re: tcpdump only shows incoming packets
|
||||
Date: 02/16/2000
|
||||
From: Harald Skotnes <harald@cc.uit.no>
|
||||
|
||||
Rick Jones wrote:
|
||||
|
||||
...
|
||||
|
||||
> What you are seeing is expected, un-patched, behaviour for an HP-UX
|
||||
> system. On 11.00, you need to install the latest lancommon/DLPI
|
||||
> patches, and then the latest driver patch for the interface(s) in
|
||||
> use. At that point, a miracle happens and you should start seeing
|
||||
> outbound traffic.
|
||||
|
||||
Thanks a lot. I have this problem on several machines running HPUX
|
||||
10.20 and 11.00. The machines where patched up before y2k so did not
|
||||
know what to think. Anyway I have now installed PHNE_19766,
|
||||
PHNE_19826, PHNE_20008, PHNE_20735 on the C200 and now I can see the
|
||||
outbound traffic too. Thanks again.
|
||||
|
||||
(although those patches may not be the ones to install - there may be
|
||||
later patches).
|
||||
|
||||
And another message to tcpdump-workers@tcpdump.org, from Rick Jones:
|
||||
|
||||
Date: Mon, 29 Apr 2002 15:59:55 -0700
|
||||
From: Rick Jones
|
||||
To: tcpdump-workers@tcpdump.org
|
||||
Subject: Re: [tcpdump-workers] I Can't Capture the Outbound Traffic
|
||||
|
||||
...
|
||||
|
||||
http://itrc.hp.com/ would be one place to start in a search for the most
|
||||
up-to-date patches for DLPI and the lan driver(s) used on your system (I
|
||||
cannot guess because 9000/800 is too generic - one hs to use the "model"
|
||||
command these days and/or an ioscan command (see manpage) to guess what
|
||||
the drivers (btlan[3456], gelan, etc) might be involved in addition to
|
||||
DLPI.
|
||||
|
||||
Another option is to upgrade to 11i as outbound promiscuous mode support
|
||||
is there in the base OS, no patches required.
|
||||
|
||||
Another posting:
|
||||
|
||||
http://groups.google.com/groups?selm=7d6gvn%24b3%241%40ocean.cup.hp.com
|
||||
|
||||
indicates that you need to install the optional STREAMS product to do
|
||||
captures on HP-UX 9.x:
|
||||
|
||||
Newsgroups: comp.sys.hp.hpux
|
||||
Subject: Re: tcpdump HP/UX 9.x
|
||||
Date: 03/22/1999
|
||||
From: Rick Jones <foo@bar.baz>
|
||||
|
||||
Dave Barr (barr@cis.ohio-state.edu) wrote:
|
||||
: Has anyone ported tcpdump (or something similar) to HP/UX 9.x?
|
||||
|
||||
I'm reasonably confident that any port of tcpdump to 9.X would require
|
||||
the (then optional) STREAMS product. This would bring DLPI, which is
|
||||
what one uses to access interfaces in promiscuous mode.
|
||||
|
||||
I'm not sure that HP even sells the 9.X STREAMS product any longer,
|
||||
since HP-UX 9.X is off the pricelist (well, maybe 9.10 for the old 68K
|
||||
devices).
|
||||
|
||||
Your best bet is to be up on 10.20 or better if that is at all
|
||||
possible. If your hardware is supported by it, I'd go with HP-UX 11.
|
||||
If you want to see the system's own outbound traffic, you'll never get
|
||||
that functionality on 9.X, but it might happen at some point for 10.20
|
||||
and 11.X.
|
||||
|
||||
rick jones
|
||||
|
||||
(as per other messages cited here, the ability to see the system's own
|
||||
outbound traffic did happen).
|
||||
|
||||
Rick Jones reports that HP-UX 11i needs no patches for outbound
|
||||
promiscuous mode support.
|
||||
|
||||
An additional note, from Jost Martin, for HP-UX 10.20:
|
||||
|
||||
Q: How do I get ethereral on HPUX to capture the _outgoing_ packets
|
||||
of an interface
|
||||
A: You need to get PHNE_20892,PHNE_20725 and PHCO_10947 (or
|
||||
newer, this is as of 4.4.00) and its dependencies. Then you can
|
||||
enable the feature as descibed below:
|
||||
|
||||
Patch Name: PHNE_20892
|
||||
Patch Description: s700 10.20 PCI 100Base-T cumulative patch
|
||||
To trace the outbound packets, please do the following
|
||||
to turn on a global promiscuous switch before running
|
||||
the promiscuous applications like snoop or tcpdump:
|
||||
|
||||
adb -w /stand/vmunix /dev/mem
|
||||
lanc_outbound_promisc_flag/W 1
|
||||
(adb will echo the result showing that the flag has
|
||||
been changed)
|
||||
$quit
|
||||
(Thanks for this part to HP-support, Ratingen)
|
||||
|
||||
The attached hack does this and some security-related stuff
|
||||
(thanks to hildeb@www.stahl.bau.tu-bs.de (Ralf Hildebrandt) who
|
||||
posted the security-part some time ago)
|
||||
|
||||
<<hack_ip_stack>>
|
||||
|
||||
(Don't switch IP-forwarding off, if you need it !)
|
||||
Install the hack as /sbin/init.d/hacl_ip_stack (adjust
|
||||
permissions !) and make a sequencing-symlink
|
||||
/sbin/rc2.d/S350hack_ip_stack pointing to this script.
|
||||
Now all this is done on every reboot.
|
||||
|
||||
According to Rick Jones, the global promiscuous switch also has to be
|
||||
turned on for HP-UX 11.00, but not for 11i - and, in fact, the switch
|
||||
doesn't even exist on 11i.
|
||||
|
||||
Here's the "hack_ip_stack" script:
|
||||
|
||||
-----------------------------------Cut Here-------------------------------------
|
||||
#!/sbin/sh
|
||||
#
|
||||
# nettune: hack kernel parms for safety
|
||||
|
||||
OKAY=0
|
||||
ERROR=-1
|
||||
|
||||
# /usr/contrib/bin fuer nettune auf Pfad
|
||||
PATH=/sbin:/usr/sbin:/usr/bin:/usr/contrib/bin
|
||||
export PATH
|
||||
|
||||
|
||||
##########
|
||||
# main #
|
||||
##########
|
||||
|
||||
case $1 in
|
||||
start_msg)
|
||||
print "Tune IP-Stack for security"
|
||||
exit $OKAY
|
||||
;;
|
||||
|
||||
stop_msg)
|
||||
print "This action is not applicable"
|
||||
exit $OKAY
|
||||
;;
|
||||
|
||||
stop)
|
||||
exit $OKAY
|
||||
;;
|
||||
|
||||
start)
|
||||
;; # fall through
|
||||
|
||||
*)
|
||||
print "USAGE: $0 {start_msg | stop_msg | start | stop}" >&2
|
||||
exit $ERROR
|
||||
;;
|
||||
esac
|
||||
|
||||
###########
|
||||
# start #
|
||||
###########
|
||||
|
||||
#
|
||||
# tcp-Sequence-Numbers nicht mehr inkrementieren sondern random
|
||||
# Syn-Flood-Protection an
|
||||
# ip_forwarding aus
|
||||
# Source-Routing aus
|
||||
# Ausgehende Packets an ethereal/tcpdump etc.
|
||||
|
||||
/usr/contrib/bin/nettune -s tcp_random_seq 2 || exit $ERROR
|
||||
/usr/contrib/bin/nettune -s hp_syn_protect 1 || exit $ERROR
|
||||
/usr/contrib/bin/nettune -s ip_forwarding 0 || exit $ERROR
|
||||
echo 'ip_block_source_routed/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem || exit $ERROR
|
||||
echo 'lanc_outbound_promisc_flag/W 1' | adb -w /stand/vmunix /dev/mem || exit $ERROR
|
||||
|
||||
exit $OKAY
|
||||
-----------------------------------Cut Here-------------------------------------
|
|
@ -1,88 +0,0 @@
|
|||
In order for libpcap to be able to capture packets on a Linux system,
|
||||
the "packet" protocol must be supported by your kernel. If it is not,
|
||||
you may get error messages such as
|
||||
|
||||
modprobe: can't locate module net-pf-17
|
||||
|
||||
in "/var/adm/messages", or may get messages such as
|
||||
|
||||
socket: Address family not supported by protocol
|
||||
|
||||
from applications using libpcap.
|
||||
|
||||
You must configure the kernel with the CONFIG_PACKET option for this
|
||||
protocol; the following note is from the Linux "Configure.help" file for
|
||||
the 2.0[.x] kernel:
|
||||
|
||||
Packet socket
|
||||
CONFIG_PACKET
|
||||
The Packet protocol is used by applications which communicate
|
||||
directly with network devices without an intermediate network
|
||||
protocol implemented in the kernel, e.g. tcpdump. If you want them
|
||||
to work, choose Y.
|
||||
|
||||
This driver is also available as a module called af_packet.o ( =
|
||||
code which can be inserted in and removed from the running kernel
|
||||
whenever you want). If you want to compile it as a module, say M
|
||||
here and read Documentation/modules.txt; if you use modprobe or
|
||||
kmod, you may also want to add "alias net-pf-17 af_packet" to
|
||||
/etc/modules.conf.
|
||||
|
||||
and the note for the 2.2[.x] kernel says:
|
||||
|
||||
Packet socket
|
||||
CONFIG_PACKET
|
||||
The Packet protocol is used by applications which communicate
|
||||
directly with network devices without an intermediate network
|
||||
protocol implemented in the kernel, e.g. tcpdump. If you want them
|
||||
to work, choose Y. This driver is also available as a module called
|
||||
af_packet.o ( = code which can be inserted in and removed from the
|
||||
running kernel whenever you want). If you want to compile it as a
|
||||
module, say M here and read Documentation/modules.txt. You will
|
||||
need to add 'alias net-pf-17 af_packet' to your /etc/conf.modules
|
||||
file for the module version to function automatically. If unsure,
|
||||
say Y.
|
||||
|
||||
In addition, there is an option that, in 2.2 and later kernels, will
|
||||
allow packet capture filters specified to programs such as tcpdump to be
|
||||
executed in the kernel, so that packets that don't pass the filter won't
|
||||
be copied from the kernel to the program, rather than having all packets
|
||||
copied to the program and libpcap doing the filtering in user mode.
|
||||
|
||||
Copying packets from the kernel to the program consumes a significant
|
||||
amount of CPU, so filtering in the kernel can reduce the overhead of
|
||||
capturing packets if a filter has been specified that discards a
|
||||
significant number of packets. (If no filter is specified, it makes no
|
||||
difference whether the filtering isn't performed in the kernel or isn't
|
||||
performed in user mode. :-))
|
||||
|
||||
The option for this is the CONFIG_FILTER option; the "Configure.help"
|
||||
file says:
|
||||
|
||||
Socket filtering
|
||||
CONFIG_FILTER
|
||||
The Linux Socket Filter is derived from the Berkeley Packet Filter.
|
||||
If you say Y here, user-space programs can attach a filter to any
|
||||
socket and thereby tell the kernel that it should allow or disallow
|
||||
certain types of data to get through the socket. Linux Socket
|
||||
Filtering works on all socket types except TCP for now. See the text
|
||||
file linux/Documentation/networking/filter.txt for more information.
|
||||
If unsure, say N.
|
||||
|
||||
|
||||
Statistics:
|
||||
Statistics reported by pcap are platform specific. The statistics
|
||||
reported by pcap_stats on Linux are as follows:
|
||||
|
||||
2.2.x
|
||||
=====
|
||||
ps_recv Number of packets that were accepted by the pcap filter
|
||||
ps_drops Always 0, this statistic is not gatherd on this platform
|
||||
|
||||
2.4.x
|
||||
=====
|
||||
ps_rec Number of packets that were accepted by the pcap filter
|
||||
ps_drops Number of packets that had passed filtering but were not
|
||||
passed on to pcap due to things like buffer shortage, etc.
|
||||
This is useful because these are packets you are interested in
|
||||
but won't be reported by, for example, tcpdump output.
|
|
@ -1,43 +0,0 @@
|
|||
As with other systems using BPF, Mac OS X allows users with read access
|
||||
to the BPF devices to capture packets with libpcap and allows users with
|
||||
write access to the BPF devices to send packets with libpcap.
|
||||
|
||||
On some systems that use BPF, the BPF devices live on the root file
|
||||
system, and the permissions and/or ownership on those devices can be
|
||||
changed to give users other than root permission to read or write those
|
||||
devices.
|
||||
|
||||
On newer versions of FreeBSD, the BPF devices live on devfs, and devfs
|
||||
can be configured to set the permissions and/or ownership of those
|
||||
devices to give users other than root permission to read or write those
|
||||
devices.
|
||||
|
||||
On Mac OS X, the BPF devices live on devfs, but the OS X version of
|
||||
devfs is based on an older (non-default) FreeBSD devfs, and that version
|
||||
of devfs cannot be configured to set the permissions and/or ownership of
|
||||
those devices.
|
||||
|
||||
Therefore, we supply a "startup item" for OS X that will change the
|
||||
ownership of the BPF devices so that the "admin" group owns them, and
|
||||
will change the permission of the BPF devices to rw-rw----, so that all
|
||||
users in the "admin" group - i.e., all users with "Allow user to
|
||||
administer this computer" turned on - have both read and write access to
|
||||
them.
|
||||
|
||||
The startup item is in the ChmodBPF directory in the source tree. A
|
||||
/Library/StartupItems directory should be created if it doesn't already
|
||||
exist, and the ChmodBPF directory should be copied to the
|
||||
/Library/StartupItems directory (copy the entire directory, so that
|
||||
there's a /Library/StartupItems/ChmodBPF directory, containing all the
|
||||
files in the source tree's ChmodBPF directory; don't copy the individual
|
||||
items in that directory to /Library/StartupItems).
|
||||
|
||||
If you want to give a particular user permission to access the BPF
|
||||
devices, rather than giving all administrative users permission to
|
||||
access them, you can have the ChmodBPF/ChmodBPF script change the
|
||||
ownership of /dev/bpf* without changing the permissions. If you want to
|
||||
give a particular user permission to read and write the BPF devices and
|
||||
give the administrative users permission to read but not write the BPF
|
||||
devices, you can have the script change the owner to that user, the
|
||||
group to "admin", and the permissions to rw-r-----. Other possibilities
|
||||
are left as an exercise for the reader.
|
|
@ -1,50 +0,0 @@
|
|||
The following instructions apply if you have a Linux platform and want
|
||||
libpcap to support the Septel range of passive network monitoring cards
|
||||
from Intel (http://www.intel.com)
|
||||
|
||||
1) Install and build the Septel software distribution by following the
|
||||
instructions supplied with that package.
|
||||
|
||||
2) Configure libcap. To allow the 'configure' script to locate the Septel
|
||||
software distribution use the '--with-septel' option:
|
||||
|
||||
./configure --with-septel=DIR
|
||||
|
||||
where DIR is the root of the Septel software distribution, for example
|
||||
/var/src/septel.
|
||||
|
||||
By default (if you write only ./configure --with-septel) it takes
|
||||
./../septel as argument for DIR.
|
||||
|
||||
If the Septel software is correctly detected 'configure' will
|
||||
report:
|
||||
|
||||
checking whether we have Septel API... yes
|
||||
|
||||
If 'configure' reports that there is no Septel API, the directory may have been
|
||||
incorrectly specified or the Septel software was not built before configuring
|
||||
libpcap.
|
||||
|
||||
See also the libpcap INSTALL.txt file for further libpcap configuration
|
||||
options.
|
||||
|
||||
Building libpcap at this stage will include support for both the native
|
||||
packet capture stream and for capturing from Septel cards. To build
|
||||
libpcap with only Septel support specify the capture type as 'septel'
|
||||
when configuring libpcap:
|
||||
|
||||
./configure --with-septel=DIR --with-pcap=septel
|
||||
|
||||
Applications built with libpcap configured in this way will only detect Septel
|
||||
cards and will not capture from the native OS packet stream.
|
||||
|
||||
Note: As mentioned in pcap-septel.c we should first edit the system.txt
|
||||
file to change the user part example (UPE) module id to 0xdd instead of
|
||||
0x2d for technical reason. So this change in system.txt is crutial and
|
||||
things will go wrong if it's not done. System.txt along with config.txt
|
||||
are configuration files that are edited by the user before running the
|
||||
gctload program that uses these files for initialising modules and
|
||||
configuring parameters.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
for more information please contact me : gil_hoyek@hotmail.com
|
|
@ -1,49 +0,0 @@
|
|||
The following instructions are applicable to Tru64 UNIX
|
||||
(formerly Digital UNIX (formerly DEC OSF/1)) version 4.0, and
|
||||
probably to later versions as well; at least some options apply to
|
||||
Digital UNIX 3.2 - perhaps all do.
|
||||
|
||||
In order to use kernel packet filtering on this system, you have
|
||||
to configure it in such a way:
|
||||
|
||||
Kernel configuration
|
||||
--------------------
|
||||
|
||||
The packet filtering kernel option must be enabled at kernel
|
||||
installation. If it was not the case, you can rebuild the kernel with
|
||||
"doconfig -c" after adding the following line in the kernel
|
||||
configuration file (/sys/conf/<HOSTNAME>):
|
||||
|
||||
option PACKETFILTER
|
||||
|
||||
or use "doconfig" without any arguments to add the packet filter driver
|
||||
option via the kernel option menu (see the system administration
|
||||
documentation for information on how to do this).
|
||||
|
||||
Device configuration
|
||||
--------------------
|
||||
|
||||
Devices used for packet filtering must be created thanks to
|
||||
the following command (executed in the /dev directory):
|
||||
|
||||
./MAKEDEV pfilt
|
||||
|
||||
Interface configuration
|
||||
-----------------------
|
||||
|
||||
In order to capture all packets on a network, you may want to allow
|
||||
applications to put the interface on that network into "local copy"
|
||||
mode, so that tcpdump can see packets sent by the host on which it's
|
||||
running as well as packets received by that host, and to put the
|
||||
interface into "promiscuous" mode, so that tcpdump can see packets on
|
||||
the network segment not sent to the host on which it's running, by using
|
||||
the pfconfig(1) command:
|
||||
|
||||
pfconfig +c +p <network_device>
|
||||
|
||||
or allow application to put any interface into "local copy" or
|
||||
"promiscuous" mode by using the command:
|
||||
|
||||
pfconfig +c +p -a
|
||||
|
||||
Note: all instructions given require root privileges.
|
|
@ -1,42 +0,0 @@
|
|||
TODO list for libpcap
|
||||
=======================
|
||||
|
||||
Important stuff (to be done before the next release)
|
||||
---------------
|
||||
|
||||
General
|
||||
|
||||
- configure should not be in the CVS. Most open source projects have an
|
||||
autogen.sh script to run autoconf etc. after checkout. I think we
|
||||
should stick to the standard.
|
||||
|
||||
- The source files should be better documented. There is no official
|
||||
design guideline for what is done where. There should be a common coding
|
||||
style (okay, you can guess that by looking at the code) and a guide for
|
||||
what needs to be documented.
|
||||
|
||||
Linux kernel interface
|
||||
|
||||
- Currently there is a race condition in that a socket is activated at the
|
||||
same time it is opened - before applying a filter. This has to
|
||||
be corrected so that capture starts when pcap_read is called for the
|
||||
first time.
|
||||
|
||||
Less urgent items
|
||||
-----------------
|
||||
|
||||
- Better documentation and cleanup of the interface. I am seeing a few
|
||||
problems at the first glance which needs fixing:
|
||||
+ pcap_lookupnet makes little to no sense with protocols != IPv4
|
||||
+ not very well suited for interactive programs (think ethereal). There
|
||||
should be a way for the application to get a file descriptor which it
|
||||
has to monitor and a callback in pcap which has to be called on
|
||||
activity (XXX - "pcap_fileno()" handles the first part, although
|
||||
"select()" and "poll()" don't work on BPF devices on most BSDs, and
|
||||
you can call "pcap_dispatch()" as the dispatch routine after putting
|
||||
the descriptor into non-blocking mode)
|
||||
+ too many functions. There are a lot of functions for everything which
|
||||
violates the KISS principle. Why do we need pcap_strerror, pcap_perror
|
||||
and pcap_geterr?
|
||||
+ the manpage has a brief description of each function but where is the
|
||||
big picture? Seems like you need to buy UNP for that...
|
|
@ -1 +0,0 @@
|
|||
0.9.4
|
|
@ -1,7 +0,0 @@
|
|||
/* Long story short: aclocal.m4 depends on autoconf 2.13
|
||||
* implementation details wrt "const"; newer versions
|
||||
* have different implementation details so for now we
|
||||
* put "const" here. This may cause duplicate definitions
|
||||
* in config.h but that should be OK since they're the same.
|
||||
*/
|
||||
#undef const
|
|
@ -1,900 +0,0 @@
|
|||
dnl @(#) $Header: /cvsroot/src/dist/libpcap/Attic/aclocal.m4,v 1.1.1.1 2006/02/27 15:45:40 drochner Exp $ (LBL)
|
||||
dnl
|
||||
dnl Copyright (c) 1995, 1996, 1997, 1998
|
||||
dnl The Regents of the University of California. All rights reserved.
|
||||
dnl
|
||||
dnl Redistribution and use in source and binary forms, with or without
|
||||
dnl modification, are permitted provided that: (1) source code distributions
|
||||
dnl retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
dnl distributions including binary code include the above copyright notice and
|
||||
dnl this paragraph in its entirety in the documentation or other materials
|
||||
dnl provided with the distribution, and (3) all advertising materials mentioning
|
||||
dnl features or use of this software display the following acknowledgement:
|
||||
dnl ``This product includes software developed by the University of California,
|
||||
dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
dnl the University nor the names of its contributors may be used to endorse
|
||||
dnl or promote products derived from this software without specific prior
|
||||
dnl written permission.
|
||||
dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
dnl
|
||||
dnl LBL autoconf macros
|
||||
dnl
|
||||
|
||||
dnl
|
||||
dnl Determine which compiler we're using (cc or gcc)
|
||||
dnl If using gcc, determine the version number
|
||||
dnl If using cc, require that it support ansi prototypes
|
||||
dnl If using gcc, use -O2 (otherwise use -O)
|
||||
dnl If using cc, explicitly specify /usr/local/include
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_C_INIT(copt, incls)
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl $1 (copt set)
|
||||
dnl $2 (incls set)
|
||||
dnl CC
|
||||
dnl LDFLAGS
|
||||
dnl ac_cv_lbl_gcc_vers
|
||||
dnl LBL_CFLAGS
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_C_INIT,
|
||||
[AC_PREREQ(2.12)
|
||||
AC_BEFORE([$0], [AC_PROG_CC])
|
||||
AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
|
||||
AC_BEFORE([$0], [AC_LBL_DEVEL])
|
||||
AC_ARG_WITH(gcc, [ --without-gcc don't use gcc])
|
||||
$1="-O"
|
||||
$2=""
|
||||
if test "${srcdir}" != "." ; then
|
||||
$2="-I\$(srcdir)"
|
||||
fi
|
||||
if test "${CFLAGS+set}" = set; then
|
||||
LBL_CFLAGS="$CFLAGS"
|
||||
fi
|
||||
if test -z "$CC" ; then
|
||||
case "$target_os" in
|
||||
|
||||
bsdi*)
|
||||
AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
|
||||
if test $SHLICC2 = yes ; then
|
||||
CC=shlicc2
|
||||
export CC
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if test -z "$CC" -a "$with_gcc" = no ; then
|
||||
CC=cc
|
||||
export CC
|
||||
fi
|
||||
AC_PROG_CC
|
||||
if test "$GCC" = yes ; then
|
||||
if test "$SHLICC2" = yes ; then
|
||||
ac_cv_lbl_gcc_vers=2
|
||||
$1="-O2"
|
||||
else
|
||||
AC_MSG_CHECKING(gcc version)
|
||||
AC_CACHE_VAL(ac_cv_lbl_gcc_vers,
|
||||
ac_cv_lbl_gcc_vers=`$CC -v 2>&1 | \
|
||||
sed -e '/^gcc version /!d' \
|
||||
-e 's/^gcc version //' \
|
||||
-e 's/ .*//' -e 's/^[[[^0-9]]]*//' \
|
||||
-e 's/\..*//'`)
|
||||
AC_MSG_RESULT($ac_cv_lbl_gcc_vers)
|
||||
if test $ac_cv_lbl_gcc_vers -gt 1 ; then
|
||||
$1="-O2"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
AC_MSG_CHECKING(that $CC handles ansi prototypes)
|
||||
AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[int frob(int, char *)],
|
||||
ac_cv_lbl_cc_ansi_prototypes=yes,
|
||||
ac_cv_lbl_cc_ansi_prototypes=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes)
|
||||
if test $ac_cv_lbl_cc_ansi_prototypes = no ; then
|
||||
case "$target_os" in
|
||||
|
||||
hpux*)
|
||||
AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
|
||||
savedcflags="$CFLAGS"
|
||||
CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
|
||||
AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[int frob(int, char *)],
|
||||
ac_cv_lbl_cc_hpux_cc_aa=yes,
|
||||
ac_cv_lbl_cc_hpux_cc_aa=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa)
|
||||
if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then
|
||||
AC_MSG_ERROR(see the INSTALL doc for more info)
|
||||
fi
|
||||
CFLAGS="$savedcflags"
|
||||
V_CCOPT="-Aa $V_CCOPT"
|
||||
AC_DEFINE(_HPUX_SOURCE,1,[needed on HP-UX])
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_ERROR(see the INSTALL doc for more info)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
$2="$$2 -I/usr/local/include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||
|
||||
case "$target_os" in
|
||||
|
||||
irix*)
|
||||
V_CCOPT="$V_CCOPT -xansi -signed -g3"
|
||||
;;
|
||||
|
||||
osf*)
|
||||
V_CCOPT="$V_CCOPT -std1 -g3"
|
||||
;;
|
||||
|
||||
ultrix*)
|
||||
AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
|
||||
AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[struct a { int b; };
|
||||
void c(const struct a *)],
|
||||
ac_cv_lbl_cc_const_proto=yes,
|
||||
ac_cv_lbl_cc_const_proto=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
|
||||
if test $ac_cv_lbl_cc_const_proto = no ; then
|
||||
AC_DEFINE(const,)
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
|
||||
#
|
||||
# Try compiling a sample of the type of code that appears in
|
||||
# gencode.c with "inline", "__inline__", and "__inline".
|
||||
#
|
||||
# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
|
||||
# as it just tests whether a function returning "int" can be inlined;
|
||||
# at least some versions of HP's C compiler can inline that, but can't
|
||||
# inline a function that returns a struct pointer.
|
||||
#
|
||||
# Make sure we use the V_CCOPT flags, because some of those might
|
||||
# disable inlining.
|
||||
#
|
||||
AC_DEFUN(AC_LBL_C_INLINE,
|
||||
[AC_MSG_CHECKING(for inline)
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$V_CCOPT"
|
||||
AC_CACHE_VAL(ac_cv_lbl_inline, [
|
||||
ac_cv_lbl_inline=""
|
||||
ac_lbl_cc_inline=no
|
||||
for ac_lbl_inline in inline __inline__ __inline
|
||||
do
|
||||
AC_TRY_COMPILE(
|
||||
[#define inline $ac_lbl_inline
|
||||
static inline struct iltest *foo(void);
|
||||
struct iltest {
|
||||
int iltest1;
|
||||
int iltest2;
|
||||
};
|
||||
|
||||
static inline struct iltest *
|
||||
foo()
|
||||
{
|
||||
static struct iltest xxx;
|
||||
|
||||
return &xxx;
|
||||
}],,ac_lbl_cc_inline=yes,)
|
||||
if test "$ac_lbl_cc_inline" = yes ; then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if test "$ac_lbl_cc_inline" = yes ; then
|
||||
ac_cv_lbl_inline=$ac_lbl_inline
|
||||
fi])
|
||||
CFLAGS="$save_CFLAGS"
|
||||
if test ! -z "$ac_cv_lbl_inline" ; then
|
||||
AC_MSG_RESULT($ac_cv_lbl_inline)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
|
||||
|
||||
dnl
|
||||
dnl Use pfopen.c if available and pfopen() not in standard libraries
|
||||
dnl Require libpcap
|
||||
dnl Look for libpcap in ..
|
||||
dnl Use the installed libpcap if there is no local version
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_LIBPCAP(pcapdep, incls)
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl $1 (pcapdep set)
|
||||
dnl $2 (incls appended)
|
||||
dnl LIBS
|
||||
dnl LBL_LIBS
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_LIBPCAP,
|
||||
[AC_REQUIRE([AC_LBL_LIBRARY_NET])
|
||||
dnl
|
||||
dnl save a copy before locating libpcap.a
|
||||
dnl
|
||||
LBL_LIBS="$LIBS"
|
||||
pfopen=/usr/examples/packetfilter/pfopen.c
|
||||
if test -f $pfopen ; then
|
||||
AC_CHECK_FUNCS(pfopen)
|
||||
if test $ac_cv_func_pfopen = "no" ; then
|
||||
AC_MSG_RESULT(Using $pfopen)
|
||||
LIBS="$LIBS $pfopen"
|
||||
fi
|
||||
fi
|
||||
AC_MSG_CHECKING(for local pcap library)
|
||||
libpcap=FAIL
|
||||
lastdir=FAIL
|
||||
places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
|
||||
egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
|
||||
for dir in $places ../libpcap libpcap ; do
|
||||
basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'`
|
||||
if test $lastdir = $basedir ; then
|
||||
dnl skip alphas when an actual release is present
|
||||
continue;
|
||||
fi
|
||||
lastdir=$dir
|
||||
if test -r $dir/pcap.c ; then
|
||||
libpcap=$dir/libpcap.a
|
||||
d=$dir
|
||||
dnl continue and select the last one that exists
|
||||
fi
|
||||
done
|
||||
if test $libpcap = FAIL ; then
|
||||
AC_MSG_RESULT(not found)
|
||||
AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
|
||||
if test $libpcap = FAIL ; then
|
||||
AC_MSG_ERROR(see the INSTALL doc for more info)
|
||||
fi
|
||||
else
|
||||
$1=$libpcap
|
||||
$2="-I$d $$2"
|
||||
AC_MSG_RESULT($libpcap)
|
||||
fi
|
||||
LIBS="$libpcap $LIBS"
|
||||
case "$target_os" in
|
||||
|
||||
aix*)
|
||||
pseexe="/lib/pse.exp"
|
||||
AC_MSG_CHECKING(for $pseexe)
|
||||
if test -f $pseexe ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
LIBS="$LIBS -I:$pseexe"
|
||||
fi
|
||||
;;
|
||||
esac])
|
||||
|
||||
dnl
|
||||
dnl Define RETSIGTYPE and RETSIGVAL
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_TYPE_SIGNAL
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl RETSIGTYPE (defined)
|
||||
dnl RETSIGVAL (defined)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_TYPE_SIGNAL,
|
||||
[AC_BEFORE([$0], [AC_LBL_LIBPCAP])
|
||||
AC_TYPE_SIGNAL
|
||||
if test "$ac_cv_type_signal" = void ; then
|
||||
AC_DEFINE(RETSIGVAL,[],[return value of signal handlers])
|
||||
else
|
||||
AC_DEFINE(RETSIGVAL,(0),[return value of signal handlers])
|
||||
fi
|
||||
case "$target_os" in
|
||||
|
||||
irix*)
|
||||
AC_DEFINE(_BSD_SIGNALS,1,[get BSD semantics on Irix])
|
||||
;;
|
||||
|
||||
*)
|
||||
dnl prefer sigset() to sigaction()
|
||||
AC_CHECK_FUNCS(sigset)
|
||||
if test $ac_cv_func_sigset = no ; then
|
||||
AC_CHECK_FUNCS(sigaction)
|
||||
fi
|
||||
;;
|
||||
esac])
|
||||
|
||||
dnl
|
||||
dnl If using gcc, make sure we have ANSI ioctl definitions
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_FIXINCLUDES
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_FIXINCLUDES,
|
||||
[if test "$GCC" = yes ; then
|
||||
AC_MSG_CHECKING(for ANSI ioctl definitions)
|
||||
AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
|
||||
AC_TRY_COMPILE(
|
||||
[/*
|
||||
* This generates a "duplicate case value" when fixincludes
|
||||
* has not be run.
|
||||
*/
|
||||
# include <sys/types.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/ioctl.h>
|
||||
# ifdef HAVE_SYS_IOCCOM_H
|
||||
# include <sys/ioccom.h>
|
||||
# endif],
|
||||
[switch (0) {
|
||||
case _IO('A', 1):;
|
||||
case _IO('B', 1):;
|
||||
}],
|
||||
ac_cv_lbl_gcc_fixincludes=yes,
|
||||
ac_cv_lbl_gcc_fixincludes=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
|
||||
if test $ac_cv_lbl_gcc_fixincludes = no ; then
|
||||
# Don't cache failure
|
||||
unset ac_cv_lbl_gcc_fixincludes
|
||||
AC_MSG_ERROR(see the INSTALL for more info)
|
||||
fi
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Check for flex, default to lex
|
||||
dnl Require flex 2.4 or higher
|
||||
dnl Check for bison, default to yacc
|
||||
dnl Default to lex/yacc if both flex and bison are not available
|
||||
dnl Define the yy prefix string if using flex and bison
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl $1 (lex set)
|
||||
dnl $2 (yacc appended)
|
||||
dnl $3 (optional flex and bison -P prefix)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_LEX_AND_YACC,
|
||||
[AC_ARG_WITH(flex, [ --without-flex don't use flex])
|
||||
AC_ARG_WITH(bison, [ --without-bison don't use bison])
|
||||
if test "$with_flex" = no ; then
|
||||
$1=lex
|
||||
else
|
||||
AC_CHECK_PROGS($1, flex, lex)
|
||||
fi
|
||||
if test "$$1" = flex ; then
|
||||
# The -V flag was added in 2.4
|
||||
AC_MSG_CHECKING(for flex 2.4 or higher)
|
||||
AC_CACHE_VAL(ac_cv_lbl_flex_v24,
|
||||
if flex -V >/dev/null 2>&1; then
|
||||
ac_cv_lbl_flex_v24=yes
|
||||
else
|
||||
ac_cv_lbl_flex_v24=no
|
||||
fi)
|
||||
AC_MSG_RESULT($ac_cv_lbl_flex_v24)
|
||||
if test $ac_cv_lbl_flex_v24 = no ; then
|
||||
s="2.4 or higher required"
|
||||
AC_MSG_WARN(ignoring obsolete flex executable ($s))
|
||||
$1=lex
|
||||
fi
|
||||
fi
|
||||
if test "$with_bison" = no ; then
|
||||
$2=yacc
|
||||
else
|
||||
AC_CHECK_PROGS($2, bison, yacc)
|
||||
fi
|
||||
if test "$$2" = bison ; then
|
||||
$2="$$2 -y"
|
||||
fi
|
||||
if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
|
||||
AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
|
||||
$1=lex
|
||||
$2=yacc
|
||||
fi
|
||||
if test "$$1" = flex -a -n "$3" ; then
|
||||
$1="$$1 -P$3"
|
||||
$2="$$2 -p $3"
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if union wait is used with WEXITSTATUS()
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_UNION_WAIT
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl DECLWAITSTATUS (defined)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_UNION_WAIT,
|
||||
[AC_MSG_CHECKING(if union wait is used)
|
||||
AC_CACHE_VAL(ac_cv_lbl_union_wait,
|
||||
AC_TRY_COMPILE([
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>],
|
||||
[int status;
|
||||
u_int i = WEXITSTATUS(status);
|
||||
u_int j = waitpid(0, &status, 0);],
|
||||
ac_cv_lbl_union_wait=no,
|
||||
ac_cv_lbl_union_wait=yes))
|
||||
AC_MSG_RESULT($ac_cv_lbl_union_wait)
|
||||
if test $ac_cv_lbl_union_wait = yes ; then
|
||||
AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
|
||||
else
|
||||
AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_SOCKADDR_SA_LEN
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl HAVE_SOCKADDR_SA_LEN (defined)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
|
||||
[AC_MSG_CHECKING(if sockaddr struct has sa_len member)
|
||||
AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
|
||||
AC_TRY_COMPILE([
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>],
|
||||
[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
|
||||
ac_cv_lbl_sockaddr_has_sa_len=yes,
|
||||
ac_cv_lbl_sockaddr_has_sa_len=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
|
||||
if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
|
||||
AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has sa_len])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if there's a sockaddr_storage structure
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_SOCKADDR_STORAGE
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl HAVE_SOCKADDR_STORAGE (defined)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_SOCKADDR_STORAGE,
|
||||
[AC_MSG_CHECKING(if sockaddr_storage struct exists)
|
||||
AC_CACHE_VAL(ac_cv_lbl_has_sockaddr_storage,
|
||||
AC_TRY_COMPILE([
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>],
|
||||
[u_int i = sizeof (struct sockaddr_storage)],
|
||||
ac_cv_lbl_has_sockaddr_storage=yes,
|
||||
ac_cv_lbl_has_sockaddr_storage=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_has_sockaddr_storage)
|
||||
if test $ac_cv_lbl_has_sockaddr_storage = yes ; then
|
||||
AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[if struct sockaddr_storage exists])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
|
||||
dnl dl_module_id_1 member
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined)
|
||||
dnl
|
||||
dnl NOTE: any compile failure means we conclude that it doesn't have
|
||||
dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h>
|
||||
dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type,
|
||||
dnl we conclude it doesn't have that member (which is OK, as either we
|
||||
dnl won't be using code that would use that member, or we wouldn't
|
||||
dnl compile in any case).
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1,
|
||||
[AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member)
|
||||
AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
|
||||
AC_TRY_COMPILE([
|
||||
# include <sys/types.h>
|
||||
# include <sys/dlpi.h>
|
||||
# include <sys/dlpi_ext.h>],
|
||||
[u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)],
|
||||
ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes,
|
||||
ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1)
|
||||
if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
|
||||
AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1,1,[if ppa_info_t_dl_module_id exists])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if -R is used
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_HAVE_RUN_PATH
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl ac_cv_lbl_have_run_path (yes or no)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
|
||||
[AC_MSG_CHECKING(for ${CC-cc} -R)
|
||||
AC_CACHE_VAL(ac_cv_lbl_have_run_path,
|
||||
[echo 'main(){}' > conftest.c
|
||||
${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
|
||||
if test ! -s conftest.out ; then
|
||||
ac_cv_lbl_have_run_path=yes
|
||||
else
|
||||
ac_cv_lbl_have_run_path=no
|
||||
fi
|
||||
rm -f conftest*])
|
||||
AC_MSG_RESULT($ac_cv_lbl_have_run_path)
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Due to the stupid way it's implemented, AC_CHECK_TYPE is nearly useless.
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_CHECK_TYPE
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl int32_t (defined)
|
||||
dnl u_int32_t (defined)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_CHECK_TYPE,
|
||||
[AC_MSG_CHECKING(for $1 using $CC)
|
||||
AC_CACHE_VAL(ac_cv_lbl_have_$1,
|
||||
AC_TRY_COMPILE([
|
||||
# include "confdefs.h"
|
||||
# include <sys/types.h>
|
||||
# if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <stddef.h>
|
||||
# endif],
|
||||
[$1 i],
|
||||
ac_cv_lbl_have_$1=yes,
|
||||
ac_cv_lbl_have_$1=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_have_$1)
|
||||
if test $ac_cv_lbl_have_$1 = no ; then
|
||||
AC_DEFINE($1, $2, [if we have $1])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if unaligned memory accesses fail
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_UNALIGNED_ACCESS
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl LBL_ALIGN (DEFINED)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
|
||||
[AC_MSG_CHECKING(if unaligned accesses fail)
|
||||
AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
|
||||
[case "$host_cpu" in
|
||||
|
||||
#
|
||||
# These are CPU types where:
|
||||
#
|
||||
# the CPU faults on an unaligned access, but at least some
|
||||
# OSes that support that CPU catch the fault and simulate
|
||||
# the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
|
||||
# the simulation is slow, so we don't want to use it;
|
||||
#
|
||||
# the CPU, I infer (from the old
|
||||
#
|
||||
# XXX: should also check that they don't do weird things (like on arm)
|
||||
#
|
||||
# comment) doesn't fault on unaligned accesses, but doesn't
|
||||
# do a normal unaligned fetch, either (e.g., presumably, ARM);
|
||||
#
|
||||
# for whatever reason, the test program doesn't work
|
||||
# (this has been claimed to be the case for several of those
|
||||
# CPUs - I don't know what the problem is; the problem
|
||||
# was reported as "the test program dumps core" for SuperH,
|
||||
# but that's what the test program is *supposed* to do -
|
||||
# it dumps core before it writes anything, so the test
|
||||
# for an empty output file should find an empty output
|
||||
# file and conclude that unaligned accesses don't work).
|
||||
#
|
||||
# This run-time test won't work if you're cross-compiling, so
|
||||
# in order to support cross-compiling for a particular CPU,
|
||||
# we have to wire in the list of CPU types anyway, as far as
|
||||
# I know, so perhaps we should just have a set of CPUs on
|
||||
# which we know it doesn't work, a set of CPUs on which we
|
||||
# know it does work, and have the script just fail on other
|
||||
# cpu types and update it when such a failure occurs.
|
||||
#
|
||||
alpha*|arm*|hp*|mips*|sh*|sparc*|ia64|nv1)
|
||||
ac_cv_lbl_unaligned_fail=yes
|
||||
;;
|
||||
|
||||
*)
|
||||
cat >conftest.c <<EOF
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
# include <stdio.h>
|
||||
unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
|
||||
main() {
|
||||
unsigned int i;
|
||||
pid_t pid;
|
||||
int status;
|
||||
/* avoid "core dumped" message */
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
exit(2);
|
||||
if (pid > 0) {
|
||||
/* parent */
|
||||
pid = waitpid(pid, &status, 0);
|
||||
if (pid < 0)
|
||||
exit(3);
|
||||
exit(!WIFEXITED(status));
|
||||
}
|
||||
/* child */
|
||||
i = *(unsigned int *)&a[[1]];
|
||||
printf("%d\n", i);
|
||||
exit(0);
|
||||
}
|
||||
EOF
|
||||
${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
|
||||
conftest.c $LIBS >/dev/null 2>&1
|
||||
if test ! -x conftest ; then
|
||||
dnl failed to compile for some reason
|
||||
ac_cv_lbl_unaligned_fail=yes
|
||||
else
|
||||
./conftest >conftest.out
|
||||
if test ! -s conftest.out ; then
|
||||
ac_cv_lbl_unaligned_fail=yes
|
||||
else
|
||||
ac_cv_lbl_unaligned_fail=no
|
||||
fi
|
||||
fi
|
||||
rm -f conftest* core core.conftest
|
||||
;;
|
||||
esac])
|
||||
AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
|
||||
if test $ac_cv_lbl_unaligned_fail = yes ; then
|
||||
AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl If using gcc and the file .devel exists:
|
||||
dnl Compile with -g (if supported) and -Wall
|
||||
dnl If using gcc 2, do extra prototype checking
|
||||
dnl If an os prototype include exists, symlink os-proto.h to it
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_DEVEL(copt)
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl $1 (copt appended)
|
||||
dnl HAVE_OS_PROTO_H (defined)
|
||||
dnl os-proto.h (symlinked)
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_DEVEL,
|
||||
[rm -f os-proto.h
|
||||
if test "${LBL_CFLAGS+set}" = set; then
|
||||
$1="$$1 ${LBL_CFLAGS}"
|
||||
fi
|
||||
if test -f .devel ; then
|
||||
if test "$GCC" = yes ; then
|
||||
if test "${LBL_CFLAGS+set}" != set; then
|
||||
if test "$ac_cv_prog_cc_g" = yes ; then
|
||||
$1="-g $$1"
|
||||
fi
|
||||
$1="$$1 -Wall"
|
||||
if test $ac_cv_lbl_gcc_vers -gt 1 ; then
|
||||
$1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
case "$target_os" in
|
||||
|
||||
irix6*)
|
||||
V_CCOPT="$V_CCOPT -n32"
|
||||
;;
|
||||
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
|
||||
name="lbl/os-$os.h"
|
||||
if test -f $name ; then
|
||||
ln -s $name os-proto.h
|
||||
AC_DEFINE(HAVE_OS_PROTO_H,1,[if there's an os_proto.h])
|
||||
else
|
||||
AC_MSG_WARN(can't find $name)
|
||||
fi
|
||||
fi])
|
||||
|
||||
dnl
|
||||
dnl Improved version of AC_CHECK_LIB
|
||||
dnl
|
||||
dnl Thanks to John Hawkinson (jhawk@mit.edu)
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
|
||||
dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
|
||||
dnl
|
||||
dnl results:
|
||||
dnl
|
||||
dnl LIBS
|
||||
dnl
|
||||
|
||||
define(AC_LBL_CHECK_LIB,
|
||||
[AC_MSG_CHECKING([for $2 in -l$1])
|
||||
dnl Use a cache variable name containing both the library and function name,
|
||||
dnl because the test really is for library $1 defining function $2, not
|
||||
dnl just for library $1. Separate tests with the same $1 and different $2's
|
||||
dnl may have different results.
|
||||
ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
|
||||
AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
|
||||
[ac_save_LIBS="$LIBS"
|
||||
LIBS="-l$1 $5 $LIBS"
|
||||
AC_TRY_LINK(dnl
|
||||
ifelse([$2], [main], , dnl Avoid conflicting decl of main.
|
||||
[/* Override any gcc2 internal prototype to avoid an error. */
|
||||
]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
])dnl
|
||||
[/* We use char because int might match the return type of a gcc2
|
||||
builtin and then its argument prototype would still apply. */
|
||||
char $2();
|
||||
]),
|
||||
[$2()],
|
||||
eval "ac_cv_lbl_lib_$ac_lib_var=yes",
|
||||
eval "ac_cv_lbl_lib_$ac_lib_var=no")
|
||||
LIBS="$ac_save_LIBS"
|
||||
])dnl
|
||||
if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
|
||||
AC_MSG_RESULT(yes)
|
||||
ifelse([$3], ,
|
||||
[changequote(, )dnl
|
||||
ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
|
||||
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
|
||||
changequote([, ])dnl
|
||||
AC_DEFINE_UNQUOTED($ac_tr_lib)
|
||||
LIBS="-l$1 $LIBS"
|
||||
], [$3])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
ifelse([$4], , , [$4
|
||||
])dnl
|
||||
fi
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl AC_LBL_LIBRARY_NET
|
||||
dnl
|
||||
dnl This test is for network applications that need socket() and
|
||||
dnl gethostbyname() -ish functions. Under Solaris, those applications
|
||||
dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
|
||||
dnl with "-lnsl" but should *not* link with "-lsocket" because
|
||||
dnl libsocket.a breaks a number of things (for instance:
|
||||
dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
|
||||
dnl versions of IRIX).
|
||||
dnl
|
||||
dnl Unfortunately, many application developers are not aware of this,
|
||||
dnl and mistakenly write tests that cause -lsocket to be used under
|
||||
dnl IRIX. It is also easy to write tests that cause -lnsl to be used
|
||||
dnl under operating systems where neither are necessary (or useful),
|
||||
dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
|
||||
dnl
|
||||
dnl This test exists so that every application developer does not test
|
||||
dnl this in a different, and subtly broken fashion.
|
||||
|
||||
dnl It has been argued that this test should be broken up into two
|
||||
dnl seperate tests, one for the resolver libraries, and one for the
|
||||
dnl libraries necessary for using Sockets API. Unfortunately, the two
|
||||
dnl are carefully intertwined and allowing the autoconf user to use
|
||||
dnl them independantly potentially results in unfortunate ordering
|
||||
dnl dependancies -- as such, such component macros would have to
|
||||
dnl carefully use indirection and be aware if the other components were
|
||||
dnl executed. Since other autoconf macros do not go to this trouble,
|
||||
dnl and almost no applications use sockets without the resolver, this
|
||||
dnl complexity has not been implemented.
|
||||
dnl
|
||||
dnl The check for libresolv is in case you are attempting to link
|
||||
dnl statically and happen to have a libresolv.a lying around (and no
|
||||
dnl libnsl.a).
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_LIBRARY_NET, [
|
||||
# Most operating systems have gethostbyname() in the default searched
|
||||
# libraries (i.e. libc):
|
||||
# Some OSes (eg. Solaris) place it in libnsl
|
||||
# Some strange OSes (SINIX) have it in libsocket:
|
||||
AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
|
||||
# Unfortunately libsocket sometimes depends on libnsl and
|
||||
# AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
|
||||
if test "$ac_cv_search_gethostbyname" = "no"
|
||||
then
|
||||
AC_CHECK_LIB(socket, gethostbyname,
|
||||
LIBS="-lsocket -lnsl $LIBS", , -lnsl)
|
||||
fi
|
||||
AC_SEARCH_LIBS(socket, socket, ,
|
||||
AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
|
||||
# DLPI needs putmsg under HPUX so test for -lstr while we're at it
|
||||
AC_SEARCH_LIBS(putmsg, str)
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Test for __attribute__
|
||||
dnl
|
||||
|
||||
AC_DEFUN(AC_C___ATTRIBUTE__, [
|
||||
AC_MSG_CHECKING(for __attribute__)
|
||||
AC_CACHE_VAL(ac_cv___attribute__, [
|
||||
AC_COMPILE_IFELSE(
|
||||
AC_LANG_SOURCE([[
|
||||
#include <stdlib.h>
|
||||
|
||||
static void foo(void) __attribute__ ((noreturn));
|
||||
|
||||
static void
|
||||
foo(void)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
foo();
|
||||
}
|
||||
]]),
|
||||
ac_cv___attribute__=yes,
|
||||
ac_cv___attribute__=no)])
|
||||
if test "$ac_cv___attribute__" = "yes"; then
|
||||
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
|
||||
V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
|
||||
else
|
||||
V_DEFS="$V_DEFS -D_U_=\"\""
|
||||
fi
|
||||
AC_MSG_RESULT($ac_cv___attribute__)
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
|
||||
dnl If so then pcap-linux.c can use this to report proper statistics.
|
||||
dnl
|
||||
dnl -Scott Barron
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_TPACKET_STATS,
|
||||
[AC_MSG_CHECKING(if if_packet.h has tpacket_stats defined)
|
||||
AC_CACHE_VAL(ac_cv_lbl_tpacket_stats,
|
||||
AC_TRY_COMPILE([
|
||||
# include <linux/if_packet.h>],
|
||||
[struct tpacket_stats stats],
|
||||
ac_cv_lbl_tpacket_stats=yes,
|
||||
ac_cv_lbl_tpacket_stats=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_tpacket_stats)
|
||||
if test $ac_cv_lbl_tpacket_stats = yes; then
|
||||
AC_DEFINE(HAVE_TPACKET_STATS,1,[if if_packet.h has tpacket_stats defined])
|
||||
fi])
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* 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 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.
|
||||
*
|
||||
* @(#) $Id: arcnet.h,v 1.1.1.1 2006/02/27 15:45:40 drochner Exp $ (LBL)
|
||||
*
|
||||
* from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp
|
||||
*/
|
||||
|
||||
/* RFC 1051 */
|
||||
#define ARCTYPE_IP_OLD 240 /* IP protocol */
|
||||
#define ARCTYPE_ARP_OLD 241 /* address resolution protocol */
|
||||
|
||||
/* RFC 1201 */
|
||||
#define ARCTYPE_IP 212 /* IP protocol */
|
||||
#define ARCTYPE_ARP 213 /* address resolution protocol */
|
||||
#define ARCTYPE_REVARP 214 /* reverse addr resolution protocol */
|
||||
|
||||
#define ARCTYPE_ATALK 221 /* Appletalk */
|
||||
#define ARCTYPE_BANIAN 247 /* Banyan Vines */
|
||||
#define ARCTYPE_IPX 250 /* Novell IPX */
|
||||
|
||||
#define ARCTYPE_INET6 0xc4 /* IPng */
|
||||
#define ARCTYPE_DIAGNOSE 0x80 /* as per ANSI/ATA 878.1 */
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/atmuni31.h,v 1.1.1.1 2006/02/27 15:45:40 drochner 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,565 +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.
|
||||
*
|
||||
* @(#)bpf.c 7.5 (Berkeley) 7/15/91
|
||||
*/
|
||||
|
||||
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/bpf/net/Attic/bpf_filter.c,v 1.1.1.1 2006/02/27 15:45:49 drochner Exp $ (LBL)";
|
||||
#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>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define SOLARIS (defined(sun) && (defined(__SVR4) || defined(__svr4__)))
|
||||
#if defined(__hpux) || SOLARIS
|
||||
# include <sys/sysmacros.h>
|
||||
# include <sys/stream.h>
|
||||
# define mbuf msgb
|
||||
# define m_next b_cont
|
||||
# define MLEN(m) ((m)->b_wptr - (m)->b_rptr)
|
||||
# define mtod(m,t) ((t)(m)->b_rptr)
|
||||
#else
|
||||
# define MLEN(m) ((m)->m_len)
|
||||
#endif
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <pcap-bpf.h>
|
||||
|
||||
#if !defined(KERNEL) && !defined(_KERNEL)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define int32 bpf_int32
|
||||
#define u_int32 bpf_u_int32
|
||||
|
||||
#ifndef LBL_ALIGN
|
||||
/*
|
||||
* XXX - IA-64? If not, this probably won't work on Win64 IA-64
|
||||
* systems, unless LBL_ALIGN is defined elsewhere for them.
|
||||
* XXX - SuperH? If not, this probably won't work on WinCE SuperH
|
||||
* systems, unless LBL_ALIGN is defined elsewhere for them.
|
||||
*/
|
||||
#if defined(sparc) || defined(__sparc__) || defined(mips) || \
|
||||
defined(ibm032) || defined(__alpha) || defined(__hpux) || \
|
||||
defined(__arm__)
|
||||
#define LBL_ALIGN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LBL_ALIGN
|
||||
#ifndef WIN32
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p))
|
||||
#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p))
|
||||
#else
|
||||
#define EXTRACT_SHORT(p)\
|
||||
((u_short)\
|
||||
((u_short)*((u_char *)p+0)<<8|\
|
||||
(u_short)*((u_char *)p+1)<<0))
|
||||
#define EXTRACT_LONG(p)\
|
||||
((u_int32)*((u_char *)p+0)<<24|\
|
||||
(u_int32)*((u_char *)p+1)<<16|\
|
||||
(u_int32)*((u_char *)p+2)<<8|\
|
||||
(u_int32)*((u_char *)p+3)<<0)
|
||||
#endif
|
||||
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
# if !defined(__hpux) && !SOLARIS
|
||||
#include <sys/mbuf.h>
|
||||
# endif
|
||||
#define MINDEX(len, _m, _k) \
|
||||
{ \
|
||||
len = MLEN(m); \
|
||||
while ((_k) >= len) { \
|
||||
(_k) -= len; \
|
||||
(_m) = (_m)->m_next; \
|
||||
if ((_m) == 0) \
|
||||
return 0; \
|
||||
len = MLEN(m); \
|
||||
} \
|
||||
}
|
||||
|
||||
static int
|
||||
m_xword(m, k, err)
|
||||
register struct mbuf *m;
|
||||
register int k, *err;
|
||||
{
|
||||
register int len;
|
||||
register u_char *cp, *np;
|
||||
register struct mbuf *m0;
|
||||
|
||||
MINDEX(len, m, k);
|
||||
cp = mtod(m, u_char *) + k;
|
||||
if (len - k >= 4) {
|
||||
*err = 0;
|
||||
return EXTRACT_LONG(cp);
|
||||
}
|
||||
m0 = m->m_next;
|
||||
if (m0 == 0 || MLEN(m0) + len - k < 4)
|
||||
goto bad;
|
||||
*err = 0;
|
||||
np = mtod(m0, u_char *);
|
||||
switch (len - k) {
|
||||
|
||||
case 1:
|
||||
return (cp[0] << 24) | (np[0] << 16) | (np[1] << 8) | np[2];
|
||||
|
||||
case 2:
|
||||
return (cp[0] << 24) | (cp[1] << 16) | (np[0] << 8) | np[1];
|
||||
|
||||
default:
|
||||
return (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | np[0];
|
||||
}
|
||||
bad:
|
||||
*err = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
m_xhalf(m, k, err)
|
||||
register struct mbuf *m;
|
||||
register int k, *err;
|
||||
{
|
||||
register int len;
|
||||
register u_char *cp;
|
||||
register struct mbuf *m0;
|
||||
|
||||
MINDEX(len, m, k);
|
||||
cp = mtod(m, u_char *) + k;
|
||||
if (len - k >= 2) {
|
||||
*err = 0;
|
||||
return EXTRACT_SHORT(cp);
|
||||
}
|
||||
m0 = m->m_next;
|
||||
if (m0 == 0)
|
||||
goto bad;
|
||||
*err = 0;
|
||||
return (cp[0] << 8) | mtod(m0, u_char *)[0];
|
||||
bad:
|
||||
*err = 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Execute the filter program starting at pc on the packet p
|
||||
* wirelen is the length of the original packet
|
||||
* buflen is the amount of data present
|
||||
* For the kernel, p is assumed to be a pointer to an mbuf if buflen is 0,
|
||||
* in all other cases, p is a pointer to a buffer and buflen is its size.
|
||||
*/
|
||||
u_int
|
||||
bpf_filter(pc, p, wirelen, buflen)
|
||||
register struct bpf_insn *pc;
|
||||
register u_char *p;
|
||||
u_int wirelen;
|
||||
register u_int buflen;
|
||||
{
|
||||
register u_int32 A, X;
|
||||
register int k;
|
||||
int32 mem[BPF_MEMWORDS];
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
struct mbuf *m, *n;
|
||||
int merr, len;
|
||||
|
||||
if (buflen == 0) {
|
||||
m = (struct mbuf *)p;
|
||||
p = mtod(m, u_char *);
|
||||
buflen = MLEN(m);
|
||||
} else
|
||||
m = NULL;
|
||||
#endif
|
||||
|
||||
if (pc == 0)
|
||||
/*
|
||||
* No filter means accept all.
|
||||
*/
|
||||
return (u_int)-1;
|
||||
A = 0;
|
||||
X = 0;
|
||||
--pc;
|
||||
while (1) {
|
||||
++pc;
|
||||
switch (pc->code) {
|
||||
|
||||
default:
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
return 0;
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
case BPF_RET|BPF_K:
|
||||
return (u_int)pc->k;
|
||||
|
||||
case BPF_RET|BPF_A:
|
||||
return (u_int)A;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_ABS:
|
||||
k = pc->k;
|
||||
if (k + sizeof(int32) > buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
A = m_xword(m, k, &merr);
|
||||
if (merr != 0)
|
||||
return 0;
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = EXTRACT_LONG(&p[k]);
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_ABS:
|
||||
k = pc->k;
|
||||
if (k + sizeof(short) > buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
A = m_xhalf(m, k, &merr);
|
||||
if (merr != 0)
|
||||
return 0;
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = EXTRACT_SHORT(&p[k]);
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_ABS:
|
||||
k = pc->k;
|
||||
if (k >= buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
n = m;
|
||||
MINDEX(len, n, k);
|
||||
A = mtod(n, u_char *)[k];
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = p[k];
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_LEN:
|
||||
A = wirelen;
|
||||
continue;
|
||||
|
||||
case BPF_LDX|BPF_W|BPF_LEN:
|
||||
X = wirelen;
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_IND:
|
||||
k = X + pc->k;
|
||||
if (k + sizeof(int32) > buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
A = m_xword(m, k, &merr);
|
||||
if (merr != 0)
|
||||
return 0;
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = EXTRACT_LONG(&p[k]);
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_IND:
|
||||
k = X + pc->k;
|
||||
if (k + sizeof(short) > buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
A = m_xhalf(m, k, &merr);
|
||||
if (merr != 0)
|
||||
return 0;
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = EXTRACT_SHORT(&p[k]);
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_IND:
|
||||
k = X + pc->k;
|
||||
if (k >= buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
n = m;
|
||||
MINDEX(len, n, k);
|
||||
A = mtod(n, u_char *)[k];
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = p[k];
|
||||
continue;
|
||||
|
||||
case BPF_LDX|BPF_MSH|BPF_B:
|
||||
k = pc->k;
|
||||
if (k >= buflen) {
|
||||
#if defined(KERNEL) || defined(_KERNEL)
|
||||
if (m == NULL)
|
||||
return 0;
|
||||
n = m;
|
||||
MINDEX(len, n, k);
|
||||
X = (mtod(n, char *)[k] & 0xf) << 2;
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
X = (p[pc->k] & 0xf) << 2;
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_IMM:
|
||||
A = pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_LDX|BPF_IMM:
|
||||
X = pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_MEM:
|
||||
A = mem[pc->k];
|
||||
continue;
|
||||
|
||||
case BPF_LDX|BPF_MEM:
|
||||
X = mem[pc->k];
|
||||
continue;
|
||||
|
||||
case BPF_ST:
|
||||
mem[pc->k] = A;
|
||||
continue;
|
||||
|
||||
case BPF_STX:
|
||||
mem[pc->k] = X;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JA:
|
||||
pc += pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_K:
|
||||
pc += (A > pc->k) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_K:
|
||||
pc += (A >= pc->k) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_K:
|
||||
pc += (A == pc->k) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_K:
|
||||
pc += (A & pc->k) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_X:
|
||||
pc += (A > X) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_X:
|
||||
pc += (A >= X) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_X:
|
||||
pc += (A == X) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_X:
|
||||
pc += (A & X) ? pc->jt : pc->jf;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_X:
|
||||
A += X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_X:
|
||||
A -= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_X:
|
||||
A *= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_X:
|
||||
if (X == 0)
|
||||
return 0;
|
||||
A /= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_X:
|
||||
A &= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_X:
|
||||
A |= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_X:
|
||||
A <<= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_X:
|
||||
A >>= X;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_K:
|
||||
A += pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_K:
|
||||
A -= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_K:
|
||||
A *= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_K:
|
||||
A /= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_K:
|
||||
A &= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_K:
|
||||
A |= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_K:
|
||||
A <<= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_K:
|
||||
A >>= pc->k;
|
||||
continue;
|
||||
|
||||
case BPF_ALU|BPF_NEG:
|
||||
A = -A;
|
||||
continue;
|
||||
|
||||
case BPF_MISC|BPF_TAX:
|
||||
X = A;
|
||||
continue;
|
||||
|
||||
case BPF_MISC|BPF_TXA:
|
||||
A = X;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return true if the 'fcode' is a valid filter program.
|
||||
* The constraints are that each jump be forward and to a valid
|
||||
* code. The code must terminate with either an accept or reject.
|
||||
* 'valid' is an array for use by the routine (it must be at least
|
||||
* 'len' bytes long).
|
||||
*
|
||||
* The kernel needs to be able to verify an application's filter code.
|
||||
* Otherwise, a bogus program could easily crash the system.
|
||||
*/
|
||||
int
|
||||
bpf_validate(f, len)
|
||||
struct bpf_insn *f;
|
||||
int len;
|
||||
{
|
||||
register int i;
|
||||
register struct bpf_insn *p;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
/*
|
||||
* Check that that jumps are forward, and within
|
||||
* the code block.
|
||||
*/
|
||||
p = &f[i];
|
||||
if (BPF_CLASS(p->code) == BPF_JMP) {
|
||||
register int from = i + 1;
|
||||
|
||||
if (BPF_OP(p->code) == BPF_JA) {
|
||||
if (from + p->k >= (unsigned)len)
|
||||
return 0;
|
||||
}
|
||||
else if (from + p->jt >= len || from + p->jf >= len)
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Check that memory operations use valid addresses.
|
||||
*/
|
||||
if ((BPF_CLASS(p->code) == BPF_ST ||
|
||||
(BPF_CLASS(p->code) == BPF_LD &&
|
||||
(p->code & 0xe0) == BPF_MEM)) &&
|
||||
(p->k >= BPF_MEMWORDS || p->k < 0))
|
||||
return 0;
|
||||
/*
|
||||
* Check for constant division by 0.
|
||||
*/
|
||||
if (p->code == (BPF_ALU|BPF_DIV|BPF_K) && p->k == 0)
|
||||
return 0;
|
||||
}
|
||||
return BPF_CLASS(f[len - 1].code) == BPF_RET;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/bpf_dump.c,v 1.1.1.1 2006/02/27 15:45:40 drochner Exp $ (LBL)";
|
||||
#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,288 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/bpf_image.c,v 1.2 2006/02/27 15:55:30 drochner Exp $ (LBL)";
|
||||
#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;
|
||||
const char *fmt, *op;
|
||||
static char image[256];
|
||||
char operand[64];
|
||||
|
||||
v = p->k;
|
||||
switch (p->code) {
|
||||
|
||||
default:
|
||||
op = "unimp";
|
||||
fmt = "0x%x";
|
||||
v = p->code;
|
||||
break;
|
||||
|
||||
case BPF_RET|BPF_K:
|
||||
op = "ret";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_RET|BPF_A:
|
||||
op = "ret";
|
||||
fmt = "";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_ABS:
|
||||
op = "ld";
|
||||
fmt = "[%d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_ABS:
|
||||
op = "ldh";
|
||||
fmt = "[%d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_ABS:
|
||||
op = "ldb";
|
||||
fmt = "[%d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_LEN:
|
||||
op = "ld";
|
||||
fmt = "#pktlen";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_W|BPF_IND:
|
||||
op = "ld";
|
||||
fmt = "[x + %d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_H|BPF_IND:
|
||||
op = "ldh";
|
||||
fmt = "[x + %d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_IND:
|
||||
op = "ldb";
|
||||
fmt = "[x + %d]";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_IMM:
|
||||
op = "ld";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_LDX|BPF_IMM:
|
||||
op = "ldx";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_LDX|BPF_MSH|BPF_B:
|
||||
op = "ldxb";
|
||||
fmt = "4*([%d]&0xf)";
|
||||
break;
|
||||
|
||||
case BPF_LD|BPF_MEM:
|
||||
op = "ld";
|
||||
fmt = "M[%d]";
|
||||
break;
|
||||
|
||||
case BPF_LDX|BPF_MEM:
|
||||
op = "ldx";
|
||||
fmt = "M[%d]";
|
||||
break;
|
||||
|
||||
case BPF_ST:
|
||||
op = "st";
|
||||
fmt = "M[%d]";
|
||||
break;
|
||||
|
||||
case BPF_STX:
|
||||
op = "stx";
|
||||
fmt = "M[%d]";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JA:
|
||||
op = "ja";
|
||||
fmt = "%d";
|
||||
v = n + 1 + p->k;
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_K:
|
||||
op = "jgt";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_K:
|
||||
op = "jge";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_K:
|
||||
op = "jeq";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_K:
|
||||
op = "jset";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_X:
|
||||
op = "jgt";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGE|BPF_X:
|
||||
op = "jge";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JEQ|BPF_X:
|
||||
op = "jeq";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JSET|BPF_X:
|
||||
op = "jset";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_X:
|
||||
op = "add";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_X:
|
||||
op = "sub";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_X:
|
||||
op = "mul";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_X:
|
||||
op = "div";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_X:
|
||||
op = "and";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_X:
|
||||
op = "or";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_X:
|
||||
op = "lsh";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_X:
|
||||
op = "rsh";
|
||||
fmt = "x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_ADD|BPF_K:
|
||||
op = "add";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_SUB|BPF_K:
|
||||
op = "sub";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_MUL|BPF_K:
|
||||
op = "mul";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_DIV|BPF_K:
|
||||
op = "div";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_AND|BPF_K:
|
||||
op = "and";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_K:
|
||||
op = "or";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_K:
|
||||
op = "lsh";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_RSH|BPF_K:
|
||||
op = "rsh";
|
||||
fmt = "#%d";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_NEG:
|
||||
op = "neg";
|
||||
fmt = "";
|
||||
break;
|
||||
|
||||
case BPF_MISC|BPF_TAX:
|
||||
op = "tax";
|
||||
fmt = "";
|
||||
break;
|
||||
|
||||
case BPF_MISC|BPF_TXA:
|
||||
op = "txa";
|
||||
fmt = "";
|
||||
break;
|
||||
}
|
||||
(void)snprintf(operand, sizeof operand, fmt, v);
|
||||
(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;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,186 +0,0 @@
|
|||
/* config.h.in. Generated from configure.in by autoheader. */
|
||||
/* Long story short: aclocal.m4 depends on autoconf 2.13
|
||||
* implementation details wrt "const"; newer versions
|
||||
* have different implementation details so for now we
|
||||
* put "const" here. This may cause duplicate definitions
|
||||
* in config.h but that should be OK since they're the same.
|
||||
*/
|
||||
#undef const
|
||||
|
||||
/* Enable optimizer debugging */
|
||||
#undef BDEBUG
|
||||
|
||||
/* define if you have the DAG API */
|
||||
#undef HAVE_DAG_API
|
||||
|
||||
/* define if you have streams capable DAG API */
|
||||
#undef HAVE_DAG_STREAMS_API
|
||||
|
||||
/* Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_ETHER_HOSTTON
|
||||
|
||||
/* define if you have a /dev/dlpi */
|
||||
#undef HAVE_DEV_DLPI
|
||||
|
||||
/* Define to 1 if you have the `ether_hostton' function. */
|
||||
#undef HAVE_ETHER_HOSTTON
|
||||
|
||||
/* on HP-UX 10.20 or later */
|
||||
#undef HAVE_HPUX10_20_OR_LATER
|
||||
|
||||
/* on HP-UX 9.x */
|
||||
#undef HAVE_HPUX9
|
||||
|
||||
/* if ppa_info_t_dl_module_id exists */
|
||||
#undef HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/ether.h> header file. */
|
||||
#undef HAVE_NETINET_ETHER_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/if_ether.h> header file. */
|
||||
#undef HAVE_NETINET_IF_ETHER_H
|
||||
|
||||
/* if there's an os_proto.h */
|
||||
#undef HAVE_OS_PROTO_H
|
||||
|
||||
/* define if you have a /proc/net/dev */
|
||||
#undef HAVE_PROC_NET_DEV
|
||||
|
||||
/* define if you have a Septel API */
|
||||
#undef HAVE_SEPTEL_API
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* if struct sockaddr has sa_len */
|
||||
#undef HAVE_SOCKADDR_SA_LEN
|
||||
|
||||
/* if struct sockaddr_storage exists */
|
||||
#undef HAVE_SOCKADDR_STORAGE
|
||||
|
||||
/* On solaris */
|
||||
#undef HAVE_SOLARIS
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if the system has the type `struct ether_addr'. */
|
||||
#undef HAVE_STRUCT_ETHER_ADDR
|
||||
|
||||
/* Define to 1 if you have the <sys/bufmod.h> header file. */
|
||||
#undef HAVE_SYS_BUFMOD_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dlpi_ext.h> header file. */
|
||||
#undef HAVE_SYS_DLPI_EXT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioccom.h> header file. */
|
||||
#undef HAVE_SYS_IOCCOM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/sockio.h> header file. */
|
||||
#undef HAVE_SYS_SOCKIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* if if_packet.h has tpacket_stats defined */
|
||||
#undef HAVE_TPACKET_STATS
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* define if version.h is generated in the build procedure */
|
||||
#undef HAVE_VERSION_H
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* define if your compiler has __attribute__ */
|
||||
#undef HAVE___ATTRIBUTE__
|
||||
|
||||
/* IPv6 */
|
||||
#undef INET6
|
||||
|
||||
/* if unaligned access fails */
|
||||
#undef LBL_ALIGN
|
||||
|
||||
/* Define to 1 if netinet/ether.h declares `ether_hostton' */
|
||||
#undef NETINET_ETHER_H_DECLARES_ETHER_HOSTTON
|
||||
|
||||
/* Define to 1 if netinet/if_ether.h declares `ether_hostton' */
|
||||
#undef NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON
|
||||
|
||||
/* do not use protochain */
|
||||
#undef NO_PROTOCHAIN
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* /dev/dlpi directory */
|
||||
#undef PCAP_DEV_PREFIX
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Enable parser debugging */
|
||||
#undef YYDEBUG
|
||||
|
||||
/* needed on HP-UX */
|
||||
#undef _HPUX_SOURCE
|
||||
|
||||
/* define on AIX to get certain functions */
|
||||
#undef _SUN
|
||||
|
||||
/* Define as token for inline if inlining supported */
|
||||
#undef inline
|
||||
|
||||
/* on sinix */
|
||||
#undef sinix
|
||||
|
||||
/* if we have u_int16_t */
|
||||
#undef u_int16_t
|
||||
|
||||
/* if we have u_int32_t */
|
||||
#undef u_int32_t
|
||||
|
||||
/* if we have u_int8_t */
|
||||
#undef u_int8_t
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,793 +0,0 @@
|
|||
dnl @(#) $Header: /cvsroot/src/dist/libpcap/Attic/configure.in,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)
|
||||
dnl
|
||||
dnl Copyright (c) 1994, 1995, 1996, 1997
|
||||
dnl The Regents of the University of California. All rights reserved.
|
||||
dnl
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
dnl
|
||||
|
||||
AC_REVISION($Revision: 1.1.1.1 $)
|
||||
AC_PREREQ(2.50)
|
||||
AC_INIT(pcap.c)
|
||||
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
AC_LBL_C_INIT(V_CCOPT, V_INCLS, V_LIBS)
|
||||
AC_LBL_C_INLINE
|
||||
AC_C___ATTRIBUTE__
|
||||
|
||||
AC_LBL_CHECK_TYPE(u_int8_t, u_char)
|
||||
AC_LBL_CHECK_TYPE(u_int16_t, u_short)
|
||||
AC_LBL_CHECK_TYPE(u_int32_t, u_int)
|
||||
|
||||
dnl
|
||||
dnl libpcap doesn't itself use <sys/ioccom.h>; however, the test program
|
||||
dnl in "AC_LBL_FIXINCLUDES" in "aclocal.m4" uses it, so we have to
|
||||
dnl test for it and set "HAVE_SYS_IOCCOM_H" if we have it, otherwise
|
||||
dnl "AC_LBL_FIXINCLUDES" won't work on some platforms such as Solaris.
|
||||
dnl
|
||||
AC_CHECK_HEADERS(sys/ioccom.h sys/sockio.h limits.h)
|
||||
AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
|
||||
#include <sys/socket.h>])
|
||||
if test "$ac_cv_header_netinet_if_ether_h" != yes; then
|
||||
#
|
||||
# The simple test didn't work.
|
||||
# Do we need to include <net/if.h> first?
|
||||
# Unset ac_cv_header_netinet_if_ether_h so we don't
|
||||
# treat the previous failure as a cached value and
|
||||
# suppress the next test.
|
||||
#
|
||||
AC_MSG_NOTICE([Rechecking with some additional includes])
|
||||
unset ac_cv_header_netinet_if_ether_h
|
||||
AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#include <net/if.h>])
|
||||
fi
|
||||
|
||||
AC_LBL_FIXINCLUDES
|
||||
|
||||
AC_CHECK_FUNCS(strerror strlcpy)
|
||||
|
||||
needsnprintf=no
|
||||
AC_CHECK_FUNCS(vsnprintf snprintf,,
|
||||
[needsnprintf=yes])
|
||||
if test $needsnprintf = yes; then
|
||||
AC_LIBOBJ(snprintf)
|
||||
fi
|
||||
|
||||
#
|
||||
# Do this before checking for ether_hostton(), as it's a
|
||||
# "gethostbyname() -ish function".
|
||||
#
|
||||
AC_LBL_LIBRARY_NET
|
||||
|
||||
#
|
||||
# You are in a twisty little maze of UN*Xes, all different.
|
||||
# Some might not have ether_hostton().
|
||||
# Some might have it, but not declare it in any header file.
|
||||
# Some might have it, but declare it in <netinet/if_ether.h>.
|
||||
# Some might have it, but declare it in <netinet/ether.h>
|
||||
# (And some might have it but document it as something declared in
|
||||
# <netinet/ethernet.h>, although <netinet/if_ether.h> appears to work.)
|
||||
#
|
||||
# Before you is a C compiler.
|
||||
#
|
||||
AC_CHECK_FUNCS(ether_hostton)
|
||||
if test "$ac_cv_func_ether_hostton" = yes; then
|
||||
#
|
||||
# OK, we have ether_hostton(). Do we have <netinet/if_ether.h>?
|
||||
#
|
||||
if test "$ac_cv_header_netinet_if_ether_h" = yes; then
|
||||
#
|
||||
# Yes. Does it declare ether_hostton()?
|
||||
#
|
||||
AC_CHECK_DECL(ether_hostton,
|
||||
[
|
||||
AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON,,
|
||||
[Define to 1 if netinet/if_ether.h declares `ether_hostton'])
|
||||
],,
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#include <net/if.h>
|
||||
#include <netinet/if_ether.h>
|
||||
])
|
||||
fi
|
||||
#
|
||||
# Did that succeed?
|
||||
#
|
||||
if test "$ac_cv_have_decl_ether_hostton" != yes; then
|
||||
#
|
||||
# No, how about <netinet/ether.h>, as on Linux?
|
||||
#
|
||||
AC_CHECK_HEADERS(netinet/ether.h)
|
||||
if test "$ac_cv_header_netinet_ether_h" = yes; then
|
||||
#
|
||||
# We have it - does it declare ether_hostton()?
|
||||
# Unset ac_cv_have_decl_ether_hostton so we don't
|
||||
# treat the previous failure as a cached value and
|
||||
# suppress the next test.
|
||||
#
|
||||
unset ac_cv_have_decl_ether_hostton
|
||||
AC_CHECK_DECL(ether_hostton,
|
||||
[
|
||||
AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON,,
|
||||
[Define to 1 if netinet/ether.h declares `ether_hostton'])
|
||||
],,
|
||||
[
|
||||
#include <netinet/ether.h>
|
||||
])
|
||||
fi
|
||||
fi
|
||||
#
|
||||
# Is ether_hostton() declared?
|
||||
#
|
||||
if test "$ac_cv_have_decl_ether_hostton" != yes; then
|
||||
#
|
||||
# No, we'll have to declare it ourselves.
|
||||
# Do we have "struct ether_addr"?
|
||||
#
|
||||
AC_CHECK_TYPES(struct ether_addr,,,
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#include <net/if.h>
|
||||
#include <netinet/if_ether.h>
|
||||
])
|
||||
AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 0,
|
||||
[Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
|
||||
don't.])
|
||||
else
|
||||
AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 1,
|
||||
[Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
|
||||
don't.])
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl to pacify those who hate protochain insn
|
||||
AC_MSG_CHECKING(if --disable-protochain option is specified)
|
||||
AC_ARG_ENABLE(protochain, [ --disable-protochain disable \"protochain\" insn])
|
||||
case "x$enable_protochain" in
|
||||
xyes) enable_protochain=enabled ;;
|
||||
xno) enable_protochain=disabled ;;
|
||||
x) enable_protochain=enabled ;;
|
||||
esac
|
||||
|
||||
if test "$enable_protochain" = "disabled"; then
|
||||
AC_DEFINE(NO_PROTOCHAIN,1,[do not use protochain])
|
||||
fi
|
||||
AC_MSG_RESULT(${enable_protochain})
|
||||
|
||||
dnl
|
||||
dnl Not all versions of test support -c (character special) but it's a
|
||||
dnl better way of testing since the device might be protected. So we
|
||||
dnl check in our normal order using -r and then check the for the /dev
|
||||
dnl guys again using -c.
|
||||
dnl
|
||||
dnl XXX This could be done for cross-compiling, but for now it's not.
|
||||
dnl
|
||||
if test -z "$with_pcap" && test "$cross_compiling" = yes; then
|
||||
AC_MSG_ERROR(pcap type not determined when cross-compiling; use --with-pcap=...)
|
||||
fi
|
||||
AC_ARG_WITH(pcap, [ --with-pcap=TYPE use packet capture TYPE])
|
||||
AC_MSG_CHECKING(packet capture type)
|
||||
if test ! -z "$with_pcap" ; then
|
||||
V_PCAP="$withval"
|
||||
elif test -r /dev/bpf0 ; then
|
||||
V_PCAP=bpf
|
||||
elif test -r /usr/include/net/pfilt.h ; then
|
||||
V_PCAP=pf
|
||||
elif test -r /dev/enet ; then
|
||||
V_PCAP=enet
|
||||
elif test -r /dev/nit ; then
|
||||
V_PCAP=snit
|
||||
elif test -r /usr/include/sys/net/nit.h ; then
|
||||
V_PCAP=nit
|
||||
elif test -r /usr/include/linux/socket.h ; then
|
||||
V_PCAP=linux
|
||||
elif test -r /usr/include/net/raw.h ; then
|
||||
V_PCAP=snoop
|
||||
elif test -r /usr/include/odmi.h ; then
|
||||
#
|
||||
# On AIX, the BPF devices might not yet be present - they're
|
||||
# created the first time libpcap runs after booting.
|
||||
# We check for odmi.h instead.
|
||||
#
|
||||
V_PCAP=bpf
|
||||
elif test -r /usr/include/sys/dlpi.h ; then
|
||||
V_PCAP=dlpi
|
||||
elif test -c /dev/bpf0 ; then # check again in case not readable
|
||||
V_PCAP=bpf
|
||||
elif test -c /dev/enet ; then # check again in case not readable
|
||||
V_PCAP=enet
|
||||
elif test -c /dev/nit ; then # check again in case not readable
|
||||
V_PCAP=snit
|
||||
else
|
||||
V_PCAP=null
|
||||
fi
|
||||
AC_MSG_RESULT($V_PCAP)
|
||||
|
||||
dnl
|
||||
dnl Now figure out how we get a list of interfaces and addresses,
|
||||
dnl if we support capturing. Don't bother if we don't support
|
||||
dnl capturing.
|
||||
dnl
|
||||
if test "$V_PCAP" = null
|
||||
then
|
||||
#
|
||||
# We can't capture, so we can't open any capture
|
||||
# devices, so we won't return any interfaces.
|
||||
#
|
||||
V_FINDALLDEVS=null
|
||||
else
|
||||
AC_CHECK_FUNC(getifaddrs,[
|
||||
#
|
||||
# We have "getifaddrs()"; make sure we have <ifaddrs.h>
|
||||
# as well, just in case some platform is really weird.
|
||||
#
|
||||
AC_CHECK_HEADER(ifaddrs.h,[
|
||||
#
|
||||
# We have the header, so we use "getifaddrs()" to
|
||||
# get the list of interfaces.
|
||||
#
|
||||
V_FINDALLDEVS=getad
|
||||
],[
|
||||
#
|
||||
# We don't have the header - give up.
|
||||
# XXX - we could also fall back on some other
|
||||
# mechanism, but, for now, this'll catch this
|
||||
# problem so that we can at least try to figure
|
||||
# out something to do on systems with "getifaddrs()"
|
||||
# but without "ifaddrs.h", if there is something
|
||||
# we can do on those systems.
|
||||
#
|
||||
AC_MSG_ERROR([Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.])
|
||||
])
|
||||
],[
|
||||
#
|
||||
# Well, we don't have "getifaddrs()", so we have to use
|
||||
# some other mechanism; determine what that mechanism is.
|
||||
#
|
||||
# The first thing we use is the type of capture mechanism,
|
||||
# which is somewhat of a proxy for the OS we're using.
|
||||
#
|
||||
case "$V_PCAP" in
|
||||
|
||||
dlpi)
|
||||
#
|
||||
# This might be Solaris 8 or later, with
|
||||
# SIOCGLIFCONF, or it might be some other OS
|
||||
# or some older version of Solaris, with
|
||||
# just SIOCGIFCONF.
|
||||
#
|
||||
AC_MSG_CHECKING(whether we have SIOCGLIFCONF)
|
||||
AC_CACHE_VAL(ac_cv_lbl_have_siocglifconf,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>],
|
||||
[ioctl(0, SIOCGLIFCONF, (char *)0);],
|
||||
ac_cv_lbl_have_siocglifconf=yes,
|
||||
ac_cv_lbl_have_siocglifconf=no))
|
||||
AC_MSG_RESULT($ac_cv_lbl_have_siocglifconf)
|
||||
if test $ac_cv_lbl_have_siocglifconf = yes ; then
|
||||
V_FINDALLDEVS=glifc
|
||||
else
|
||||
V_FINDALLDEVS=gifc
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
#
|
||||
# Assume we just have SIOCGIFCONF.
|
||||
# (XXX - on at least later Linux kernels, there's
|
||||
# another mechanism, and we should be using that
|
||||
# instead.)
|
||||
#
|
||||
V_FINDALLDEVS=gifc
|
||||
;;
|
||||
esac])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(if --enable-ipv6 option is specified)
|
||||
AC_ARG_ENABLE(ipv6, [ --enable-ipv6 build IPv6-capable version])
|
||||
if test "$enable_ipv6" = "yes"; then
|
||||
AC_DEFINE(INET6,1,[IPv6])
|
||||
fi
|
||||
AC_MSG_RESULT(${enable_ipv6-no})
|
||||
|
||||
AC_MSG_CHECKING(whether to build optimizer debugging code)
|
||||
AC_ARG_ENABLE(optimizer-dbg, [ --enable-optimizer-dbg build optimizer debugging code])
|
||||
if test "$enable_optimizer_dbg" = "yes"; then
|
||||
AC_DEFINE(BDEBUG,1,[Enable optimizer debugging])
|
||||
fi
|
||||
AC_MSG_RESULT(${enable_optimizer_dbg-no})
|
||||
|
||||
AC_MSG_CHECKING(whether to build parser debugging code)
|
||||
AC_ARG_ENABLE(yydebug, [ --enable-yydebug build parser debugging code])
|
||||
if test "$enable_yydebug" = "yes"; then
|
||||
AC_DEFINE(YYDEBUG,1,[Enable parser debugging])
|
||||
fi
|
||||
AC_MSG_RESULT(${enable_yydebug-no})
|
||||
|
||||
case "$V_PCAP" in
|
||||
|
||||
dlpi)
|
||||
AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi_ext.h)
|
||||
AC_MSG_CHECKING(for /dev/dlpi device)
|
||||
if test -c /dev/dlpi ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_DEV_DLPI, 1, [define if you have a /dev/dlpi])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
dir="/dev/dlpi"
|
||||
AC_MSG_CHECKING(for $dir directory)
|
||||
if test -d $dir ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE_UNQUOTED(PCAP_DEV_PREFIX, "$dir", [/dev/dlpi directory])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
linux)
|
||||
AC_MSG_CHECKING(Linux kernel version)
|
||||
if test "$cross_compiling" = yes; then
|
||||
AC_CACHE_VAL(ac_cv_linux_vers,
|
||||
ac_cv_linux_vers=unknown)
|
||||
else
|
||||
AC_CACHE_VAL(ac_cv_linux_vers,
|
||||
ac_cv_linux_vers=`uname -r 2>&1 | \
|
||||
sed -n -e '$s/.* //' -e '$s/\..*//p'`)
|
||||
fi
|
||||
AC_MSG_RESULT($ac_cv_linux_vers)
|
||||
if test $ac_cv_linux_vers = unknown ; then
|
||||
AC_MSG_ERROR(cannot determine linux version when cross-compiling)
|
||||
fi
|
||||
if test $ac_cv_linux_vers -lt 2 ; then
|
||||
AC_MSG_ERROR(version 2 or higher required; see the INSTALL doc for more info)
|
||||
fi
|
||||
AC_LBL_TPACKET_STATS
|
||||
;;
|
||||
|
||||
dag)
|
||||
V_DEFS="$V_DEFS -DDAG_ONLY"
|
||||
;;
|
||||
|
||||
septel)
|
||||
V_DEFS="$V_DEFS -DSEPTEL_ONLY"
|
||||
;;
|
||||
|
||||
null)
|
||||
AC_MSG_WARN(cannot determine packet capture interface)
|
||||
AC_MSG_WARN((see the INSTALL doc for more info))
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
AC_MSG_CHECKING(whether we have /proc/net/dev)
|
||||
if test -r /proc/net/dev ; then
|
||||
ac_cv_lbl_proc_net_dev=yes
|
||||
else
|
||||
ac_cv_lbl_proc_net_dev=no
|
||||
fi
|
||||
if test $ac_cv_lbl_proc_net_dev = yes; then
|
||||
AC_DEFINE(HAVE_PROC_NET_DEV, 1, [define if you have a /proc/net/dev])
|
||||
fi
|
||||
AC_MSG_RESULT($ac_cv_lbl_proc_net_dev)
|
||||
|
||||
# Check for Endace DAG card support.
|
||||
AC_ARG_WITH([dag], [ --with-dag[[=DIR]] include Endace DAG support ("yes", "no" or DIR; default="yes" on BSD and Linux if present)],
|
||||
[
|
||||
if test "$withval" = no
|
||||
then
|
||||
# User doesn't want DAG support.
|
||||
want_dag=no
|
||||
elif test "$withval" = yes
|
||||
then
|
||||
# User wants DAG support but hasn't specified a directory.
|
||||
want_dag=yes
|
||||
else
|
||||
# User wants DAG support and has specified a directory, so use the provided value.
|
||||
want_dag=yes
|
||||
dag_root=$withval
|
||||
fi
|
||||
],[
|
||||
#
|
||||
# Use DAG API if present, otherwise don't
|
||||
#
|
||||
want_dag=ifpresent
|
||||
])
|
||||
|
||||
AC_ARG_WITH([dag-includes], [ --with-dag-includes=DIR Endace DAG include directory],
|
||||
[
|
||||
# User wants DAG support and has specified a header directory, so use the provided value.
|
||||
want_dag=yes
|
||||
dag_include_dir=$withval
|
||||
],[])
|
||||
|
||||
AC_ARG_WITH([dag-libraries], [ --with-dag-libraries=DIR Endace DAG library directory],
|
||||
[
|
||||
# User wants DAG support and has specified a library directory, so use the provided value.
|
||||
want_dag=yes
|
||||
dag_lib_dir=$withval
|
||||
],[])
|
||||
|
||||
case "$V_PCAP" in
|
||||
linux|bpf|dag)
|
||||
#
|
||||
# We support the DAG API if we're on Linux or BSD, or if we're
|
||||
# building a DAG-only libpcap.
|
||||
#
|
||||
;;
|
||||
*)
|
||||
#
|
||||
# If the user explicitly requested DAG, tell them it's not
|
||||
# supported.
|
||||
#
|
||||
# If they expressed no preference, don't include it.
|
||||
#
|
||||
if test $want_dag = yes; then
|
||||
AC_MSG_ERROR([DAG support is only available with 'linux' 'bpf' and 'dag' packet capture types])
|
||||
elif test $want_dag = yes; then
|
||||
want_dag=no
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
ac_cv_lbl_dag_api=no
|
||||
if test "$want_dag" != no; then
|
||||
|
||||
AC_MSG_CHECKING([whether we have DAG API headers])
|
||||
|
||||
# If necessary, set default paths for DAG API headers and libraries.
|
||||
if test -z "$dag_root"; then
|
||||
dag_root=/usr/local
|
||||
fi
|
||||
|
||||
if test -z "$dag_include_dir"; then
|
||||
dag_include_dir="$dag_root/include"
|
||||
fi
|
||||
|
||||
if test -z "$dag_lib_dir"; then
|
||||
dag_lib_dir="$dag_root/lib"
|
||||
fi
|
||||
|
||||
if test -z "$dag_tools_dir"; then
|
||||
dag_tools_dir="$dag_root/tools"
|
||||
fi
|
||||
|
||||
if test -r $dag_include_dir/dagapi.h; then
|
||||
ac_cv_lbl_dag_api=yes
|
||||
fi
|
||||
AC_MSG_RESULT([$ac_cv_lbl_dag_api ($dag_include_dir)])
|
||||
fi
|
||||
|
||||
if test $ac_cv_lbl_dag_api = yes; then
|
||||
|
||||
AC_MSG_CHECKING([dagapi.o])
|
||||
dagapi_obj=no
|
||||
if test -r $dag_tools_dir/dagapi.o; then
|
||||
# 2.4.x.
|
||||
dagapi_obj=$dag_tools_dir/dagapi.o
|
||||
elif test -r $dag_lib_dir/dagapi.o; then
|
||||
# 2.5.x.
|
||||
dagapi_obj=$dag_lib_dir/dagapi.o
|
||||
elif test -r $dag_lib_dir/libdag.a; then
|
||||
# 2.5.x.
|
||||
ar x $dag_lib_dir/libdag.a dagapi.o
|
||||
if test -r ./dagapi.o; then
|
||||
dagapi_obj=./dagapi.o
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $dagapi_obj = no; then
|
||||
AC_MSG_RESULT([no (checked $dag_lib_dir $dag_tools_dir $dag_lib_dir/libdag.a)])
|
||||
ac_cv_lbl_dag_api=no
|
||||
else
|
||||
AC_MSG_RESULT([yes ($dagapi_obj)])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $ac_cv_lbl_dag_api = yes; then
|
||||
|
||||
AC_MSG_CHECKING([dagopts.o])
|
||||
dagopts_obj=no
|
||||
if test -r $dag_tools_dir/dagopts.o; then
|
||||
# 2.4.x.
|
||||
dagopts_obj=$dag_tools_dir/dagopts.o
|
||||
elif test -r $dag_lib_dir/dagopts.o; then
|
||||
# 2.5.x.
|
||||
dagopts_obj=$dag_lib_dir/dagopts.o
|
||||
elif test -r $dag_lib_dir/libdag.a; then
|
||||
# 2.5.x.
|
||||
ar x $dag_lib_dir/libdag.a dagopts.o
|
||||
if test -r ./dagopts.o; then
|
||||
dagopts_obj=./dagopts.o
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $dagopts_obj = no; then
|
||||
AC_MSG_RESULT([no (checked $dag_lib_dir $dag_tools_dir $dag_lib_dir/libdag.a)])
|
||||
ac_cv_lbl_dag_api=no
|
||||
else
|
||||
AC_MSG_RESULT([yes ($dagopts_obj)])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $ac_cv_lbl_dag_api = yes; then
|
||||
# Under 2.5.x only we need to add dagreg.o.
|
||||
if test -r $dag_include_dir/dagreg.h; then
|
||||
AC_MSG_CHECKING([dagreg.o])
|
||||
dagreg_obj=no
|
||||
if test -r $dag_lib_dir/dagreg.o; then
|
||||
# Object file is ready and waiting.
|
||||
dagreg_obj=$dag_lib_dir/dagreg.o
|
||||
elif test -r $dag_lib_dir/libdag.a; then
|
||||
# Extract from libdag.a.
|
||||
ar x $dag_lib_dir/libdag.a dagreg.o
|
||||
if test -r ./dagreg.o; then
|
||||
dagreg_obj=./dagreg.o
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $dagreg_obj = no; then
|
||||
AC_MSG_RESULT([no (checked $dag_lib_dir $dag_lib_dir/libdag.a)])
|
||||
ac_cv_lbl_dag_api=no
|
||||
else
|
||||
AC_MSG_RESULT([yes ($dagreg_obj)])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $ac_cv_lbl_dag_api = yes; then
|
||||
V_INCLS="$V_INCLS -I$dag_include_dir"
|
||||
V_LIBS="$V_LIBS $dagapi_obj $dagopts_obj $dagreg_obj"
|
||||
if test $V_PCAP != dag ; then
|
||||
SSRC="pcap-dag.c"
|
||||
fi
|
||||
|
||||
# See if we can find a general version string.
|
||||
# Don't need to save and restore LIBS to prevent -ldag being
|
||||
# included if there's a found-action (arg 3).
|
||||
saved_ldflags=$LDFLAGS
|
||||
LDFLAGS="-L$dag_lib_dir"
|
||||
AC_CHECK_LIB([dag], [dag_attach_stream], [dag_version="2.5.x"], [dag_version="2.4.x"])
|
||||
LDFLAGS=$saved_ldflags
|
||||
|
||||
if test "$dag_version" = 2.5.x; then
|
||||
AC_DEFINE(HAVE_DAG_STREAMS_API, 1, [define if you have streams capable DAG API])
|
||||
fi
|
||||
|
||||
# See if we can find a specific version string.
|
||||
AC_MSG_CHECKING([the DAG API version])
|
||||
if test -r "$dag_root/VERSION"; then
|
||||
dag_version="`cat $dag_root/VERSION`"
|
||||
fi
|
||||
AC_MSG_RESULT([$dag_version])
|
||||
AC_DEFINE(HAVE_DAG_API, 1, [define if you have the DAG API])
|
||||
fi
|
||||
|
||||
if test $ac_cv_lbl_dag_api = no; then
|
||||
if test "$want_dag" = yes; then
|
||||
# User wanted DAG support but we couldn't find it.
|
||||
AC_MSG_ERROR([DAG API requested, but not found at $dag_root: use --without-dag])
|
||||
fi
|
||||
|
||||
if test "$V_PCAP" = dag; then
|
||||
# User requested "dag" capture type but the DAG API wasn't
|
||||
# found.
|
||||
AC_MSG_ERROR([Specifying the capture type as "dag" requires the DAG API to be present; use the --with-dag options to specify the location. (Try "./configure --help" for more information.)])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_WITH(septel, [ --with-septel[[=DIR]] include Septel support (located in directory DIR, if supplied). [default=yes, on Linux, if present]],
|
||||
[
|
||||
if test "$withval" = no
|
||||
then
|
||||
want_septel=no
|
||||
elif test "$withval" = yes
|
||||
then
|
||||
want_septel=yes
|
||||
septel_root=
|
||||
else
|
||||
want_septel=yes
|
||||
septel_root=$withval
|
||||
fi
|
||||
],[
|
||||
#
|
||||
# Use Septel API if present, otherwise don't
|
||||
#
|
||||
want_septel=ifpresent
|
||||
septel_root=./../septel
|
||||
])
|
||||
ac_cv_lbl_septel_api=no
|
||||
case "$V_PCAP" in
|
||||
linux|septel)
|
||||
#
|
||||
# We support the Septel API if we're on Linux, or if we're building
|
||||
# a Septel-only libpcap.
|
||||
#
|
||||
;;
|
||||
*)
|
||||
#
|
||||
# If the user explicitly requested Septel, tell them it's not
|
||||
# supported.
|
||||
#
|
||||
# If they expressed no preference, don't include it.
|
||||
#
|
||||
if test $want_septel = yes; then
|
||||
AC_MSG_ERROR(Septel support only available with 'linux' and 'septel' packet capture types)
|
||||
elif test $want_septel = yes; then
|
||||
want_septel=no
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$with_septel" != no; then
|
||||
AC_MSG_CHECKING(whether we have Septel API)
|
||||
|
||||
if test -z "$septel_root"; then
|
||||
septel_root=$srcdir/../septel
|
||||
|
||||
fi
|
||||
|
||||
septel_tools_dir="$septel_root"
|
||||
septel_include_dir="$septel_root/INC"
|
||||
DEF="-DHAVE_SEPTEL_API"
|
||||
|
||||
ac_cv_lbl_septel_api=no
|
||||
if test -r "$septel_include_dir/msg.h"; then
|
||||
V_INCLS="$V_INCLS -I$septel_include_dir"
|
||||
V_DEFS="$V_DEFS $DEF"
|
||||
V_LIBS="$V_LIBS $septel_tools_dir/asciibin.o $septel_tools_dir/bit2byte.o $septel_tools_dir/confirm.o $septel_tools_dir/fmtmsg.o $septel_tools_dir/gct_unix.o $septel_tools_dir/hqueue.o $septel_tools_dir/ident.o $septel_tools_dir/mem.o $septel_tools_dir/pack.o $septel_tools_dir/parse.o $septel_tools_dir/pool.o $septel_tools_dir/sdlsig.o $septel_tools_dir/strtonum.o $septel_tools_dir/timer.o $septel_tools_dir/trace.o "
|
||||
|
||||
if test "$V_PCAP" != septel ; then
|
||||
SSRC="pcap-septel.c"
|
||||
|
||||
fi
|
||||
ac_cv_lbl_septel_api=yes
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT($ac_cv_lbl_septel_api)
|
||||
if test $ac_cv_lbl_septel_api = no; then
|
||||
if test "$want_septel" = yes; then
|
||||
AC_MSG_ERROR(Septel API not found under directory $septel_root; use --without-septel)
|
||||
fi
|
||||
else
|
||||
AC_DEFINE(HAVE_SEPTEL_API, 1, [define if you have a Septel API])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$V_PCAP" = septel -a "$ac_cv_lbl_septel_api" = no; then
|
||||
AC_MSG_ERROR(Specifying the capture type as 'septel' requires the Septel API to be present; use --with-septel=DIR)
|
||||
fi
|
||||
|
||||
|
||||
AC_LBL_LEX_AND_YACC(V_LEX, V_YACC, pcap_)
|
||||
if test "$V_LEX" = lex ; then
|
||||
# Some versions of lex can't handle the definitions section of scanner.l .
|
||||
# Try lexing it and complain if it can't deal.
|
||||
AC_CACHE_CHECK([for capable lex], tcpdump_cv_capable_lex,
|
||||
if lex -t scanner.l > /dev/null 2>&1; then
|
||||
tcpdump_cv_capable_lex=yes
|
||||
else
|
||||
tcpdump_cv_capable_lex=insufficient
|
||||
fi)
|
||||
if test $tcpdump_cv_capable_lex = insufficient ; then
|
||||
AC_MSG_ERROR([Your operating system's lex is insufficient to compile
|
||||
libpcap. flex is a lex replacement that has many advantages, including
|
||||
being able to compile libpcap. For more information, see
|
||||
http://www.gnu.org/software/flex/flex.html .])
|
||||
fi
|
||||
fi
|
||||
|
||||
DYEXT="so"
|
||||
case "$host_os" in
|
||||
|
||||
aix*)
|
||||
dnl Workaround to enable certain features
|
||||
AC_DEFINE(_SUN,1,[define on AIX to get certain functions])
|
||||
;;
|
||||
|
||||
hpux9*)
|
||||
AC_DEFINE(HAVE_HPUX9,1,[on HP-UX 9.x])
|
||||
;;
|
||||
|
||||
hpux10.0*)
|
||||
;;
|
||||
|
||||
hpux10.1*)
|
||||
;;
|
||||
|
||||
hpux*)
|
||||
dnl HPUX 10.20 and above is similar to HPUX 9, but
|
||||
dnl not the same....
|
||||
dnl
|
||||
dnl XXX - DYEXT should be set to "sl" if this is building
|
||||
dnl for 32-bit PA-RISC, but should be left as "so" for
|
||||
dnl 64-bit PA-RISC or, I suspect, IA-64.
|
||||
AC_DEFINE(HAVE_HPUX10_20_OR_LATER,1,[on HP-UX 10.20 or later])
|
||||
;;
|
||||
|
||||
sinix*)
|
||||
AC_MSG_CHECKING(if SINIX compiler defines sinix)
|
||||
AC_CACHE_VAL(ac_cv_cc_sinix_defined,
|
||||
AC_TRY_COMPILE(
|
||||
[],
|
||||
[int i = sinix;],
|
||||
ac_cv_cc_sinix_defined=yes,
|
||||
ac_cv_cc_sinix_defined=no))
|
||||
AC_MSG_RESULT($ac_cv_cc_sinix_defined)
|
||||
if test $ac_cv_cc_sinix_defined = no ; then
|
||||
AC_DEFINE(sinix,1,[on sinix])
|
||||
fi
|
||||
;;
|
||||
|
||||
solaris*)
|
||||
AC_DEFINE(HAVE_SOLARIS,1,[On solaris])
|
||||
;;
|
||||
|
||||
darwin*)
|
||||
DYEXT="dylib"
|
||||
V_CCOPT="$V_CCOPT -fno-common"
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_PROG_RANLIB
|
||||
|
||||
AC_LBL_DEVEL(V_CCOPT)
|
||||
|
||||
AC_LBL_SOCKADDR_SA_LEN
|
||||
|
||||
AC_LBL_SOCKADDR_STORAGE
|
||||
|
||||
AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
|
||||
|
||||
AC_LBL_UNALIGNED_ACCESS
|
||||
|
||||
#
|
||||
# Makefile.in includes rules to generate version.h, so we assume
|
||||
# that it will be generated if autoconf is used.
|
||||
#
|
||||
AC_DEFINE(HAVE_VERSION_H, 1, [define if version.h is generated in the build procedure])
|
||||
|
||||
rm -f net
|
||||
ln -s ${srcdir}/bpf/net net
|
||||
|
||||
AC_SUBST(V_CCOPT)
|
||||
AC_SUBST(V_DEFS)
|
||||
AC_SUBST(V_INCLS)
|
||||
AC_SUBST(V_LIBS)
|
||||
AC_SUBST(V_LEX)
|
||||
AC_SUBST(V_PCAP)
|
||||
AC_SUBST(V_FINDALLDEVS)
|
||||
AC_SUBST(V_RANLIB)
|
||||
AC_SUBST(V_YACC)
|
||||
AC_SUBST(SSRC)
|
||||
AC_SUBST(DYEXT)
|
||||
|
||||
AC_PROG_INSTALL
|
||||
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_OUTPUT(Makefile)
|
||||
|
||||
if test -f .devel ; then
|
||||
make depend
|
||||
fi
|
||||
exit 0
|
|
@ -1,997 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html lang="en"><head><title>PCAP New Generation Dump File Format</title>
|
||||
<meta name="description" content="PCAP New Generation Dump File Format">
|
||||
<meta name="keywords" content="Internet-Draft, Libpcap, dump file format">
|
||||
<meta name="generator" content="xml2rfc v1.22 (http://xml.resource.org/)">
|
||||
<style type='text/css'>
|
||||
<!--
|
||||
body {
|
||||
font-family: verdana, charcoal, helvetica, arial, sans-serif;
|
||||
font-size: small ; color: #000000 ; background-color: #ffffff ; }
|
||||
.title { color: #990000; font-size: x-large ;
|
||||
font-weight: bold; text-align: right;
|
||||
font-family: helvetica, monaco, "MS Sans Serif", arial, sans-serif;
|
||||
background-color: transparent; }
|
||||
.filename { color: #666666; font-size: 18px; line-height: 28px;
|
||||
font-weight: bold; text-align: right;
|
||||
font-family: helvetica, arial, sans-serif;
|
||||
background-color: transparent; }
|
||||
td.rfcbug { background-color: #000000 ; width: 30px ; height: 30px ;
|
||||
text-align: justify; vertical-align: middle ; padding-top: 2px ; }
|
||||
td.rfcbug span.RFC { color: #666666; font-weight: bold; text-decoration: none;
|
||||
background-color: #000000 ;
|
||||
font-family: monaco, charcoal, geneva, "MS Sans Serif", helvetica, verdana, sans-serif;
|
||||
font-size: x-small ; }
|
||||
td.rfcbug span.hotText { color: #ffffff; font-weight: normal; text-decoration: none;
|
||||
text-align: center ;
|
||||
font-family: charcoal, monaco, geneva, "MS Sans Serif", helvetica, verdana, sans-serif;
|
||||
font-size: x-small ; background-color: #000000; }
|
||||
|
||||
A { font-weight: bold; }
|
||||
A:link { color: #990000; background-color: transparent ; }
|
||||
A:visited { color: #333333; background-color: transparent ; }
|
||||
A:active { color: #333333; background-color: transparent ; }
|
||||
|
||||
p { margin-left: 2em; margin-right: 2em; }
|
||||
p.copyright { font-size: x-small ; }
|
||||
p.toc { font-size: small ; font-weight: bold ; margin-left: 3em ;}
|
||||
|
||||
span.emph { font-style: italic; }
|
||||
span.strong { font-weight: bold; }
|
||||
span.verb { font-family: "Courier New", Courier, monospace ; }
|
||||
|
||||
ol.text { margin-left: 2em; margin-right: 2em; }
|
||||
ul.text { margin-left: 2em; margin-right: 2em; }
|
||||
li { margin-left: 3em; }
|
||||
|
||||
pre { margin-left: 3em; color: #333333; background-color: transparent;
|
||||
font-family: "Courier New", Courier, monospace ; font-size: small ;
|
||||
}
|
||||
|
||||
h3 { color: #333333; font-size: medium ;
|
||||
font-family: helvetica, arial, sans-serif ;
|
||||
background-color: transparent; }
|
||||
h4 { font-size: small; font-family: helvetica, arial, sans-serif ; }
|
||||
|
||||
table.bug { width: 30px ; height: 15px ; }
|
||||
td.bug { color: #ffffff ; background-color: #990000 ;
|
||||
text-align: center ; width: 30px ; height: 15px ;
|
||||
}
|
||||
td.bug A.link2 { color: #ffffff ; font-weight: bold;
|
||||
text-decoration: none;
|
||||
font-family: monaco, charcoal, geneva, "MS Sans Serif", helvetica, sans-serif;
|
||||
font-size: x-small ; background-color: transparent }
|
||||
|
||||
td.header { color: #ffffff; font-size: x-small ;
|
||||
font-family: arial, helvetica, sans-serif; vertical-align: top;
|
||||
background-color: #666666 ; width: 33% ; }
|
||||
td.author { font-weight: bold; margin-left: 4em; font-size: x-small ; }
|
||||
td.author-text { font-size: x-small; }
|
||||
table.data { vertical-align: top ; border-collapse: collapse ;
|
||||
border-style: solid solid solid solid ;
|
||||
border-color: black black black black ;
|
||||
font-size: small ; text-align: center ; }
|
||||
table.data th { font-weight: bold ;
|
||||
border-style: solid solid solid solid ;
|
||||
border-color: black black black black ; }
|
||||
table.data td {
|
||||
border-style: solid solid solid solid ;
|
||||
border-color: #333333 #333333 #333333 #333333 ; }
|
||||
|
||||
hr { height: 1px }
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<table summary="layout" width="66%" border="0" cellpadding="0" cellspacing="0"><tr><td><table summary="layout" width="100%" border="0" cellpadding="2" cellspacing="1">
|
||||
<tr><td class="header">Network Working Group</td><td class="header">L. Degioanni</td></tr>
|
||||
<tr><td class="header">Internet-Draft</td><td class="header">F. Risso</td></tr>
|
||||
<tr><td class="header">Expires: August 30, 2004</td><td class="header">Politecnico di Torino</td></tr>
|
||||
<tr><td class="header"> </td><td class="header">March 2004</td></tr>
|
||||
</table></td></tr></table>
|
||||
<div align="right"><span class="title"><br />PCAP New Generation Dump File Format</span></div>
|
||||
<div align="right"><span class="title"><br />pcap</span></div>
|
||||
|
||||
<h3>Status of this Memo</h3>
|
||||
<p>
|
||||
This document is an Internet-Draft and is
|
||||
in full conformance with all provisions of Section 10 of RFC2026.</p>
|
||||
<p>
|
||||
Internet-Drafts are working documents of the Internet Engineering
|
||||
Task Force (IETF), its areas, and its working groups.
|
||||
Note that other groups may also distribute working documents as
|
||||
Internet-Drafts.</p>
|
||||
<p>
|
||||
Internet-Drafts are draft documents valid for a maximum of six months
|
||||
and may be updated, replaced, or obsoleted by other documents at any time.
|
||||
It is inappropriate to use Internet-Drafts as reference material or to cite
|
||||
them other than as "work in progress."</p>
|
||||
<p>
|
||||
The list of current Internet-Drafts can be accessed at
|
||||
<a href='http://www.ietf.org/ietf/1id-abstracts.txt'>http://www.ietf.org/ietf/1id-abstracts.txt</a>.</p>
|
||||
<p>
|
||||
The list of Internet-Draft Shadow Directories can be accessed at
|
||||
<a href='http://www.ietf.org/shadow.html'>http://www.ietf.org/shadow.html</a>.</p>
|
||||
<p>
|
||||
This Internet-Draft will expire on August 30, 2004.</p>
|
||||
|
||||
<h3>Copyright Notice</h3>
|
||||
<p>
|
||||
Copyright (C) The Internet Society (2004). All Rights Reserved.</p>
|
||||
|
||||
<h3>Abstract</h3>
|
||||
|
||||
<p>This document describes a format to dump captured packets on a file. This format is extensible and it is currently proposed for implementation in the libpcap/WinPcap packet capture library.
|
||||
</p><a name="toc"></a><br /><hr />
|
||||
<h3>Table of Contents</h3>
|
||||
<p class="toc">
|
||||
<a href="#anchor1">1.</a>
|
||||
Objectives<br />
|
||||
<a href="#anchor2">2.</a>
|
||||
General File Structure<br />
|
||||
<a href="#sectionblock">2.1</a>
|
||||
General Block Structure<br />
|
||||
<a href="#anchor3">2.2</a>
|
||||
Block Types<br />
|
||||
<a href="#anchor4">2.3</a>
|
||||
Block Hierarchy and Precedence<br />
|
||||
<a href="#anchor5">2.4</a>
|
||||
Data format<br />
|
||||
<a href="#anchor6">3.</a>
|
||||
Block Definition<br />
|
||||
<a href="#sectionshb">3.1</a>
|
||||
Section Header Block (mandatory)<br />
|
||||
<a href="#sectionidb">3.2</a>
|
||||
Interface Description Block (mandatory)<br />
|
||||
<a href="#sectionpb">3.3</a>
|
||||
Packet Block (optional)<br />
|
||||
<a href="#anchor7">3.4</a>
|
||||
Simple Packet Block (optional)<br />
|
||||
<a href="#anchor8">3.5</a>
|
||||
Name Resolution Block (optional)<br />
|
||||
<a href="#anchor9">3.6</a>
|
||||
Interface Statistics Block (optional)<br />
|
||||
<a href="#sectionopt">4.</a>
|
||||
Options<br />
|
||||
<a href="#anchor10">5.</a>
|
||||
Experimental Blocks (deserved to a further investigation)<br />
|
||||
<a href="#anchor11">5.1</a>
|
||||
Other Packet Blocks (experimental)<br />
|
||||
<a href="#anchor12">5.2</a>
|
||||
Compression Block (experimental)<br />
|
||||
<a href="#anchor13">5.3</a>
|
||||
Encryption Block (experimental)<br />
|
||||
<a href="#anchor14">5.4</a>
|
||||
Fixed Length Block (experimental)<br />
|
||||
<a href="#anchor15">5.5</a>
|
||||
Directory Block (experimental)<br />
|
||||
<a href="#anchor16">5.6</a>
|
||||
Traffic Statistics and Monitoring Blocks (experimental)<br />
|
||||
<a href="#anchor17">5.7</a>
|
||||
Event/Security Block (experimental)<br />
|
||||
<a href="#anchor18">6.</a>
|
||||
Conclusions<br />
|
||||
<a href="#anchor19">7.</a>
|
||||
Most important open issues<br />
|
||||
<a href="#rfc.copyright">§</a>
|
||||
Intellectual Property and Copyright Statements<br />
|
||||
</p>
|
||||
<br clear="all" />
|
||||
|
||||
<a name="anchor1"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.1"></a><h3>1. Objectives</h3>
|
||||
|
||||
<p>The problem of exchanging packet traces becomes more and more critical every day; unfortunately, no standard solutions exist for this task right now. One of the most accepted packet interchange formats is the one defined by libpcap, which is rather old and does not fit for some of the nowadays applications especially in terms of extensibility.
|
||||
</p>
|
||||
<p>This document proposes a new format for dumping packet traces. The following goals are being pursued:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Extensibility: aside of some common functionalities, third parties should be able to enrich the information embedded in the file with proprietary extensions, which will be ignored by tools that are not able to understand them.
|
||||
</li>
|
||||
<li>Portability: a capture trace must contain all the information needed to read data independently from network, hardware and operating system of the machine that made the capture.
|
||||
</li>
|
||||
<li>Merge/Append data: it should be possible to add data at the end of a given file, and the resulting file must still be readable.
|
||||
</li>
|
||||
</ul>
|
||||
<a name="anchor2"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.2"></a><h3>2. General File Structure</h3>
|
||||
|
||||
<a name="rfc.section.2.1"></a><h4><a name="sectionblock">2.1</a> General Block Structure</h4>
|
||||
|
||||
<p>A capture file is organized in blocks, that are appended one to another to form the file. All the blocks share a common format, which is shown in <a href="#formatblock">Figure 1</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatblock"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Type |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Total Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ Block Body /
|
||||
/ /* variable length, aligned to 32 bits */ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Total Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Basic block structure. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The fields have the following meaning:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Block Type (32 bits): unique value that identifies the block. Values whose Most Significant Bit (MSB) is equal to 1 are reserved for local use. They allow to save private data to the file and to extend the file format.
|
||||
</li>
|
||||
<li>Block Total Length: total size of this block, in bytes. For instance, a block that does not have a body has a length of 12 bytes.
|
||||
</li>
|
||||
<li>Block Body: content of the block.
|
||||
</li>
|
||||
<li>Block Total Length: total size of this block, in bytes. This field is duplicated for permitting backward file navigation.
|
||||
</li>
|
||||
</ul>
|
||||
<p>This structure, shared among all blocks, makes easy to process a file and to skip unneeded or unknown blocks. Blocks can be nested one inside the others (NOTE: needed?). Some of the blocks are mandatory, i.e. a dump file is not valid if they are not present, other are optional.
|
||||
</p>
|
||||
<p>The structure of the blocks allows to define other blocks if needed. A parser that does non understand them can simply ignore their content.
|
||||
</p>
|
||||
<a name="rfc.section.2.2"></a><h4><a name="anchor3">2.2</a> Block Types</h4>
|
||||
|
||||
<p>The currently defined blocks are the following:
|
||||
</p>
|
||||
<ol class="text">
|
||||
<li>Section Header Block: it defines the most important characteristics of the capture file.
|
||||
</li>
|
||||
<li>Interface Description Block: it defines the most important characteristics of the interface(s) used for capturing traffic.
|
||||
</li>
|
||||
<li>Packet Block: it contains a single captured packet, or a portion of it.
|
||||
</li>
|
||||
<li>Simple Packet Block: it contains a single captured packet, or a portion of it, with only a minimal set of information about it.
|
||||
</li>
|
||||
<li>Name Resolution Block: it defines the mapping from numeric addresses present in the packet dump and the canonical name counterpart.
|
||||
</li>
|
||||
<li>Capture Statistics Block: it defines how to store some statistical data (e.g. packet dropped, etc) which can be useful to undestand the conditions in which the capture has been made.
|
||||
</li>
|
||||
<li>Compression Marker Block: TODO
|
||||
</li>
|
||||
<li>Encryption Marker Block: TODO
|
||||
</li>
|
||||
<li>Fixed Length Marker Block: TODO
|
||||
</li>
|
||||
</ol>
|
||||
<p>The following blocks instead are considered interesting but the authors believe that they deserve more in-depth discussion before being defined:
|
||||
</p>
|
||||
<ol class="text">
|
||||
<li>Further Packet Blocks
|
||||
</li>
|
||||
<li>Directory Block
|
||||
</li>
|
||||
<li>Traffic Statistics and Monitoring Blocks
|
||||
</li>
|
||||
<li>Alert and Security Blocks
|
||||
</li>
|
||||
</ol>
|
||||
<p>TODO Currently standardized Block Type codes are specified in Appendix 1.
|
||||
</p>
|
||||
<a name="rfc.section.2.3"></a><h4><a name="anchor4">2.3</a> Block Hierarchy and Precedence</h4>
|
||||
|
||||
<p>The file must begin with a Section Header Block. However, more than one Section Header Block can be present on the dump, each one covering the data following it till the next one (or the end of file). A Section includes the data delimited by two Section Header Blocks (or by a Section Header Block and the end of the file), including the first Section Header Block.
|
||||
</p>
|
||||
<p>In case an application cannot read a Section because of different version number, it must skip everything until the next Section Header Block. Note that, in order to properly skip the blocks until the next section, all blocks must have the fields Type and Length at the beginning. This is a mandatory requirement that must be maintained in future versions of the block format.
|
||||
</p>
|
||||
<p><a href="#fssample-SHB">Figure 2</a> shows two valid files: the first has a typical configuration, with a single Section Header that covers the whole file. The second one contains three headers, and is normally the result of file concatenation. An application that understands only version 1.0 of the file format skips the intermediate section and restart processing the packets after the third Section Header.
|
||||
</p><br /><hr />
|
||||
<a name="fssample-SHB"></a>
|
||||
<pre>
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SHB v1.0 | Data |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Typical configuration with a single Section Header Block
|
||||
|
||||
|
||||
|-- 1st Section --|-- 2nd Section --|-- 3rd Section --|
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SHB v1.0 | Data | SHB V1.1 | Data | SHB V1.0 | Data |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Configuration with three different Section Header Blocks
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> File structure example: the Section Header Block. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>NOTE: TO BE COMPLETED with some examples of other blocks
|
||||
</p>
|
||||
<a name="rfc.section.2.4"></a><h4><a name="anchor5">2.4</a> Data format</h4>
|
||||
|
||||
<p>Data contained in each section will always be saved according to the characteristics (little endian / big endian) of the dumping machine. This refers to all fields that are saved as numbers and that span over two or more bytes.
|
||||
</p>
|
||||
<p>The approach of having each section saved in the native format of the generating host is more efficient because it avoids translation of data when reading / writing on the host itself, which is the most common case when generating/processing capture dumps.
|
||||
</p>
|
||||
<p>TODO Probably we have to specify something more here. Is what we're saying enough to avoid any kind of ambiguity?.
|
||||
</p>
|
||||
<a name="anchor6"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.3"></a><h3>3. Block Definition</h3>
|
||||
|
||||
<p>This section details the format of the body of the blocks currently defined.
|
||||
</p>
|
||||
<a name="rfc.section.3.1"></a><h4><a name="sectionshb">3.1</a> Section Header Block (mandatory)</h4>
|
||||
|
||||
<p>The Section Header Block is mandatory. It identifies the beginning of a section of the capture dump file. Its format is shown in <a href="#formatSHB">Figure 3</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatSHB"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Magic |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Major | Minor |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Section Header Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The meaning of the fields is:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Magic: magic number, whose value is the hexadecimal number 0x1A2B3C4D. This number can be used to distinguish section that have been saved on little-endian machines from the one saved on big-endian machines.
|
||||
</li>
|
||||
<li>Major: number of the current mayor version of the format. Current value is 1.
|
||||
</li>
|
||||
<li>Minor: number of the current minor version of the format. Current value is 0.
|
||||
</li>
|
||||
<li>Options: optionally, a list of options (formatted according to the rules defined in <a href="#sectionopt">Section 4</a>) can be present.
|
||||
</li>
|
||||
</ul>
|
||||
<p>Aside form the options defined in <a href="#sectionopt">Section 4</a>, the following options are valid within this block:
|
||||
</p><a name="InterfaceOptions1"></a>
|
||||
<table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">Hardware</td>
|
||||
<td align="left">2</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">An ascii string containing the description of the hardware used to create this section.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">Operating System</td>
|
||||
<td align="left">3</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">An ascii string containing the name of the operating system used to create this section.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">User Application</td>
|
||||
<td align="left">3</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">An ascii string containing the name of the application used to create this section.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The Section Header Block does not contain data but it rather identifies a list of blocks (interfaces, packets) that are logically correlated. This block does not contain any reference to the size of the section it is currently delimiting, therefore the reader cannot skip a whole section at once. In case a section must be skipped, the user has to repeatedly skip all the blocks contained within it; this makes the parsing of the file slower but it permits to append several capture dumps at the same file.
|
||||
</p>
|
||||
<a name="rfc.section.3.2"></a><h4><a name="sectionidb">3.2</a> Interface Description Block (mandatory)</h4>
|
||||
|
||||
<p>The Interface Description Block is mandatory. This block is needed to specify the characteristics of the network interface on which the capture has been made. In order to properly associate the captured data to the corresponding interface, the Interface Description Block must be defined before any other block that uses it; therefore, this block is usually placed immediately after the Section Header Block.
|
||||
</p>
|
||||
<p>An Interface Description Block is valid only inside the section which it belongs to. The structure of a Interface Description Block is shown in <a href="#formatidb">Figure 4</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatidb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | LinkType |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SnapLen |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Interface Description Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The meaning of the fields is:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Interface ID: a progressive number that identifies uniquely any interface inside current section. Two Interface Description Blocks can have the same Interface ID only if they are in different sections of the file. The Interface ID is referenced by the packet blocks.
|
||||
</li>
|
||||
<li>LinkType: a value that defines the link layer type of this interface.
|
||||
</li>
|
||||
<li>SnapLen: maximum number of bytes dumped from each packet. The portion of each packet that exceeds this value will not be stored in the file.
|
||||
</li>
|
||||
<li>Options: optionally, a list of options (formatted according to the rules defined in <a href="#sectionopt">Section 4</a>) can be present.
|
||||
</li>
|
||||
</ul>
|
||||
<p>In addition to the options defined in <a href="#sectionopt">Section 4</a>, the following options are valid within this block:
|
||||
</p><a name="InterfaceOptions2"></a>
|
||||
<table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_name</td>
|
||||
<td align="left">2</td>
|
||||
<td align="left">Variable</td>
|
||||
<td align="left">Name of the device used to capture data.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_IPv4addr</td>
|
||||
<td align="left">3</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">Interface network address and netmask.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_IPv6addr</td>
|
||||
<td align="left">4</td>
|
||||
<td align="left">17</td>
|
||||
<td align="left">Interface network address and prefix length (stored in the last byte).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_MACaddr</td>
|
||||
<td align="left">5</td>
|
||||
<td align="left">6</td>
|
||||
<td align="left">Interface Hardware MAC address (48 bits).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_EUIaddr</td>
|
||||
<td align="left">6</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">Interface Hardware EUI address (64 bits), if available.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_speed</td>
|
||||
<td align="left">7</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">Interface speed (in bps).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_tsaccur</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">1</td>
|
||||
<td align="left">Precision of timestamps. If the Most Significant Bit is equal to zero, the remaining bits indicates the accuracy as as a negative power of 10 (e.g. 6 means microsecond accuracy). If the Most Significant Bit is equal to zero, the remaining bits indicates the accuracy as as negative power of 2 (e.g. 10 means 1/1024 of second). If this option is not present, a precision of 10^-6 is assumed.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_tzone</td>
|
||||
<td align="left">9</td>
|
||||
<td align="left">4</td>
|
||||
<td align="left">Time zone for GMT support (TODO: specify better).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_flags</td>
|
||||
<td align="left">10</td>
|
||||
<td align="left">4</td>
|
||||
<td align="left">Interface flags. (TODO: specify better. Possible flags: promiscuous, inbound/outbound, traffic filtered during capture).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_filter</td>
|
||||
<td align="left">11</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">The filter (e.g. "capture only TCP traffic") used to capture traffic. The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more). More details about this format will be presented in Appendix XXX (TODO).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">if_opersystem</td>
|
||||
<td align="left">12</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">An ascii string containing the name of the operating system of the machine that hosts this interface. This can be different from the same information that can be contained by the Section Header Block (<a href="#sectionshb">Section 3.1</a>) because the capture can have been done on a remote machine.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a name="rfc.section.3.3"></a><h4><a name="sectionpb">3.3</a> Packet Block (optional)</h4>
|
||||
|
||||
<p>A Packet Block is the standard container for storing the packets coming from the network. The Packet Block is optional because packets can be stored either by means of this block or the Simple Packet Block, which can be used to speed up dump generation. The format of a packet block is shown in <a href="#formatpb">Figure 5</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatpb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | Drops Count |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Timestamp (High) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Timestamp (Low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Captured Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Packet Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
| Packet Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Packet Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The Packet Block has the following fields:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Interface ID: Specifies the interface this packet comes from, and corresponds to the ID of one of the Interface Description Blocks present in this section of the file (see <a href="#formatidb">Figure 4</a>).
|
||||
</li>
|
||||
<li>Drops Count: a local drop counter. It specified the number of packets lost (by the interface and the operating system) between this packet and the preceding one. The value xFFFF (in hexadecimal) is reserved for those systems in which this information is not available.
|
||||
</li>
|
||||
<li>Timestamp (High): the most significative part of the timestamp. in standard Unix format, i.e. from 1/1/1970.
|
||||
</li>
|
||||
<li>Timestamp (Low): the less significative part of the timestamp. The way to interpret this field is specified by the 'ts_accur' option (see <a href="#formatidb">Figure 4</a>) of the Interface Description block referenced by this packet. If the Interface Description block does not contain a 'ts_accur' option, then this field is expressed in microseconds.
|
||||
</li>
|
||||
<li>Captured Len: number of bytes captured from the packet (i.e. the length of the Packet Data field). It will be the minimum value among the actual Packet Length and the snapshot length (defined in <a href="#formatidb">Figure 4</a>).
|
||||
</li>
|
||||
<li>Packet Len: actual length of the packet when it was transmitted on the network. Can be different from Captured Len if the user wants only a snapshot of the packet.
|
||||
</li>
|
||||
<li>Packet Data: the data coming from the network, including link-layer headers. The length of this field is Captured Len. The format of the link-layer headers depends on the LinkType field specified in the Interface Description Block (see <a href="#sectionidb">Section 3.2</a>) and it is specified in Appendix XXX (TODO).
|
||||
</li>
|
||||
<li>Options: optionally, a list of options (formatted according to the rules defined in <a href="#sectionopt">Section 4</a>) can be present.
|
||||
</li>
|
||||
</ul>
|
||||
<p>
|
||||
</p>
|
||||
<a name="rfc.section.3.4"></a><h4><a name="anchor7">3.4</a> Simple Packet Block (optional)</h4>
|
||||
|
||||
<p>The Simple Packet Block is a lightweight container for storing the packets coming from the network. Its presence is optional.
|
||||
</p>
|
||||
<p>A Simple Packet Block is similar to a Packet Block (see <a href="#sectionpb">Section 3.3</a>), but it is smaller, simpler to process and contains only a minimal set of information. This block is preferred to the standard Packet Block when performance or space occupation are critical factors, such as in sustained traffic dump applications. A capture file can contain both Packet Blocks and Simple Packet Blocks: for example, a capture tool could switch from Packet Blocks to Simple Packet Blocks when the hardware resources become critical.
|
||||
</p>
|
||||
<p>The Simple Packet Block does not contain the Interface ID field. Therefore, it must be assumed that all the Simple Packet Blocks have been captured on the interface previously specified in the Interface Description Block.
|
||||
</p>
|
||||
<p><a href="#formatpbs">Figure 6</a> shows the format of the Simple Packet Block.
|
||||
</p><br /><hr />
|
||||
<a name="formatpbs"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Packet Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
| Packet Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Simple Packet Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The Packet Block has the following fields:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Packet Len: actual length of the packet when it was transmitted on the network. Can be different from captured len if the packet has been truncated.
|
||||
</li>
|
||||
<li>Packet data: the data coming from the network, including link-layers headers. The length of this field can be derived from the field Block Total Length, present in the Block Header.
|
||||
</li>
|
||||
</ul>
|
||||
<p>The Simple Packet Block does not contain the timestamp because this is one of the most costly operations on PCs. Additionally, there are applications that do not require it; e.g. an Intrusion Detection System is interested in packets, not in their timestamp.
|
||||
</p>
|
||||
<p>The Simple Packet Block is very efficient in term of disk space: a snapshot of length 100 bytes requires only 16 bytes of overhead, which corresponds to an efficiency of more than 86%.
|
||||
</p>
|
||||
<a name="rfc.section.3.5"></a><h4><a name="anchor8">3.5</a> Name Resolution Block (optional)</h4>
|
||||
|
||||
<p>The Name Resolution Block is used to support the correlation of numeric addresses (present in the captured packets) and their corresponding canonical names and it is optional. Having the literal names saved in the file, this prevents the need of a name resolution in a delayed time, when the association between names and addresses can be different from the one in use at capture time. Moreover, The Name Resolution Block avoids the need of issuing a lot of DNS requests every time the trace capture is opened, and allows to have name resolution also when reading the capture with a machine not connected to the network.
|
||||
</p>
|
||||
<p>The format of the Name Resolution Block is shown in <a href="#formatnrb">Figure 7</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatnrb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Record Type | Record Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Record Value |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
| | | | |
|
||||
+-+-+-+-+-+-+-+-+ + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
. . . other records . . .
|
||||
| Record Type == end_of_recs | Record Length == 00 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Name Resolution Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>A Name Resolution Block is a zero-terminated list of records (in the TLV format), each of which contains an association between a network address and a name. There are three possible types of records:
|
||||
</p><a name="nrrecords"></a>
|
||||
<table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">end_of_recs</td>
|
||||
<td align="left">0</td>
|
||||
<td align="left">0</td>
|
||||
<td align="left">End of records</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">ip4_rec</td>
|
||||
<td align="left">1</td>
|
||||
<td align="left">Variable</td>
|
||||
<td align="left">Specifies an IPv4 address (contained in the first 4 bytes), followed by one or more zero-terminated strings containing the DNS entries for that address.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">ip6_rec</td>
|
||||
<td align="left">1</td>
|
||||
<td align="left">Variable</td>
|
||||
<td align="left">Specifies an IPv6 address (contained in the first 16 bytes), followed by one or more zero-terminated strings containing the DNS entries for that address.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>After the list or Name Resolution Records, optionally, a list of options (formatted according to the rules defined in <a href="#sectionopt">Section 4</a>) can be present.
|
||||
</p>
|
||||
<p>A Name Resolution Block is normally placed at the beginning of the file, but no assumptions can be taken about its position. Name Resolution Blocks can be added in a second time by tools that process the file, like network analyzers.
|
||||
</p>
|
||||
<p>In addiction to the options defined in <a href="#sectionopt">Section 4</a>, the following options are valid within this block:
|
||||
</p><table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">ns_dnsname</td>
|
||||
<td align="left">2</td>
|
||||
<td align="left">Variable</td>
|
||||
<td align="left">An ascii string containing the name of the machine (DNS server) used to perform the name resolution.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a name="rfc.section.3.6"></a><h4><a name="anchor9">3.6</a> Interface Statistics Block (optional)</h4>
|
||||
|
||||
<p>The Interface Statistics Block contains the capture statistics for a given interface and it is optional. The statistics are referred to the interface defined in the current Section identified by the Interface ID field.
|
||||
</p>
|
||||
<p>The format of the Interface Statistics Block is shown in <a href="#formatisb">Figure 8</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatisb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| IfRecv |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| IfDrop |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| FilterAccept |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| OSDrop |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| UsrDelivered |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | Reserved |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Interface Statistics Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The fields have the following meaning:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>IfRecv: number of packets received from the interface during the capture. This number is reported as a 64 bits value, in which the most significat bits are located in the first four bytes of the field.
|
||||
</li>
|
||||
<li>IfDrop: number of packets dropped by the interface during the capture due to lack of resources.
|
||||
</li>
|
||||
<li>FilterAccept: number of packets accepeted by filter during current capture.
|
||||
</li>
|
||||
<li>OSDrop: number of packets dropped by the operating system during the capture.
|
||||
</li>
|
||||
<li>UsrDelivered: number of packets delivered to the user. UsrDelivered can be different from the value 'FilterAccept - OSDropped' because some packets could still lay in the OS buffers when the capture ended.
|
||||
</li>
|
||||
<li>Interface ID: reference to an Interface Description Block.
|
||||
</li>
|
||||
<li>Reserved: Reserved to future use.
|
||||
</li>
|
||||
<li>Options: optionally, a list of options (formatted according to the rules defined in <a href="#sectionopt">Section 4</a>) can be present.
|
||||
</li>
|
||||
</ul>
|
||||
<p>In addiction to the options defined in <a href="#sectionopt">Section 4</a>, the following options are valid within this block:
|
||||
</p><table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">isb_starttime</td>
|
||||
<td align="left">2</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">Time in which the capture started; time will be stored in two blocks of four bytes each, containing the timestamp in seconds and nanoseconds.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">isb_endtime</td>
|
||||
<td align="left">3</td>
|
||||
<td align="left">8</td>
|
||||
<td align="left">Time in which the capture started; time will be stored in two blocks of four bytes each, containing the timestamp in seconds and nanoseconds.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a name="sectionopt"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.4"></a><h3>4. Options</h3>
|
||||
|
||||
<p>Almost all blocks have the possibility to embed optional fields. Optional fields can be used to insert some information that may be useful when reading data, but that it is not really needed for packet processing. Therefore, each tool can be either read the content of the optional fields (if any), or skip them at once.
|
||||
</p>
|
||||
<p>Skipping all the optional fields at once is straightforward because most of the blocks have a fixed length, therefore the field Block Length (present in the General Block Structure, see <a href="#sectionblock">Section 2.1</a>) can be used to skip everything till the next block.
|
||||
</p>
|
||||
<p>Options are a list of Type - Length - Value fields, each one containing a single value:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Option Type (2 bytes): it contains the code that specifies the type of the current TLV record. Option types whose Most Significant Bit is equal to one are reserved for local use; therefore, there is no guarantee that the code used is unique among all capture files (generated by other applications). In case of vendor-specific extensions that have to be identified uniquely, vendors must request an Option Code whose MSB is equal to zero.
|
||||
</li>
|
||||
<li>Option Length (2 bytes): it contains the length of the following 'Option Value' field.
|
||||
</li>
|
||||
<li>Option Value (variable length): it contains the value of the given option. The length of this field as been specified by the Option Length field.
|
||||
</li>
|
||||
</ul>
|
||||
<p>Options may be repeated several times (e.g. an interface that has several IP addresses associated to it). The option list is terminated by a special code which is the 'End of Option'.
|
||||
</p>
|
||||
<p>The format of the optional fields is shown in <a href="#formatopt">Figure 9</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatopt"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Code | Option Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Value |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
| / / / |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ . . . other options . . . /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Code == opt_endofopt | Option Length == 0 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Options format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The following codes can always be present in any optional field:
|
||||
</p><table class="data" align="center" border="1" cellpadding="2" cellspacing="2">
|
||||
<tr>
|
||||
<th align="left" width="25%">Name</th>
|
||||
<th align="left" width="25%">Code</th>
|
||||
<th align="left" width="25%">Length</th>
|
||||
<th align="left" width="25%">Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">opt_endofopt</td>
|
||||
<td align="left">0</td>
|
||||
<td align="left">0</td>
|
||||
<td align="left">End of options: it is used to delimit the end of the optional fields. This block cannot be repeated within a given list of options.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left">opt_comment</td>
|
||||
<td align="left">1</td>
|
||||
<td align="left">variable</td>
|
||||
<td align="left">Comment: it is an ascii string containing a comment that is associated to the current block.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a name="anchor10"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.5"></a><h3>5. Experimental Blocks (deserved to a further investigation)</h3>
|
||||
|
||||
<a name="rfc.section.5.1"></a><h4><a name="anchor11">5.1</a> Other Packet Blocks (experimental)</h4>
|
||||
|
||||
<p>Can some other packet blocks (besides the two described in the previous paragraphs) be useful?
|
||||
</p>
|
||||
<a name="rfc.section.5.2"></a><h4><a name="anchor12">5.2</a> Compression Block (experimental)</h4>
|
||||
|
||||
<p>The Compression Block is optional. A file can contain an arbitrary number of these blocks. A Compression Block, as the name says, is used to store compressed data. Its format is shown in <a href="#formatcb">Figure 10</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formatcb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Compr. Type | |
|
||||
+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Compressed Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Compression Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The fields have the following meaning:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Compression Type: specifies the compression algorithm. Possible values for this field are 0 (uncompressed), 1 (Lempel Ziv), 2 (Gzip), other?? Probably some kind of dumb and fast compression algorithm could be effective with some types of traffic (for example web), but which?
|
||||
</li>
|
||||
<li>Compressed Data: data of this block. Once decompressed, it is made of other blocks.
|
||||
</li>
|
||||
</ul>
|
||||
<a name="rfc.section.5.3"></a><h4><a name="anchor13">5.3</a> Encryption Block (experimental)</h4>
|
||||
|
||||
<p>The Encryption Block is optional. A file can contain an arbitrary number of these blocks. An Encryption Block is used to sotre encrypted data. Its format is shown in <a href="#formateb">Figure 11</a>.
|
||||
</p><br /><hr />
|
||||
<a name="formateb"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Encr. Type | |
|
||||
+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Compressed Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Encryption Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The fields have the following meaning:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Compression Type: specifies the encryption algorithm. Possible values for this field are ??? NOTE: this block should probably contain other fields, depending on the encryption algorithm. To be define precisely.
|
||||
</li>
|
||||
<li>Encrypted Data: data of this block. Once decripted, it consists of other blocks.
|
||||
</li>
|
||||
</ul>
|
||||
<a name="rfc.section.5.4"></a><h4><a name="anchor14">5.4</a> Fixed Length Block (experimental)</h4>
|
||||
|
||||
<p>The Fixed Length Block is optional. A file can contain an arbitrary number of these blocks. A Fixed Length Block can be used to optimize the access to the file. Its format is shown in <a href="#formatflm">Figure 12</a>.
|
||||
A Fixed Length Block stores records with constant size. It contains a set of Blocks (normally Packet Blocks or Simple Packet Blocks), of wihich it specifies the size. Knowing this size a priori helps to scan the file and to load some portions of it without truncating a block, and is particularly useful with cell-based networks like ATM.
|
||||
</p><br /><hr />
|
||||
<a name="formatflm"></a>
|
||||
<pre>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Cell Size | |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Fixed Size Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</pre>
|
||||
<table border="0" cellpadding="0" cellspacing="2" align="center"><tr><td align="center"><font face="monaco, MS Sans Serif" size="1"><b> Fixed Length Block format. </b></font><br /></td></tr></table><hr size="1" shade="0">
|
||||
|
||||
<p>The fields have the following meaning:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>Cell size: the size of the blocks contained in the data field.
|
||||
</li>
|
||||
<li>Fixed Size Data: data of this block.
|
||||
</li>
|
||||
</ul>
|
||||
<a name="rfc.section.5.5"></a><h4><a name="anchor15">5.5</a> Directory Block (experimental)</h4>
|
||||
|
||||
<p>If present, this block contains the following information:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>number of indexed packets (N)
|
||||
</li>
|
||||
<li>table with position and length of any indexed packet (N entries)
|
||||
</li>
|
||||
</ul>
|
||||
<p>A directory block must be followed by at least N packets, otherwise it must be considered invalid. It can be used to efficiently load portions of the file to memory and to support operations on memory mapped files. This block can be added by tools like network analyzers as a consequence of file processing.
|
||||
</p>
|
||||
<a name="rfc.section.5.6"></a><h4><a name="anchor16">5.6</a> Traffic Statistics and Monitoring Blocks (experimental)</h4>
|
||||
|
||||
<p>One or more blocks could be defined to contain network statistics or traffic monitoring information. They could be use to store data collected from RMON or Netflow probes, or from other network monitoring tools.
|
||||
</p>
|
||||
<a name="rfc.section.5.7"></a><h4><a name="anchor17">5.7</a> Event/Security Block (experimental)</h4>
|
||||
|
||||
<p>This block could be used to store events. Events could contain generic information (for example network load over 50%, server down...) or security alerts. An event could be:
|
||||
</p>
|
||||
<ul class="text">
|
||||
<li>skipped, if the application doesn't know how to do with it
|
||||
</li>
|
||||
<li>processed independently by the packets. In other words, the applications skips the packets and processes only the alerts
|
||||
</li>
|
||||
<li>processed in relation to packets: for example, a security tool could load only the packets of the file that are near a security alert; a monitorg tool could skip the packets captured while the server was down.
|
||||
</li>
|
||||
</ul>
|
||||
<a name="anchor18"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.6"></a><h3>6. Conclusions</h3>
|
||||
|
||||
<p>The file format proposed in this document should be very versatile and satisfy a wide range of applications.
|
||||
In the simplest case, it can contain a raw dump of the network data, made of a series of Simple Packet Blocks.
|
||||
In the most complex case, it can be used as a repository for heterogeneous information.
|
||||
In every case, the file remains easy to parse and an application can always skip the data it is not interested in; at the same time, different applications can share the file, and each of them can benfit of the information produced by the others.
|
||||
Two or more files can be concatenated obtaining another valid file.
|
||||
</p>
|
||||
<a name="anchor19"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<a name="rfc.section.7"></a><h3>7. Most important open issues</h3>
|
||||
|
||||
<ul class="text">
|
||||
<li>Data, in the file, must be byte or word aligned? Currently, the structure of this document is not consistent with respect to this point.
|
||||
</li>
|
||||
</ul><a name="rfc.copyright"></a><br /><hr />
|
||||
<table summary="layout" cellpadding="0" cellspacing="2" class="bug" align="right"><tr><td class="bug"><a href="#toc" class="link2"> TOC </a></td></tr></table>
|
||||
<h3>Intellectual Property Statement</h3>
|
||||
<p class='copyright'>
|
||||
The IETF takes no position regarding the validity or scope of
|
||||
any intellectual property or other rights that might be claimed
|
||||
to pertain to the implementation or use of the technology
|
||||
described in this document or the extent to which any license
|
||||
under such rights might or might not be available; neither does
|
||||
it represent that it has made any effort to identify any such
|
||||
rights. Information on the IETF's procedures with respect to
|
||||
rights in standards-track and standards-related documentation
|
||||
can be found in BCP-11. Copies of claims of rights made
|
||||
available for publication and any assurances of licenses to
|
||||
be made available, or the result of an attempt made
|
||||
to obtain a general license or permission for the use of such
|
||||
proprietary rights by implementors or users of this
|
||||
specification can be obtained from the IETF Secretariat.</p>
|
||||
<p class='copyright'>
|
||||
The IETF invites any interested party to bring to its
|
||||
attention any copyrights, patents or patent applications, or
|
||||
other proprietary rights which may cover technology that may be
|
||||
required to practice this standard. Please address the
|
||||
information to the IETF Executive Director.</p>
|
||||
<h3>Full Copyright Statement</h3>
|
||||
<p class='copyright'>
|
||||
Copyright (C) The Internet Society (2004). All Rights Reserved.</p>
|
||||
<p class='copyright'>
|
||||
This document and translations of it may be copied and furnished to
|
||||
others, and derivative works that comment on or otherwise explain it
|
||||
or assist in its implementation may be prepared, copied, published and
|
||||
distributed, in whole or in part, without restriction of any kind,
|
||||
provided that the above copyright notice and this paragraph are
|
||||
included on all such copies and derivative works. However, this
|
||||
document itself may not be modified in any way, such as by removing
|
||||
the copyright notice or references to the Internet Society or other
|
||||
Internet organizations, except as needed for the purpose of
|
||||
developing Internet standards in which case the procedures for
|
||||
copyrights defined in the Internet Standards process must be
|
||||
followed, or as required to translate it into languages other than
|
||||
English.</p>
|
||||
<p class='copyright'>
|
||||
The limited permissions granted above are perpetual and will not be
|
||||
revoked by the Internet Society or its successors or assignees.</p>
|
||||
<p class='copyright'>
|
||||
This document and the information contained herein is provided on an
|
||||
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
||||
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
||||
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.</p>
|
||||
<h3>Acknowledgment</h3>
|
||||
<p class='copyright'>
|
||||
Funding for the RFC Editor function is currently provided by the
|
||||
Internet Society.</p>
|
||||
</body></html>
|
File diff suppressed because it is too large
Load Diff
|
@ -1,746 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
|
||||
|
||||
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
|
||||
<?rfc toc="yes"?>
|
||||
<rfc ipr="full2026" docname="draft-libpcap-dump-format-00.txt">
|
||||
<front>
|
||||
<title>PCAP New Generation Dump File Format</title>
|
||||
<author initials="L." surname="Degioanni" fullname="Loris Degioanni">
|
||||
<organization>Politecnico di Torino</organization>
|
||||
<address>
|
||||
<postal>
|
||||
<street>Corso Duca degli Abruzzi, 24</street>
|
||||
<city>Torino</city>
|
||||
<code>10129</code>
|
||||
<country>Italy</country>
|
||||
</postal>
|
||||
<phone>+39 011 564 7008</phone>
|
||||
<email>loris.degioanni@polito.it</email>
|
||||
<uri>http://netgroup.polito.it/loris/</uri>
|
||||
</address>
|
||||
</author>
|
||||
<author initials="F." surname="Risso" fullname="Fulvio Risso">
|
||||
<organization>Politecnico di Torino</organization>
|
||||
<address>
|
||||
<postal>
|
||||
<street>Corso Duca degli Abruzzi, 24</street>
|
||||
<city>Torino</city>
|
||||
<code>10129</code>
|
||||
<country>Italy</country>
|
||||
</postal>
|
||||
<phone>+39 011 564 7008</phone>
|
||||
<email>fulvio.risso@polito.it</email>
|
||||
<uri>http://netgroup.polito.it/fulvio.risso/</uri>
|
||||
</address>
|
||||
</author>
|
||||
|
||||
<!-- Other authors go here -->
|
||||
|
||||
<date month="March" year="2004"/>
|
||||
<area>General</area>
|
||||
<!--
|
||||
<workgroup>
|
||||
-->
|
||||
<keyword>Internet-Draft</keyword>
|
||||
<keyword>Libpcap, dump file format</keyword>
|
||||
<abstract>
|
||||
<t>This document describes a format to dump captured packets on a file. This format is extensible and it is currently proposed for implementation in the libpcap/WinPcap packet capture library.</t>
|
||||
</abstract>
|
||||
<!--
|
||||
<note ...>
|
||||
-->
|
||||
</front>
|
||||
<middle>
|
||||
|
||||
<section title="Objectives">
|
||||
<t>The problem of exchanging packet traces becomes more and more critical every day; unfortunately, no standard solutions exist for this task right now. One of the most accepted packet interchange formats is the one defined by libpcap, which is rather old and does not fit for some of the nowadays applications especially in terms of extensibility.</t>
|
||||
<t>This document proposes a new format for dumping packet traces. The following goals are being pursued:</t>
|
||||
<list style="symbols">
|
||||
<t>Extensibility: aside of some common functionalities, third parties should be able to enrich the information embedded in the file with proprietary extensions, which will be ignored by tools that are not able to understand them.</t>
|
||||
<t>Portability: a capture trace must contain all the information needed to read data independently from network, hardware and operating system of the machine that made the capture.</t>
|
||||
<t>Merge/Append data: it should be possible to add data at the end of a given file, and the resulting file must still be readable.</t>
|
||||
</list>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section title="General File Structure">
|
||||
|
||||
<section anchor="sectionblock" title="General Block Structure">
|
||||
<t>A capture file is organized in blocks, that are appended one to another to form the file. All the blocks share a common format, which is shown in <xref target="formatblock"/>.</t>
|
||||
|
||||
<figure anchor="formatblock" title="Basic block structure.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Type |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Total Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ Block Body /
|
||||
/ /* variable length, aligned to 32 bits */ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Block Total Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The fields have the following meaning:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>Block Type (32 bits): unique value that identifies the block. Values whose Most Significant Bit (MSB) is equal to 1 are reserved for local use. They allow to save private data to the file and to extend the file format.</t>
|
||||
<t>Block Total Length: total size of this block, in bytes. For instance, a block that does not have a body has a length of 12 bytes.</t>
|
||||
<t>Block Body: content of the block.</t>
|
||||
<t>Block Total Length: total size of this block, in bytes. This field is duplicated for permitting backward file navigation.</t>
|
||||
</list>
|
||||
|
||||
<t>This structure, shared among all blocks, makes easy to process a file and to skip unneeded or unknown blocks. Blocks can be nested one inside the others (NOTE: needed?). Some of the blocks are mandatory, i.e. a dump file is not valid if they are not present, other are optional.</t>
|
||||
<t>The structure of the blocks allows to define other blocks if needed. A parser that does non understand them can simply ignore their content.</t>
|
||||
</section>
|
||||
|
||||
<section title="Block Types">
|
||||
<t>The currently defined blocks are the following:</t>
|
||||
<list style="numbers">
|
||||
<t>Section Header Block: it defines the most important characteristics of the capture file.</t>
|
||||
<t>Interface Description Block: it defines the most important characteristics of the interface(s) used for capturing traffic.</t>
|
||||
<t>Packet Block: it contains a single captured packet, or a portion of it.</t>
|
||||
<t>Simple Packet Block: it contains a single captured packet, or a portion of it, with only a minimal set of information about it.</t>
|
||||
<t>Name Resolution Block: it defines the mapping from numeric addresses present in the packet dump and the canonical name counterpart.</t>
|
||||
<t>Capture Statistics Block: it defines how to store some statistical data (e.g. packet dropped, etc) which can be useful to undestand the conditions in which the capture has been made.</t>
|
||||
<t>Compression Marker Block: TODO</t>
|
||||
<t>Encryption Marker Block: TODO</t>
|
||||
<t>Fixed Length Marker Block: TODO</t>
|
||||
</list>
|
||||
|
||||
<t>The following blocks instead are considered interesting but the authors believe that they deserve more in-depth discussion before being defined:</t>
|
||||
<list style="numbers">
|
||||
<t>Further Packet Blocks</t>
|
||||
<t>Directory Block</t>
|
||||
<t>Traffic Statistics and Monitoring Blocks</t>
|
||||
<t>Alert and Security Blocks</t>
|
||||
</list>
|
||||
|
||||
<t>TODO Currently standardized Block Type codes are specified in Appendix 1.</t>
|
||||
|
||||
</section>
|
||||
|
||||
<section title="Block Hierarchy and Precedence">
|
||||
<t>The file must begin with a Section Header Block. However, more than one Section Header Block can be present on the dump, each one covering the data following it till the next one (or the end of file). A Section includes the data delimited by two Section Header Blocks (or by a Section Header Block and the end of the file), including the first Section Header Block.</t>
|
||||
<t>In case an application cannot read a Section because of different version number, it must skip everything until the next Section Header Block. Note that, in order to properly skip the blocks until the next section, all blocks must have the fields Type and Length at the beginning. This is a mandatory requirement that must be maintained in future versions of the block format.</t>
|
||||
<t><xref target="fssample-SHB"/> shows two valid files: the first has a typical configuration, with a single Section Header that covers the whole file. The second one contains three headers, and is normally the result of file concatenation. An application that understands only version 1.0 of the file format skips the intermediate section and restart processing the packets after the third Section Header.</t>
|
||||
|
||||
<figure anchor="fssample-SHB" title="File structure example: the Section Header Block.">
|
||||
<artwork>
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SHB v1.0 | Data |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Typical configuration with a single Section Header Block
|
||||
|
||||
|
||||
|-- 1st Section --|-- 2nd Section --|-- 3rd Section --|
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SHB v1.0 | Data | SHB V1.1 | Data | SHB V1.0 | Data |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Configuration with three different Section Header Blocks
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>NOTE: TO BE COMPLETED with some examples of other blocks</t>
|
||||
|
||||
</section>
|
||||
|
||||
<section title="Data format">
|
||||
<t>Data contained in each section will always be saved according to the characteristics (little endian / big endian) of the dumping machine. This refers to all fields that are saved as numbers and that span over two or more bytes.</t>
|
||||
<t>The approach of having each section saved in the native format of the generating host is more efficient because it avoids translation of data when reading / writing on the host itself, which is the most common case when generating/processing capture dumps.</t>
|
||||
<t>TODO Probably we have to specify something more here. Is what we're saying enough to avoid any kind of ambiguity?.</t>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section title="Block Definition">
|
||||
<t>This section details the format of the body of the blocks currently defined.</t>
|
||||
|
||||
<section anchor="sectionshb" title="Section Header Block (mandatory)">
|
||||
<t>The Section Header Block is mandatory. It identifies the beginning of a section of the capture dump file. Its format is shown in <xref target="formatSHB"/>.</t>
|
||||
<figure anchor="formatSHB" title="Section Header Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Magic |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Major | Minor |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The meaning of the fields is:</t>
|
||||
<list style="symbols">
|
||||
<t>Magic: magic number, whose value is the hexadecimal number 0x1A2B3C4D. This number can be used to distinguish section that have been saved on little-endian machines from the one saved on big-endian machines.</t>
|
||||
<t>Major: number of the current mayor version of the format. Current value is 1.</t>
|
||||
<t>Minor: number of the current minor version of the format. Current value is 0.</t>
|
||||
<t>Options: optionally, a list of options (formatted according to the rules defined in <xref target="sectionopt"/>) can be present.</t>
|
||||
</list>
|
||||
|
||||
<t>Aside form the options defined in <xref target="sectionopt"/>, the following options are valid within this block:</t>
|
||||
|
||||
<texttable anchor="InterfaceOptions1">
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>Hardware</c>
|
||||
<c>2</c>
|
||||
<c>variable</c>
|
||||
<c>An ascii string containing the description of the hardware used to create this section.</c>
|
||||
|
||||
<c>Operating System</c>
|
||||
<c>3</c>
|
||||
<c>variable</c>
|
||||
<c>An ascii string containing the name of the operating system used to create this section.</c>
|
||||
|
||||
<c>User Application</c>
|
||||
<c>3</c>
|
||||
<c>variable</c>
|
||||
<c>An ascii string containing the name of the application used to create this section.</c>
|
||||
</texttable>
|
||||
|
||||
|
||||
<t>The Section Header Block does not contain data but it rather identifies a list of blocks (interfaces, packets) that are logically correlated. This block does not contain any reference to the size of the section it is currently delimiting, therefore the reader cannot skip a whole section at once. In case a section must be skipped, the user has to repeatedly skip all the blocks contained within it; this makes the parsing of the file slower but it permits to append several capture dumps at the same file.</t>
|
||||
</section>
|
||||
|
||||
<section anchor="sectionidb" title="Interface Description Block (mandatory)">
|
||||
<t>The Interface Description Block is mandatory. This block is needed to specify the characteristics of the network interface on which the capture has been made. In order to properly associate the captured data to the corresponding interface, the Interface Description Block must be defined before any other block that uses it; therefore, this block is usually placed immediately after the Section Header Block.</t>
|
||||
|
||||
<t>An Interface Description Block is valid only inside the section which it belongs to. The structure of a Interface Description Block is shown in <xref target="formatidb"/>.</t>
|
||||
|
||||
<figure anchor="formatidb" title="Interface Description Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | LinkType |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| SnapLen |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The meaning of the fields is:</t>
|
||||
<list style="symbols">
|
||||
<t>Interface ID: a progressive number that identifies uniquely any interface inside current section. Two Interface Description Blocks can have the same Interface ID only if they are in different sections of the file. The Interface ID is referenced by the packet blocks.</t>
|
||||
<t>LinkType: a value that defines the link layer type of this interface.</t>
|
||||
<t>SnapLen: maximum number of bytes dumped from each packet. The portion of each packet that exceeds this value will not be stored in the file.</t>
|
||||
<t>Options: optionally, a list of options (formatted according to the rules defined in <xref target="sectionopt"/>) can be present.</t>
|
||||
</list>
|
||||
|
||||
<t>In addition to the options defined in <xref target="sectionopt"/>, the following options are valid within this block:</t>
|
||||
|
||||
<texttable anchor="InterfaceOptions2">
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>if_name</c>
|
||||
<c>2</c>
|
||||
<c>Variable</c>
|
||||
<c>Name of the device used to capture data.</c>
|
||||
|
||||
<c>if_IPv4addr</c>
|
||||
<c>3</c>
|
||||
<c>8</c>
|
||||
<c>Interface network address and netmask.</c>
|
||||
|
||||
<c>if_IPv6addr</c>
|
||||
<c>4</c>
|
||||
<c>17</c>
|
||||
<c>Interface network address and prefix length (stored in the last byte).</c>
|
||||
|
||||
<c>if_MACaddr</c>
|
||||
<c>5</c>
|
||||
<c>6</c>
|
||||
<c>Interface Hardware MAC address (48 bits).</c>
|
||||
|
||||
<c>if_EUIaddr</c>
|
||||
<c>6</c>
|
||||
<c>8</c>
|
||||
<c>Interface Hardware EUI address (64 bits), if available.</c>
|
||||
|
||||
<c>if_speed</c>
|
||||
<c>7</c>
|
||||
<c>8</c>
|
||||
<c>Interface speed (in bps).</c>
|
||||
|
||||
<c>if_tsaccur</c>
|
||||
<c>8</c>
|
||||
<c>1</c>
|
||||
<c>Precision of timestamps. If the Most Significant Bit is equal to zero, the remaining bits indicates the accuracy as as a negative power of 10 (e.g. 6 means microsecond accuracy). If the Most Significant Bit is equal to zero, the remaining bits indicates the accuracy as as negative power of 2 (e.g. 10 means 1/1024 of second). If this option is not present, a precision of 10^-6 is assumed.</c>
|
||||
|
||||
<c>if_tzone</c>
|
||||
<c>9</c>
|
||||
<c>4</c>
|
||||
<c>Time zone for GMT support (TODO: specify better).</c>
|
||||
|
||||
<c>if_flags</c>
|
||||
<c>10</c>
|
||||
<c>4</c>
|
||||
<c>Interface flags. (TODO: specify better. Possible flags: promiscuous, inbound/outbound, traffic filtered during capture).</c>
|
||||
|
||||
<c>if_filter</c>
|
||||
<c>11</c>
|
||||
<c>variable</c>
|
||||
<c>The filter (e.g. "capture only TCP traffic") used to capture traffic. The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more). More details about this format will be presented in Appendix XXX (TODO).</c>
|
||||
|
||||
<c>if_opersystem</c>
|
||||
<c>12</c>
|
||||
<c>variable</c>
|
||||
<c>An ascii string containing the name of the operating system of the machine that hosts this interface. This can be different from the same information that can be contained by the Section Header Block (<xref target="sectionshb"/>) because the capture can have been done on a remote machine.</c>
|
||||
|
||||
</texttable>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section anchor="sectionpb" title="Packet Block (optional)">
|
||||
<t>A Packet Block is the standard container for storing the packets coming from the network. The Packet Block is optional because packets can be stored either by means of this block or the Simple Packet Block, which can be used to speed up dump generation. The format of a packet block is shown in <xref target="formatpb"/>.</t>
|
||||
|
||||
<figure anchor="formatpb" title="Packet Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | Drops Count |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Timestamp (High) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Timestamp (Low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Captured Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Packet Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
| Packet Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The Packet Block has the following fields:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>Interface ID: Specifies the interface this packet comes from, and corresponds to the ID of one of the Interface Description Blocks present in this section of the file (see <xref target="formatidb"/>).</t>
|
||||
<t>Drops Count: a local drop counter. It specified the number of packets lost (by the interface and the operating system) between this packet and the preceding one. The value xFFFF (in hexadecimal) is reserved for those systems in which this information is not available.</t>
|
||||
<t>Timestamp (High): the most significative part of the timestamp. in standard Unix format, i.e. from 1/1/1970.</t>
|
||||
<t>Timestamp (Low): the less significative part of the timestamp. The way to interpret this field is specified by the 'ts_accur' option (see <xref target="formatidb"/>) of the Interface Description block referenced by this packet. If the Interface Description block does not contain a 'ts_accur' option, then this field is expressed in microseconds.</t>
|
||||
<t>Captured Len: number of bytes captured from the packet (i.e. the length of the Packet Data field). It will be the minimum value among the actual Packet Length and the snapshot length (defined in <xref target="formatidb"/>).</t>
|
||||
<t>Packet Len: actual length of the packet when it was transmitted on the network. Can be different from Captured Len if the user wants only a snapshot of the packet.</t>
|
||||
<t>Packet Data: the data coming from the network, including link-layer headers. The length of this field is Captured Len. The format of the link-layer headers depends on the LinkType field specified in the Interface Description Block (see <xref target="sectionidb"/>) and it is specified in Appendix XXX (TODO).</t>
|
||||
<t>Options: optionally, a list of options (formatted according to the rules defined in <xref target="sectionopt"/>) can be present.</t>
|
||||
</list>
|
||||
|
||||
<t></t>
|
||||
</section>
|
||||
|
||||
|
||||
<section title="Simple Packet Block (optional)">
|
||||
<t>The Simple Packet Block is a lightweight container for storing the packets coming from the network. Its presence is optional.</t>
|
||||
<t>A Simple Packet Block is similar to a Packet Block (see <xref target="sectionpb"/>), but it is smaller, simpler to process and contains only a minimal set of information. This block is preferred to the standard Packet Block when performance or space occupation are critical factors, such as in sustained traffic dump applications. A capture file can contain both Packet Blocks and Simple Packet Blocks: for example, a capture tool could switch from Packet Blocks to Simple Packet Blocks when the hardware resources become critical.</t>
|
||||
<t>The Simple Packet Block does not contain the Interface ID field. Therefore, it must be assumed that all the Simple Packet Blocks have been captured on the interface previously specified in the Interface Description Block.</t>
|
||||
<t><xref target="formatpbs"/> shows the format of the Simple Packet Block.</t>
|
||||
|
||||
<figure anchor="formatpbs" title="Simple Packet Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Packet Len |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
| Packet Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The Packet Block has the following fields:</t>
|
||||
<list style="symbols">
|
||||
<t>Packet Len: actual length of the packet when it was transmitted on the network. Can be different from captured len if the packet has been truncated.</t>
|
||||
<t>Packet data: the data coming from the network, including link-layers headers. The length of this field can be derived from the field Block Total Length, present in the Block Header.</t>
|
||||
</list>
|
||||
|
||||
<t>The Simple Packet Block does not contain the timestamp because this is one of the most costly operations on PCs. Additionally, there are applications that do not require it; e.g. an Intrusion Detection System is interested in packets, not in their timestamp.</t>
|
||||
|
||||
<t>The Simple Packet Block is very efficient in term of disk space: a snapshot of length 100 bytes requires only 16 bytes of overhead, which corresponds to an efficiency of more than 86%.</t>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section title="Name Resolution Block (optional)">
|
||||
<t>The Name Resolution Block is used to support the correlation of numeric addresses (present in the captured packets) and their corresponding canonical names and it is optional. Having the literal names saved in the file, this prevents the need of a name resolution in a delayed time, when the association between names and addresses can be different from the one in use at capture time. Moreover, The Name Resolution Block avoids the need of issuing a lot of DNS requests every time the trace capture is opened, and allows to have name resolution also when reading the capture with a machine not connected to the network.</t>
|
||||
<t>The format of the Name Resolution Block is shown in <xref target="formatnrb"/>.</t>
|
||||
|
||||
<figure anchor="formatnrb" title="Name Resolution Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Record Type | Record Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Record Value |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
| | | | |
|
||||
+-+-+-+-+-+-+-+-+ + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
. . . other records . . .
|
||||
| Record Type == end_of_recs | Record Length == 00 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>A Name Resolution Block is a zero-terminated list of records (in the TLV format), each of which contains an association between a network address and a name. There are three possible types of records:</t>
|
||||
|
||||
<texttable anchor="nrrecords">
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>end_of_recs</c>
|
||||
<c>0</c>
|
||||
<c>0</c>
|
||||
<c>End of records</c>
|
||||
|
||||
<c>ip4_rec</c>
|
||||
<c>1</c>
|
||||
<c>Variable</c>
|
||||
<c>Specifies an IPv4 address (contained in the first 4 bytes), followed by one or more zero-terminated strings containing the DNS entries for that address.</c>
|
||||
|
||||
<c>ip6_rec</c>
|
||||
<c>1</c>
|
||||
<c>Variable</c>
|
||||
<c>Specifies an IPv6 address (contained in the first 16 bytes), followed by one or more zero-terminated strings containing the DNS entries for that address.</c>
|
||||
</texttable>
|
||||
|
||||
<t>After the list or Name Resolution Records, optionally, a list of options (formatted according to the rules defined in <xref target="sectionopt"/>) can be present.</t>
|
||||
|
||||
<t>A Name Resolution Block is normally placed at the beginning of the file, but no assumptions can be taken about its position. Name Resolution Blocks can be added in a second time by tools that process the file, like network analyzers.</t>
|
||||
|
||||
<t>In addiction to the options defined in <xref target="sectionopt"/>, the following options are valid within this block:</t>
|
||||
|
||||
<texttable>
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>ns_dnsname</c>
|
||||
<c>2</c>
|
||||
<c>Variable</c>
|
||||
<c>An ascii string containing the name of the machine (DNS server) used to perform the name resolution.</c>
|
||||
</texttable>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section title="Interface Statistics Block (optional)">
|
||||
<t>The Interface Statistics Block contains the capture statistics for a given interface and it is optional. The statistics are referred to the interface defined in the current Section identified by the Interface ID field.</t>
|
||||
<t>The format of the Interface Statistics Block is shown in <xref target="formatisb"/>.</t>
|
||||
|
||||
<figure anchor="formatisb" title="Interface Statistics Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| IfRecv |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| IfDrop |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| FilterAccept |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| OSDrop |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| UsrDelivered |
|
||||
| (high + low) |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Interface ID | Reserved |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ Options (variable) /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The fields have the following meaning:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>IfRecv: number of packets received from the interface during the capture. This number is reported as a 64 bits value, in which the most significat bits are located in the first four bytes of the field.</t>
|
||||
<t>IfDrop: number of packets dropped by the interface during the capture due to lack of resources.</t>
|
||||
<t>FilterAccept: number of packets accepeted by filter during current capture.</t>
|
||||
<t>OSDrop: number of packets dropped by the operating system during the capture.</t>
|
||||
<t>UsrDelivered: number of packets delivered to the user. UsrDelivered can be different from the value 'FilterAccept - OSDropped' because some packets could still lay in the OS buffers when the capture ended.</t>
|
||||
<t>Interface ID: reference to an Interface Description Block.</t>
|
||||
<t>Reserved: Reserved to future use.</t>
|
||||
<t>Options: optionally, a list of options (formatted according to the rules defined in <xref target="sectionopt"/>) can be present.</t>
|
||||
</list>
|
||||
|
||||
<t>In addiction to the options defined in <xref target="sectionopt"/>, the following options are valid within this block:</t>
|
||||
|
||||
<texttable>
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>isb_starttime</c>
|
||||
<c>2</c>
|
||||
<c>8</c>
|
||||
<c>Time in which the capture started; time will be stored in two blocks of four bytes each, containing the timestamp in seconds and nanoseconds.</c>
|
||||
|
||||
<c>isb_endtime</c>
|
||||
<c>3</c>
|
||||
<c>8</c>
|
||||
<c>Time in which the capture started; time will be stored in two blocks of four bytes each, containing the timestamp in seconds and nanoseconds.</c>
|
||||
</texttable>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section anchor="sectionopt" title="Options">
|
||||
<t>Almost all blocks have the possibility to embed optional fields. Optional fields can be used to insert some information that may be useful when reading data, but that it is not really needed for packet processing. Therefore, each tool can be either read the content of the optional fields (if any), or skip them at once.</t>
|
||||
<t>Skipping all the optional fields at once is straightforward because most of the blocks have a fixed length, therefore the field Block Length (present in the General Block Structure, see <xref target="sectionblock"/>) can be used to skip everything till the next block.</t>
|
||||
|
||||
<t>Options are a list of Type - Length - Value fields, each one containing a single value:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>Option Type (2 bytes): it contains the code that specifies the type of the current TLV record. Option types whose Most Significant Bit is equal to one are reserved for local use; therefore, there is no guarantee that the code used is unique among all capture files (generated by other applications). In case of vendor-specific extensions that have to be identified uniquely, vendors must request an Option Code whose MSB is equal to zero.</t>
|
||||
<t>Option Length (2 bytes): it contains the length of the following 'Option Value' field.</t>
|
||||
<t>Option Value (variable length): it contains the value of the given option. The length of this field as been specified by the Option Length field.</t>
|
||||
</list>
|
||||
|
||||
<t>Options may be repeated several times (e.g. an interface that has several IP addresses associated to it). The option list is terminated by a special code which is the 'End of Option'.</t>
|
||||
|
||||
<t>The format of the optional fields is shown in <xref target="formatopt"/>.</t>
|
||||
|
||||
<figure anchor="formatopt" title="Options format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Code | Option Length |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Value |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
| / / / |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ . . . other options . . . /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Option Code == opt_endofopt | Option Length == 0 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The following codes can always be present in any optional field:</t>
|
||||
|
||||
<texttable>
|
||||
<ttcol>Name</ttcol>
|
||||
<ttcol>Code</ttcol>
|
||||
<ttcol>Length</ttcol>
|
||||
<ttcol>Description</ttcol>
|
||||
|
||||
<c>opt_endofopt</c>
|
||||
<c>0</c>
|
||||
<c>0</c>
|
||||
<c>End of options: it is used to delimit the end of the optional fields. This block cannot be repeated within a given list of options.</c>
|
||||
|
||||
<c>opt_comment</c>
|
||||
<c>1</c>
|
||||
<c>variable</c>
|
||||
<c>Comment: it is an ascii string containing a comment that is associated to the current block.</c>
|
||||
</texttable>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section title="Experimental Blocks (deserved to a further investigation)">
|
||||
|
||||
<section title="Other Packet Blocks (experimental)">
|
||||
<t>Can some other packet blocks (besides the two described in the previous paragraphs) be useful?</t>
|
||||
</section>
|
||||
|
||||
<section title="Compression Block (experimental)">
|
||||
<t>The Compression Block is optional. A file can contain an arbitrary number of these blocks. A Compression Block, as the name says, is used to store compressed data. Its format is shown in <xref target="formatcb"/>.</t>
|
||||
|
||||
<figure anchor="formatcb" title="Compression Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Compr. Type | |
|
||||
+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Compressed Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The fields have the following meaning:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>Compression Type: specifies the compression algorithm. Possible values for this field are 0 (uncompressed), 1 (Lempel Ziv), 2 (Gzip), other?? Probably some kind of dumb and fast compression algorithm could be effective with some types of traffic (for example web), but which?</t>
|
||||
<t>Compressed Data: data of this block. Once decompressed, it is made of other blocks.</t>
|
||||
</list>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section title="Encryption Block (experimental)">
|
||||
<t>The Encryption Block is optional. A file can contain an arbitrary number of these blocks. An Encryption Block is used to sotre encrypted data. Its format is shown in <xref target="formateb"/>.</t>
|
||||
|
||||
<figure anchor="formateb" title="Encryption Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Encr. Type | |
|
||||
+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Compressed Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The fields have the following meaning:</t>
|
||||
<list style="symbols">
|
||||
<t>Compression Type: specifies the encryption algorithm. Possible values for this field are ??? NOTE: this block should probably contain other fields, depending on the encryption algorithm. To be define precisely.</t>
|
||||
<t>Encrypted Data: data of this block. Once decripted, it consists of other blocks.</t>
|
||||
</list>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section title="Fixed Length Block (experimental)">
|
||||
<t>The Fixed Length Block is optional. A file can contain an arbitrary number of these blocks. A Fixed Length Block can be used to optimize the access to the file. Its format is shown in <xref target="formatflm"/>.
|
||||
A Fixed Length Block stores records with constant size. It contains a set of Blocks (normally Packet Blocks or Simple Packet Blocks), of wihich it specifies the size. Knowing this size a priori helps to scan the file and to load some portions of it without truncating a block, and is particularly useful with cell-based networks like ATM.</t>
|
||||
|
||||
<figure anchor="formatflm" title="Fixed Length Block format.">
|
||||
<artwork>
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Cell Size | |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
||||
| |
|
||||
| Fixed Size Data |
|
||||
| |
|
||||
| /* variable length, byte-aligned */ |
|
||||
| |
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
</artwork>
|
||||
</figure>
|
||||
|
||||
<t>The fields have the following meaning:</t>
|
||||
<list style="symbols">
|
||||
<t>Cell size: the size of the blocks contained in the data field.</t>
|
||||
<t>Fixed Size Data: data of this block.</t>
|
||||
</list>
|
||||
|
||||
</section>
|
||||
|
||||
<section title="Directory Block (experimental)">
|
||||
<t>If present, this block contains the following information:</t>
|
||||
<list style="symbols">
|
||||
<t>number of indexed packets (N)</t>
|
||||
<t>table with position and length of any indexed packet (N entries)</t>
|
||||
</list>
|
||||
|
||||
<t>A directory block must be followed by at least N packets, otherwise it must be considered invalid. It can be used to efficiently load portions of the file to memory and to support operations on memory mapped files. This block can be added by tools like network analyzers as a consequence of file processing.</t>
|
||||
</section>
|
||||
|
||||
<section title="Traffic Statistics and Monitoring Blocks (experimental)">
|
||||
<t>One or more blocks could be defined to contain network statistics or traffic monitoring information. They could be use to store data collected from RMON or Netflow probes, or from other network monitoring tools.</t>
|
||||
</section>
|
||||
|
||||
<section title="Event/Security Block (experimental)">
|
||||
<t>This block could be used to store events. Events could contain generic information (for example network load over 50%, server down...) or security alerts. An event could be:</t>
|
||||
|
||||
<list style="symbols">
|
||||
<t>skipped, if the application doesn't know how to do with it</t>
|
||||
<t>processed independently by the packets. In other words, the applications skips the packets and processes only the alerts</t>
|
||||
<t>processed in relation to packets: for example, a security tool could load only the packets of the file that are near a security alert; a monitorg tool could skip the packets captured while the server was down.</t>
|
||||
</list>
|
||||
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section title="Conclusions">
|
||||
<t>The file format proposed in this document should be very versatile and satisfy a wide range of applications.
|
||||
In the simplest case, it can contain a raw dump of the network data, made of a series of Simple Packet Blocks.
|
||||
In the most complex case, it can be used as a repository for heterogeneous information.
|
||||
In every case, the file remains easy to parse and an application can always skip the data it is not interested in; at the same time, different applications can share the file, and each of them can benfit of the information produced by the others.
|
||||
Two or more files can be concatenated obtaining another valid file.</t>
|
||||
</section>
|
||||
|
||||
|
||||
<section title="Most important open issues">
|
||||
<list style="symbols">
|
||||
<t>Data, in the file, must be byte or word aligned? Currently, the structure of this document is not consistent with respect to this point.</t>
|
||||
</list>
|
||||
</section>
|
||||
|
||||
</middle>
|
||||
|
||||
</rfc>
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/etherent.c,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)";
|
||||
#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,119 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/ethertype.h,v 1.1.1.1 2006/02/27 15:45:44 drochner 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_MPLS
|
||||
#define ETHERTYPE_MPLS 0x8847
|
||||
#endif
|
||||
#ifndef ETHERTYPE_MPLS_MULTI
|
||||
#define ETHERTYPE_MPLS_MULTI 0x8848
|
||||
#endif
|
||||
#ifndef ETHERTYPE_PPPOED
|
||||
#define ETHERTYPE_PPPOED 0x8863
|
||||
#endif
|
||||
#ifndef ETHERTYPE_PPPOES
|
||||
#define ETHERTYPE_PPPOES 0x8864
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LOOPBACK
|
||||
#define ETHERTYPE_LOOPBACK 0x9000
|
||||
#endif
|
|
@ -1,284 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/fad-getad.c,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)";
|
||||
#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 <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifdef AF_PACKET
|
||||
# include <linux/if_packet.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
|
||||
|
||||
#ifdef AF_PACKET
|
||||
case AF_PACKET:
|
||||
return (sizeof (struct sockaddr_ll));
|
||||
#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;
|
||||
char *p, *q;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this entry has a colon followed by a number at
|
||||
* the end, we assume it's a logical interface. Those
|
||||
* are just the way you assign multiple IP addresses to
|
||||
* a real interface on Linux, so an entry for a logical
|
||||
* interface should be treated like the entry for the
|
||||
* real interface; we do that by stripping off the ":"
|
||||
* and the number.
|
||||
*
|
||||
* XXX - should we do this only on Linux?
|
||||
*/
|
||||
p = strchr(ifa->ifa_name, ':');
|
||||
if (p != NULL) {
|
||||
/*
|
||||
* We have a ":"; is it followed by a number?
|
||||
*/
|
||||
q = p + 1;
|
||||
while (isdigit((unsigned char)*q))
|
||||
q++;
|
||||
if (*q == '\0') {
|
||||
/*
|
||||
* All digits after the ":" until the end.
|
||||
* Strip off the ":" and everything after
|
||||
* it.
|
||||
*/
|
||||
*p = '\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);
|
||||
}
|
|
@ -1,578 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/fad-gifc.c,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#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>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.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).
|
||||
*
|
||||
* We assume that a UNIX that doesn't have "getifaddrs()" and doesn't have
|
||||
* SIOCGLIFCONF, but has SIOCGIFCONF, uses "struct sockaddr" for the
|
||||
* address in an entry returned by SIOCGIFCONF.
|
||||
*/
|
||||
#ifndef SA_LEN
|
||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||
#define SA_LEN(addr) ((addr)->sa_len)
|
||||
#else /* HAVE_SOCKADDR_SA_LEN */
|
||||
#define SA_LEN(addr) (sizeof (struct sockaddr))
|
||||
#endif /* HAVE_SOCKADDR_SA_LEN */
|
||||
#endif /* SA_LEN */
|
||||
|
||||
/*
|
||||
* This is also fun.
|
||||
*
|
||||
* There is no ioctl that returns the amount of space required for all
|
||||
* the data that SIOCGIFCONF could return, and if a buffer is supplied
|
||||
* that's not large enough for all the data SIOCGIFCONF could return,
|
||||
* on at least some platforms it just returns the data that'd fit with
|
||||
* no indication that there wasn't enough room for all the data, much
|
||||
* less an indication of how much more room is required.
|
||||
*
|
||||
* The only way to ensure that we got all the data is to pass a buffer
|
||||
* large enough that the amount of space in the buffer *not* filled in
|
||||
* is greater than the largest possible entry.
|
||||
*
|
||||
* We assume that's "sizeof(ifreq.ifr_name)" plus 255, under the assumption
|
||||
* that no address is more than 255 bytes (on systems where the "sa_len"
|
||||
* field in a "struct sockaddr" is 1 byte, e.g. newer BSDs, that's the
|
||||
* case, and addresses are unlikely to be bigger than that in any case).
|
||||
*/
|
||||
#define MAX_SA_LEN 255
|
||||
|
||||
#ifdef HAVE_PROC_NET_DEV
|
||||
/*
|
||||
* Get from "/proc/net/dev" all interfaces listed there; if they're
|
||||
* already in the list of interfaces we have, that won't add another
|
||||
* instance, but if they're not, that'll add them.
|
||||
*
|
||||
* We don't bother getting any addresses for them; it appears you can't
|
||||
* use SIOCGIFADDR on Linux to get IPv6 addresses for interfaces, and,
|
||||
* although some other types of addresses can be fetched with SIOCGIFADDR,
|
||||
* we don't bother with them for now.
|
||||
*
|
||||
* We also don't fail if we couldn't open "/proc/net/dev"; we just leave
|
||||
* the list of interfaces as is.
|
||||
*/
|
||||
static int
|
||||
scan_proc_net_dev(pcap_if_t **devlistp, int fd, char *errbuf)
|
||||
{
|
||||
FILE *proc_net_f;
|
||||
char linebuf[512];
|
||||
int linenum;
|
||||
unsigned char *p;
|
||||
char name[512]; /* XXX - pick a size */
|
||||
char *q, *saveq;
|
||||
struct ifreq ifrflags;
|
||||
int ret = 0;
|
||||
|
||||
proc_net_f = fopen("/proc/net/dev", "r");
|
||||
if (proc_net_f == NULL)
|
||||
return (0);
|
||||
|
||||
for (linenum = 1;
|
||||
fgets(linebuf, sizeof linebuf, proc_net_f) != NULL; linenum++) {
|
||||
/*
|
||||
* Skip the first two lines - they're headers.
|
||||
*/
|
||||
if (linenum <= 2)
|
||||
continue;
|
||||
|
||||
p = &linebuf[0];
|
||||
|
||||
/*
|
||||
* Skip leading white space.
|
||||
*/
|
||||
while (*p != '\0' && isspace(*p))
|
||||
p++;
|
||||
if (*p == '\0' || *p == '\n')
|
||||
continue; /* blank line */
|
||||
|
||||
/*
|
||||
* Get the interface name.
|
||||
*/
|
||||
q = &name[0];
|
||||
while (*p != '\0' && !isspace(*p)) {
|
||||
if (*p == ':') {
|
||||
/*
|
||||
* This could be the separator between a
|
||||
* name and an alias number, or it could be
|
||||
* the separator between a name with no
|
||||
* alias number and the next field.
|
||||
*
|
||||
* If there's a colon after digits, it
|
||||
* separates the name and the alias number,
|
||||
* otherwise it separates the name and the
|
||||
* next field.
|
||||
*/
|
||||
saveq = q;
|
||||
while (isdigit(*p))
|
||||
*q++ = *p++;
|
||||
if (*p != ':') {
|
||||
/*
|
||||
* That was the next field,
|
||||
* not the alias number.
|
||||
*/
|
||||
q = saveq;
|
||||
}
|
||||
break;
|
||||
} else
|
||||
*q++ = *p++;
|
||||
}
|
||||
*q = '\0';
|
||||
|
||||
/*
|
||||
* Get the flags for this interface, and skip it if
|
||||
* it's not up.
|
||||
*/
|
||||
strncpy(ifrflags.ifr_name, name, sizeof(ifrflags.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifrflags) < 0) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFFLAGS: %.*s: %s",
|
||||
(int)sizeof(ifrflags.ifr_name),
|
||||
ifrflags.ifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (!(ifrflags.ifr_flags & IFF_UP))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Add an entry for this interface, with no addresses.
|
||||
*/
|
||||
if (pcap_add_if(devlistp, name, ifrflags.ifr_flags, NULL,
|
||||
errbuf) == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret != -1) {
|
||||
/*
|
||||
* Well, we didn't fail for any other reason; did we
|
||||
* fail due to an error reading the file?
|
||||
*/
|
||||
if (ferror(proc_net_f)) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Error reading /proc/net/dev: %s",
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
(void)fclose(proc_net_f);
|
||||
return (ret);
|
||||
}
|
||||
#endif /* HAVE_PROC_NET_DEV */
|
||||
|
||||
/*
|
||||
* 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 SIOCGIFCONF but
|
||||
* don't have any other mechanism for getting a list of interfaces.
|
||||
*
|
||||
* XXX - or platforms that have other, better mechanisms but for which
|
||||
* we don't yet have code to use that mechanism; I think there's a better
|
||||
* way on Linux, for example.
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
pcap_if_t *devlist = NULL;
|
||||
register int fd;
|
||||
register struct ifreq *ifrp, *ifend, *ifnext;
|
||||
int n;
|
||||
struct ifconf ifc;
|
||||
char *buf = NULL;
|
||||
unsigned buf_size;
|
||||
#if defined (HAVE_SOLARIS) || defined (HAVE_HPUX10_20_OR_LATER)
|
||||
char *p, *q;
|
||||
#endif
|
||||
struct ifreq ifrflags, ifrnetmask, ifrbroadaddr, ifrdstaddr;
|
||||
struct sockaddr *netmask, *broadaddr, *dstaddr;
|
||||
size_t netmask_size, broadaddr_size, dstaddr_size;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Create a socket from which to fetch the list of interfaces.
|
||||
*/
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"socket: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start with an 8K buffer, and keep growing the buffer until
|
||||
* we have more than "sizeof(ifrp->ifr_name) + MAX_SA_LEN"
|
||||
* bytes left over in the buffer or we fail to get the
|
||||
* interface list for some reason other than EINVAL (which is
|
||||
* presumed here to mean "buffer is too small").
|
||||
*/
|
||||
buf_size = 8192;
|
||||
for (;;) {
|
||||
buf = malloc(buf_size);
|
||||
if (buf == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
(void)close(fd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ifc.ifc_len = buf_size;
|
||||
ifc.ifc_buf = buf;
|
||||
memset(buf, 0, buf_size);
|
||||
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0
|
||||
&& errno != EINVAL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFCONF: %s", pcap_strerror(errno));
|
||||
(void)close(fd);
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
if (ifc.ifc_len < buf_size &&
|
||||
(buf_size - ifc.ifc_len) > sizeof(ifrp->ifr_name) + MAX_SA_LEN)
|
||||
break;
|
||||
free(buf);
|
||||
buf_size *= 2;
|
||||
}
|
||||
|
||||
ifrp = (struct ifreq *)buf;
|
||||
ifend = (struct ifreq *)(buf + ifc.ifc_len);
|
||||
|
||||
for (; ifrp < ifend; ifrp = ifnext) {
|
||||
/*
|
||||
* XXX - what if this isn't an IPv4 address? Can
|
||||
* we still get the netmask, etc. with ioctls on
|
||||
* an IPv4 socket?
|
||||
*
|
||||
* The answer is probably platform-dependent, and
|
||||
* if the answer is "no" on more than one platform,
|
||||
* the way you work around it is probably platform-
|
||||
* dependent as well.
|
||||
*/
|
||||
n = SA_LEN(&ifrp->ifr_addr) + sizeof(ifrp->ifr_name);
|
||||
if (n < sizeof(*ifrp))
|
||||
ifnext = ifrp + 1;
|
||||
else
|
||||
ifnext = (struct ifreq *)((char *)ifrp + n);
|
||||
|
||||
/*
|
||||
* XXX - The 32-bit compatibility layer for Linux on IA-64
|
||||
* is slightly broken. It correctly converts the structures
|
||||
* to and from kernel land from 64 bit to 32 bit but
|
||||
* doesn't update ifc.ifc_len, leaving it larger than the
|
||||
* amount really used. This means we read off the end
|
||||
* of the buffer and encounter an interface with an
|
||||
* "empty" name. Since this is highly unlikely to ever
|
||||
* occur in a valid case we can just finish looking for
|
||||
* interfaces if we see an empty name.
|
||||
*/
|
||||
if (!(*ifrp->ifr_name))
|
||||
break;
|
||||
|
||||
/*
|
||||
* Skip entries that begin with "dummy".
|
||||
* XXX - what are these? Is this Linux-specific?
|
||||
* Are there platforms on which we shouldn't do this?
|
||||
*/
|
||||
if (strncmp(ifrp->ifr_name, "dummy", 5) == 0)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Get the flags for this interface, and skip it if it's
|
||||
* not up.
|
||||
*/
|
||||
strncpy(ifrflags.ifr_name, ifrp->ifr_name,
|
||||
sizeof(ifrflags.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifrflags) < 0) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFFLAGS: %.*s: %s",
|
||||
(int)sizeof(ifrflags.ifr_name),
|
||||
ifrflags.ifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (!(ifrflags.ifr_flags & IFF_UP))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Get the netmask for this address on this interface.
|
||||
*/
|
||||
strncpy(ifrnetmask.ifr_name, ifrp->ifr_name,
|
||||
sizeof(ifrnetmask.ifr_name));
|
||||
memcpy(&ifrnetmask.ifr_addr, &ifrp->ifr_addr,
|
||||
sizeof(ifrnetmask.ifr_addr));
|
||||
if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifrnetmask) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
netmask = NULL;
|
||||
netmask_size = 0;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFNETMASK: %.*s: %s",
|
||||
(int)sizeof(ifrnetmask.ifr_name),
|
||||
ifrnetmask.ifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
netmask = &ifrnetmask.ifr_addr;
|
||||
netmask_size = SA_LEN(netmask);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the broadcast address for this address on this
|
||||
* interface (if any).
|
||||
*/
|
||||
if (ifrflags.ifr_flags & IFF_BROADCAST) {
|
||||
strncpy(ifrbroadaddr.ifr_name, ifrp->ifr_name,
|
||||
sizeof(ifrbroadaddr.ifr_name));
|
||||
memcpy(&ifrbroadaddr.ifr_addr, &ifrp->ifr_addr,
|
||||
sizeof(ifrbroadaddr.ifr_addr));
|
||||
if (ioctl(fd, SIOCGIFBRDADDR,
|
||||
(char *)&ifrbroadaddr) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
broadaddr = NULL;
|
||||
broadaddr_size = 0;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFBRDADDR: %.*s: %s",
|
||||
(int)sizeof(ifrbroadaddr.ifr_name),
|
||||
ifrbroadaddr.ifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
broadaddr = &ifrbroadaddr.ifr_broadaddr;
|
||||
broadaddr_size = SA_LEN(broadaddr);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Not a broadcast interface, so no broadcast
|
||||
* address.
|
||||
*/
|
||||
broadaddr = NULL;
|
||||
broadaddr_size = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the destination address for this address on this
|
||||
* interface (if any).
|
||||
*/
|
||||
if (ifrflags.ifr_flags & IFF_POINTOPOINT) {
|
||||
strncpy(ifrdstaddr.ifr_name, ifrp->ifr_name,
|
||||
sizeof(ifrdstaddr.ifr_name));
|
||||
memcpy(&ifrdstaddr.ifr_addr, &ifrp->ifr_addr,
|
||||
sizeof(ifrdstaddr.ifr_addr));
|
||||
if (ioctl(fd, SIOCGIFDSTADDR,
|
||||
(char *)&ifrdstaddr) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
dstaddr = NULL;
|
||||
dstaddr_size = 0;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGIFDSTADDR: %.*s: %s",
|
||||
(int)sizeof(ifrdstaddr.ifr_name),
|
||||
ifrdstaddr.ifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dstaddr = &ifrdstaddr.ifr_dstaddr;
|
||||
dstaddr_size = SA_LEN(dstaddr);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Not a point-to-point interface, so no destination
|
||||
* address.
|
||||
*/
|
||||
dstaddr = NULL;
|
||||
dstaddr_size = 0;
|
||||
}
|
||||
|
||||
#if defined (HAVE_SOLARIS) || defined (HAVE_HPUX10_20_OR_LATER)
|
||||
/*
|
||||
* If this entry has a colon followed by a number at
|
||||
* the end, it's a logical interface. Those are just
|
||||
* the way you assign multiple IP addresses to a real
|
||||
* interface, so an entry for a logical interface should
|
||||
* be treated like the entry for the real interface;
|
||||
* we do that by stripping off the ":" and the number.
|
||||
*/
|
||||
p = strchr(ifrp->ifr_name, ':');
|
||||
if (p != NULL) {
|
||||
/*
|
||||
* We have a ":"; is it followed by a number?
|
||||
*/
|
||||
q = p + 1;
|
||||
while (isdigit((unsigned char)*q))
|
||||
q++;
|
||||
if (*q == '\0') {
|
||||
/*
|
||||
* All digits after the ":" until the end.
|
||||
* Strip off the ":" and everything after
|
||||
* it.
|
||||
*/
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_iflist(&devlist, ifrp->ifr_name,
|
||||
ifrflags.ifr_flags, &ifrp->ifr_addr,
|
||||
SA_LEN(&ifrp->ifr_addr), netmask, netmask_size,
|
||||
broadaddr, broadaddr_size, dstaddr, dstaddr_size,
|
||||
errbuf) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
|
||||
#ifdef HAVE_PROC_NET_DEV
|
||||
if (ret != -1) {
|
||||
/*
|
||||
* We haven't had any errors yet; now read "/proc/net/dev",
|
||||
* and add to the list of interfaces all interfaces listed
|
||||
* there that we don't already have, because, on Linux,
|
||||
* SIOCGIFCONF reports only interfaces with IPv4 addresses,
|
||||
* so you need to read "/proc/net/dev" to get the names of
|
||||
* the rest of the interfaces.
|
||||
*/
|
||||
ret = scan_proc_net_dev(&devlist, fd, errbuf);
|
||||
}
|
||||
#endif
|
||||
(void)close(fd);
|
||||
|
||||
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);
|
||||
}
|
|
@ -1,386 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/fad-glifc.c,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#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>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 SIOCLGIFCONF
|
||||
* but don't have "getifaddrs()". (Solaris 8 and later; we use
|
||||
* SIOCLGIFCONF rather than SIOCGIFCONF in order to get IPv6 addresses.)
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
pcap_if_t *devlist = NULL;
|
||||
register int fd4, fd6, fd;
|
||||
register struct lifreq *ifrp, *ifend;
|
||||
struct lifnum ifn;
|
||||
struct lifconf ifc;
|
||||
char *buf = NULL;
|
||||
unsigned buf_size;
|
||||
#ifdef HAVE_SOLARIS
|
||||
char *p, *q;
|
||||
#endif
|
||||
struct lifreq ifrflags, ifrnetmask, ifrbroadaddr, ifrdstaddr;
|
||||
struct sockaddr *netmask, *broadaddr, *dstaddr;
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* Create a socket from which to fetch the list of interfaces,
|
||||
* and from which to fetch IPv4 information.
|
||||
*/
|
||||
fd4 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd4 < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"socket: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a socket from which to fetch IPv6 information.
|
||||
*/
|
||||
fd6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (fd6 < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"socket: %s", pcap_strerror(errno));
|
||||
(void)close(fd4);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* How many entries will SIOCGLIFCONF return?
|
||||
*/
|
||||
ifn.lifn_family = AF_UNSPEC;
|
||||
ifn.lifn_flags = 0;
|
||||
ifn.lifn_count = 0;
|
||||
if (ioctl(fd4, SIOCGLIFNUM, (char *)&ifn) < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFNUM: %s", pcap_strerror(errno));
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a buffer for those entries.
|
||||
*/
|
||||
buf_size = ifn.lifn_count * sizeof (struct lifreq);
|
||||
buf = malloc(buf_size);
|
||||
if (buf == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the entries.
|
||||
*/
|
||||
ifc.lifc_len = buf_size;
|
||||
ifc.lifc_buf = buf;
|
||||
ifc.lifc_family = AF_UNSPEC;
|
||||
ifc.lifc_flags = 0;
|
||||
memset(buf, 0, buf_size);
|
||||
if (ioctl(fd4, SIOCGLIFCONF, (char *)&ifc) < 0) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFCONF: %s", pcap_strerror(errno));
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the entries.
|
||||
*/
|
||||
ifrp = (struct lifreq *)buf;
|
||||
ifend = (struct lifreq *)(buf + ifc.lifc_len);
|
||||
|
||||
for (; ifrp < ifend; ifrp++) {
|
||||
/*
|
||||
* IPv6 or not?
|
||||
*/
|
||||
if (((struct sockaddr *)&ifrp->lifr_addr)->sa_family == AF_INET6)
|
||||
fd = fd6;
|
||||
else
|
||||
fd = fd4;
|
||||
|
||||
/*
|
||||
* Skip entries that begin with "dummy".
|
||||
* XXX - what are these? Is this Linux-specific?
|
||||
* Are there platforms on which we shouldn't do this?
|
||||
*/
|
||||
if (strncmp(ifrp->lifr_name, "dummy", 5) == 0)
|
||||
continue;
|
||||
|
||||
#ifdef HAVE_SOLARIS
|
||||
/*
|
||||
* Skip entries that have a ":" followed by a number
|
||||
* at the end - those are Solaris virtual interfaces
|
||||
* on which you can't capture.
|
||||
*/
|
||||
p = strchr(ifrp->lifr_name, ':');
|
||||
if (p != NULL) {
|
||||
/*
|
||||
* We have a ":"; is it followed by a number?
|
||||
*/
|
||||
while (isdigit((unsigned char)*p))
|
||||
p++;
|
||||
if (*p == '\0') {
|
||||
/*
|
||||
* All digits after the ":" until the end.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get the flags for this interface, and skip it if it's
|
||||
* not up.
|
||||
*/
|
||||
strncpy(ifrflags.lifr_name, ifrp->lifr_name,
|
||||
sizeof(ifrflags.lifr_name));
|
||||
if (ioctl(fd, SIOCGLIFFLAGS, (char *)&ifrflags) < 0) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFFLAGS: %.*s: %s",
|
||||
(int)sizeof(ifrflags.lifr_name),
|
||||
ifrflags.lifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (!(ifrflags.lifr_flags & IFF_UP))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Get the netmask for this address on this interface.
|
||||
*/
|
||||
strncpy(ifrnetmask.lifr_name, ifrp->lifr_name,
|
||||
sizeof(ifrnetmask.lifr_name));
|
||||
memcpy(&ifrnetmask.lifr_addr, &ifrp->lifr_addr,
|
||||
sizeof(ifrnetmask.lifr_addr));
|
||||
if (ioctl(fd, SIOCGLIFNETMASK, (char *)&ifrnetmask) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
netmask = NULL;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFNETMASK: %.*s: %s",
|
||||
(int)sizeof(ifrnetmask.lifr_name),
|
||||
ifrnetmask.lifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
netmask = (struct sockaddr *)&ifrnetmask.lifr_addr;
|
||||
|
||||
/*
|
||||
* Get the broadcast address for this address on this
|
||||
* interface (if any).
|
||||
*/
|
||||
if (ifrflags.lifr_flags & IFF_BROADCAST) {
|
||||
strncpy(ifrbroadaddr.lifr_name, ifrp->lifr_name,
|
||||
sizeof(ifrbroadaddr.lifr_name));
|
||||
memcpy(&ifrbroadaddr.lifr_addr, &ifrp->lifr_addr,
|
||||
sizeof(ifrbroadaddr.lifr_addr));
|
||||
if (ioctl(fd, SIOCGLIFBRDADDR,
|
||||
(char *)&ifrbroadaddr) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
broadaddr = NULL;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFBRDADDR: %.*s: %s",
|
||||
(int)sizeof(ifrbroadaddr.lifr_name),
|
||||
ifrbroadaddr.lifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
broadaddr = (struct sockaddr *)&ifrbroadaddr.lifr_broadaddr;
|
||||
} else {
|
||||
/*
|
||||
* Not a broadcast interface, so no broadcast
|
||||
* address.
|
||||
*/
|
||||
broadaddr = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the destination address for this address on this
|
||||
* interface (if any).
|
||||
*/
|
||||
if (ifrflags.lifr_flags & IFF_POINTOPOINT) {
|
||||
strncpy(ifrdstaddr.lifr_name, ifrp->lifr_name,
|
||||
sizeof(ifrdstaddr.lifr_name));
|
||||
memcpy(&ifrdstaddr.lifr_addr, &ifrp->lifr_addr,
|
||||
sizeof(ifrdstaddr.lifr_addr));
|
||||
if (ioctl(fd, SIOCGLIFDSTADDR,
|
||||
(char *)&ifrdstaddr) < 0) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
/*
|
||||
* Not available.
|
||||
*/
|
||||
dstaddr = NULL;
|
||||
} else {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"SIOCGLIFDSTADDR: %.*s: %s",
|
||||
(int)sizeof(ifrdstaddr.lifr_name),
|
||||
ifrdstaddr.lifr_name,
|
||||
pcap_strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
dstaddr = (struct sockaddr *)&ifrdstaddr.lifr_dstaddr;
|
||||
} else
|
||||
dstaddr = NULL;
|
||||
|
||||
#ifdef HAVE_SOLARIS
|
||||
/*
|
||||
* If this entry has a colon followed by a number at
|
||||
* the end, it's a logical interface. Those are just
|
||||
* the way you assign multiple IP addresses to a real
|
||||
* interface, so an entry for a logical interface should
|
||||
* be treated like the entry for the real interface;
|
||||
* we do that by stripping off the ":" and the number.
|
||||
*/
|
||||
p = strchr(ifrp->lifr_name, ':');
|
||||
if (p != NULL) {
|
||||
/*
|
||||
* We have a ":"; is it followed by a number?
|
||||
*/
|
||||
q = p + 1;
|
||||
while (isdigit((unsigned char)*q))
|
||||
q++;
|
||||
if (*q == '\0') {
|
||||
/*
|
||||
* All digits after the ":" until the end.
|
||||
* Strip off the ":" and everything after
|
||||
* it.
|
||||
*/
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_iflist(&devlist, ifrp->lifr_name,
|
||||
ifrflags.lifr_flags, (struct sockaddr *)&ifrp->lifr_addr,
|
||||
sizeof (struct sockaddr_storage),
|
||||
netmask, sizeof (struct sockaddr_storage),
|
||||
broadaddr, sizeof (struct sockaddr_storage),
|
||||
dstaddr, sizeof (struct sockaddr_storage), errbuf) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
|
||||
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);
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/fad-null.c,v 1.1.1.1 2006/02/27 15:45:44 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
/*
|
||||
* 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 no support for
|
||||
* packet capture.
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
/*
|
||||
* Succeed, but don't return any interfaces; we return only those
|
||||
* we can open, and we can't open any if there's no support
|
||||
* for packet capture.
|
||||
*/
|
||||
*alldevsp = NULL;
|
||||
return (0);
|
||||
}
|
|
@ -1,316 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 - 2003
|
||||
* NetGroup, Politecnico di Torino (Italy)
|
||||
* 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. Neither the name of the Politecnico di Torino 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/fad-win32.c,v 1.1.1.1 2006/02/27 15:45:45 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
#include <pcap-int.h>
|
||||
#include <packet32.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* Add an entry to the list of addresses for an interface.
|
||||
* "curdev" is the entry for that interface.
|
||||
*/
|
||||
static int
|
||||
add_addr_to_list(pcap_if_t *curdev, struct sockaddr *addr,
|
||||
struct sockaddr *netmask, struct sockaddr *broadaddr,
|
||||
struct sockaddr *dstaddr, char *errbuf)
|
||||
{
|
||||
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
|
||||
|
||||
/*
|
||||
* Allocate the new entry and fill it in.
|
||||
*/
|
||||
curaddr = (pcap_addr_t*)malloc(sizeof(pcap_addr_t));
|
||||
if (curaddr == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
curaddr->next = NULL;
|
||||
if (addr != NULL) {
|
||||
curaddr->addr = (struct sockaddr*)dup_sockaddr(addr, sizeof(struct sockaddr_storage));
|
||||
if (curaddr->addr == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
free(curaddr);
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
curaddr->addr = NULL;
|
||||
|
||||
if (netmask != NULL) {
|
||||
curaddr->netmask = (struct sockaddr*)dup_sockaddr(netmask, sizeof(struct sockaddr_storage));
|
||||
if (curaddr->netmask == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
free(curaddr);
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
curaddr->netmask = NULL;
|
||||
|
||||
if (broadaddr != NULL) {
|
||||
curaddr->broadaddr = (struct sockaddr*)dup_sockaddr(broadaddr, sizeof(struct sockaddr_storage));
|
||||
if (curaddr->broadaddr == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
free(curaddr);
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
curaddr->broadaddr = NULL;
|
||||
|
||||
if (dstaddr != NULL) {
|
||||
curaddr->dstaddr = (struct sockaddr*)dup_sockaddr(dstaddr, sizeof(struct sockaddr_storage));
|
||||
if (curaddr->dstaddr == NULL) {
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
free(curaddr);
|
||||
return (-1);
|
||||
}
|
||||
} else
|
||||
curaddr->dstaddr = NULL;
|
||||
|
||||
/*
|
||||
* Find the end of the list of addresses.
|
||||
*/
|
||||
for (prevaddr = curdev->addresses; prevaddr != NULL; prevaddr = nextaddr) {
|
||||
nextaddr = prevaddr->next;
|
||||
if (nextaddr == NULL) {
|
||||
/*
|
||||
* This is the end of the list.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevaddr == NULL) {
|
||||
/*
|
||||
* The list was empty; this is the first member.
|
||||
*/
|
||||
curdev->addresses = curaddr;
|
||||
} else {
|
||||
/*
|
||||
* "prevaddr" is the last member of the list; append
|
||||
* this member to it.
|
||||
*/
|
||||
prevaddr->next = curaddr;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
|
||||
char *errbuf)
|
||||
{
|
||||
pcap_if_t *curdev;
|
||||
npf_if_addr if_addrs[MAX_NETWORK_ADDRESSES];
|
||||
LONG if_addr_size;
|
||||
int res = 0;
|
||||
|
||||
if_addr_size = MAX_NETWORK_ADDRESSES;
|
||||
|
||||
/*
|
||||
* Add an entry for this interface, with no addresses.
|
||||
*/
|
||||
if (add_or_find_if(&curdev, devlist, name, 0, desc, errbuf) == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the list of addresses for the interface.
|
||||
*/
|
||||
if (!PacketGetNetInfoEx((void *)name, if_addrs, &if_addr_size)) {
|
||||
/*
|
||||
* Failure.
|
||||
*
|
||||
* We don't return an error, because this can happen with
|
||||
* NdisWan interfaces, and we want to supply them even
|
||||
* if we can't supply their addresses.
|
||||
*
|
||||
* We return an entry with an empty address list.
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now add the addresses.
|
||||
*/
|
||||
while (if_addr_size-- > 0) {
|
||||
/*
|
||||
* "curdev" is an entry for this interface; add an entry for
|
||||
* this address to its list of addresses.
|
||||
*/
|
||||
if(curdev == NULL)
|
||||
break;
|
||||
res = add_addr_to_list(curdev,
|
||||
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
|
||||
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
|
||||
(struct sockaddr *)&if_addrs[if_addr_size].Broadcast,
|
||||
NULL,
|
||||
errbuf);
|
||||
if (res == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Win32 implementation, based on WinPcap
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
pcap_if_t *devlist = NULL;
|
||||
int ret = 0;
|
||||
const char *desc;
|
||||
char *AdaptersName;
|
||||
ULONG NameLength;
|
||||
char *name;
|
||||
|
||||
if(!PacketGetAdapterNames(NULL, &NameLength) && NameLength == 0)
|
||||
{
|
||||
/*
|
||||
* If PacketGetAdapterNames *and* sets the lenght of the buffer to zero,
|
||||
* it means there was an error.
|
||||
*/
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "PacketGetAdapterNames failed: %s", pcap_win32strerror());
|
||||
*alldevsp = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NameLength > 0)
|
||||
AdaptersName = (char*) malloc(NameLength);
|
||||
else
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "no adapters found.");
|
||||
*alldevsp = NULL;
|
||||
return 0;
|
||||
}
|
||||
if (AdaptersName == NULL)
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Cannot allocate enough memory to list the adapters.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (!PacketGetAdapterNames(AdaptersName, &NameLength)) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"PacketGetAdapterNames: %s",
|
||||
pcap_win32strerror());
|
||||
free(AdaptersName);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* "PacketGetAdapterNames()" returned a list of
|
||||
* null-terminated ASCII interface name strings,
|
||||
* terminated by a null string, followed by a list
|
||||
* of null-terminated ASCII interface description
|
||||
* strings, terminated by a null string.
|
||||
* This means there are two ASCII nulls at the end
|
||||
* of the first list.
|
||||
*
|
||||
* Find the end of the first list; that's the
|
||||
* beginning of the second list.
|
||||
*/
|
||||
desc = &AdaptersName[0];
|
||||
while (*desc != '\0' || *(desc + 1) != '\0')
|
||||
desc++;
|
||||
|
||||
/*
|
||||
* Found it - "desc" points to the first of the two
|
||||
* nulls at the end of the list of names, so the
|
||||
* first byte of the list of descriptions is two bytes
|
||||
* after it.
|
||||
*/
|
||||
desc += 2;
|
||||
|
||||
/*
|
||||
* Loop over the elements in the first list.
|
||||
*/
|
||||
name = &AdaptersName[0];
|
||||
while (*name != '\0') {
|
||||
/*
|
||||
* Add an entry for this interface.
|
||||
*/
|
||||
if (pcap_add_if_win32(&devlist, name, desc, errbuf) == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
name += strlen(name) + 1;
|
||||
desc += strlen(desc) + 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;
|
||||
free(AdaptersName);
|
||||
return (ret);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,326 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/gencode.h,v 1.2 2006/02/27 15:55:30 drochner 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.
|
||||
*/
|
||||
|
||||
#ifndef HAVE___ATTRIBUTE__
|
||||
#define __attribute__(x)
|
||||
#endif /* HAVE___ATTRIBUTE__ */
|
||||
|
||||
/* 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
|
||||
#define Q_PORTRANGE 7
|
||||
|
||||
/* 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
|
||||
|
||||
#define Q_RADIO 40
|
||||
|
||||
/* 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. */
|
||||
|
||||
/*MTP3 field types */
|
||||
#define M_SIO 1
|
||||
#define M_OPC 2
|
||||
#define M_DPC 3
|
||||
#define M_SLS 4
|
||||
|
||||
|
||||
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 *, 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_mpls(int);
|
||||
|
||||
struct block *gen_pppoed(void);
|
||||
struct block *gen_pppoes(void);
|
||||
|
||||
struct block *gen_atmfield_code(int atmfield, bpf_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_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse);
|
||||
|
||||
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 *);
|
||||
int pcap_parse(void);
|
||||
void lex_init(const 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,465 +0,0 @@
|
|||
%{
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/grammar.y,v 1.2 2006/02/27 15:55:30 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include "pf.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(const 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;
|
||||
int mtp3fieldtype;
|
||||
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
|
||||
%type <blk> mtp3field
|
||||
%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
|
||||
|
||||
|
||||
%token DST SRC HOST GATEWAY
|
||||
%token NET NETMASK PORT PORTRANGE 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 MPLS
|
||||
%token PPPOED PPPOES
|
||||
%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
|
||||
%token RADIO
|
||||
%token SIO OPC DPC SLS
|
||||
|
||||
%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, $3,
|
||||
$$.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; }
|
||||
| mtp3field mtp3value { $$.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; }
|
||||
| PORTRANGE { $$ = Q_PORTRANGE; }
|
||||
;
|
||||
/* 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; }
|
||||
| RADIO { $$ = Q_RADIO; }
|
||||
;
|
||||
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); }
|
||||
| MPLS pnum { $$ = gen_mpls($2); }
|
||||
| MPLS { $$ = gen_mpls(-1); }
|
||||
| PPPOED { $$ = gen_pppoed(); }
|
||||
| PPPOES { $$ = gen_pppoes(); }
|
||||
| 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, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
|
||||
| irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$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, (bpf_int32) $1, BPF_JEQ, 0);
|
||||
}
|
||||
;
|
||||
atmlistvalue: atmfieldvalue
|
||||
| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
|
||||
;
|
||||
/* MTP3 field types quantifier */
|
||||
mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
|
||||
| OPC { $$.mtp3fieldtype = M_OPC; }
|
||||
| DPC { $$.mtp3fieldtype = M_DPC; }
|
||||
| SLS { $$.mtp3fieldtype = M_SLS; }
|
||||
;
|
||||
mtp3value: mtp3fieldvalue
|
||||
| relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
|
||||
| irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
|
||||
| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
|
||||
;
|
||||
mtp3fieldvalue: NUM {
|
||||
$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
|
||||
if ($$.mtp3fieldtype == M_SIO ||
|
||||
$$.mtp3fieldtype == M_OPC ||
|
||||
$$.mtp3fieldtype == M_DPC ||
|
||||
$$.mtp3fieldtype == M_SLS )
|
||||
$$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
|
||||
}
|
||||
;
|
||||
mtp3listvalue: mtp3fieldvalue
|
||||
| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
|
||||
;
|
||||
%%
|
|
@ -1,733 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/inet.c,v 1.3 2009/09/29 19:00:45 bouyer Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
|
||||
#include <sys/param.h>
|
||||
#ifndef MSDOS
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
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>
|
||||
#if !defined(WIN32) && !defined(__BORLANDC__)
|
||||
#include <unistd.h>
|
||||
#endif /* !WIN32 && !__BORLANDC__ */
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#else
|
||||
#define INT_MAX 2147483647
|
||||
#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_t *p;
|
||||
pcap_if_t *curdev, *prevdev, *nextdev;
|
||||
int this_instance;
|
||||
|
||||
/*
|
||||
* Can we open this interface for live capture?
|
||||
*
|
||||
* We do this check so that interfaces that ae supplied
|
||||
* by the interface enumeration mechanism we're using
|
||||
* but that don't support packet capture aren't included
|
||||
* in the list. An example of this is loopback interfaces
|
||||
* on Solaris; we don't just omit loopback interfaces
|
||||
* becaue you *can* capture on loopback interfaces on some
|
||||
* OSes.
|
||||
*/
|
||||
p = pcap_open_live(name, 68, 0, 0, errbuf);
|
||||
if (p == NULL) {
|
||||
/*
|
||||
* No. Don't bother including it.
|
||||
* Don't treat this as an error, though.
|
||||
*/
|
||||
*curdev_ret = NULL;
|
||||
return (0);
|
||||
}
|
||||
pcap_close(p);
|
||||
|
||||
/*
|
||||
* 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, const char *name, u_int flags,
|
||||
struct sockaddr *addr, size_t addr_size,
|
||||
struct sockaddr *netmask, size_t netmask_size,
|
||||
struct sockaddr *broadaddr, size_t broadaddr_size,
|
||||
struct sockaddr *dstaddr, size_t dstaddr_size,
|
||||
char *errbuf)
|
||||
{
|
||||
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, const 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);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
|
||||
/*
|
||||
* 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 *sin4;
|
||||
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
|
||||
#ifdef HAVE_SEPTEL_API
|
||||
|| strstr(device, "septel") != 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);
|
||||
}
|
||||
sin4 = (struct sockaddr_in *)&ifr.ifr_addr;
|
||||
*netp = sin4->sin_addr.s_addr;
|
||||
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, 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 = sin4->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);
|
||||
}
|
||||
|
||||
#elif defined(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];
|
||||
|
||||
if (PacketGetAdapterNames(AdaptersName,&NameLength) )
|
||||
return (AdaptersName);
|
||||
else
|
||||
return NULL;
|
||||
} 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;
|
||||
}
|
||||
|
||||
if ( !PacketGetAdapterNames((PTSTR)TAdaptersName,&NameLength) )
|
||||
{
|
||||
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"PacketGetAdapterNames: %s",
|
||||
pcap_win32strerror());
|
||||
free(TAdaptersName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
free(TAdaptersName);
|
||||
return (char *)(AdaptersName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pcap_lookupnet(device, netp, maskp, errbuf)
|
||||
register const 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 && !MSDOS */
|
|
@ -1,250 +0,0 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/llc.h,v 1.1.1.1 2006/02/27 15:45:46 drochner 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,109 +0,0 @@
|
|||
#!/bin/sh -
|
||||
#
|
||||
# Copyright (c) 1994, 1996
|
||||
# The Regents of the University of California. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms are permitted
|
||||
# provided that this notice is preserved and that due credit is given
|
||||
# to the University of California at Berkeley. The name of the University
|
||||
# may not be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission. This software
|
||||
# is provided ``as is'' without express or implied warranty.
|
||||
#
|
||||
# @(#)mkdep.sh 5.11 (Berkeley) 5/5/88
|
||||
#
|
||||
|
||||
PATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/local/bin
|
||||
export PATH
|
||||
|
||||
MAKE=Makefile # default makefile name is "Makefile"
|
||||
CC=cc # default C compiler is "cc"
|
||||
|
||||
while :
|
||||
do case "$1" in
|
||||
# -c allows you to specify the C compiler
|
||||
-c)
|
||||
CC=$2
|
||||
shift; shift ;;
|
||||
|
||||
# -f allows you to select a makefile name
|
||||
-f)
|
||||
MAKE=$2
|
||||
shift; shift ;;
|
||||
|
||||
# the -p flag produces "program: program.c" style dependencies
|
||||
# so .o's don't get produced
|
||||
-p)
|
||||
SED='s;\.o;;'
|
||||
shift ;;
|
||||
*)
|
||||
break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# = 0 ] ; then
|
||||
echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -w $MAKE ]; then
|
||||
echo "mkdep: no writeable file \"$MAKE\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TMP=/tmp/mkdep$$
|
||||
|
||||
trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
|
||||
|
||||
cp $MAKE ${MAKE}.bak
|
||||
|
||||
sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
|
||||
|
||||
cat << _EOF_ >> $TMP
|
||||
# DO NOT DELETE THIS LINE -- mkdep uses it.
|
||||
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
|
||||
|
||||
_EOF_
|
||||
|
||||
# If your compiler doesn't have -M, add it. If you can't, the next two
|
||||
# lines will try and replace the "cc -M". The real problem is that this
|
||||
# hack can't deal with anything that requires a search path, and doesn't
|
||||
# even try for anything using bracket (<>) syntax.
|
||||
#
|
||||
# egrep '^#include[ ]*".*"' /dev/null $* |
|
||||
# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
|
||||
|
||||
# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
|
||||
$CC -M $* |
|
||||
sed "
|
||||
s; \./; ;g
|
||||
$SED" |
|
||||
awk '{
|
||||
if ($1 != prev) {
|
||||
if (rec != "")
|
||||
print rec;
|
||||
rec = $0;
|
||||
prev = $1;
|
||||
}
|
||||
else {
|
||||
if (length(rec $2) > 78) {
|
||||
print rec;
|
||||
rec = $0;
|
||||
}
|
||||
else
|
||||
rec = rec " " $2
|
||||
}
|
||||
}
|
||||
END {
|
||||
print rec
|
||||
}' >> $TMP
|
||||
|
||||
cat << _EOF_ >> $TMP
|
||||
|
||||
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
|
||||
_EOF_
|
||||
|
||||
# copy to preserve permissions
|
||||
cp $TMP $MAKE
|
||||
rm -f ${MAKE}.bak $TMP
|
||||
exit 0
|
|
@ -1,505 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/nametoaddr.c,v 1.2 2006/02/27 15:55:30 drochner Exp $ (LBL)";
|
||||
#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
|
||||
/*
|
||||
* XXX - do we need any of this if <netinet/if_ether.h> doesn't declare
|
||||
* 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 */
|
||||
#ifdef NETINET_ETHER_H_DECLARES_ETHER_HOSTTON
|
||||
#include <netinet/ether.h>
|
||||
#endif /* NETINET_ETHER_H_DECLARES_ETHER_HOSTTON */
|
||||
#endif /* HAVE_ETHER_HOSTTON */
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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*/
|
||||
hints.ai_protocol = IPPROTO_TCP; /*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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string in the form PPP-PPP, where correspond to ports, to
|
||||
* a starting and ending port in a port range.
|
||||
* Return 0 on failure.
|
||||
*/
|
||||
int
|
||||
pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
|
||||
{
|
||||
u_int p1, p2;
|
||||
char *off, *cpy;
|
||||
int save_proto;
|
||||
|
||||
if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
|
||||
if ((cpy = strdup(name)) == NULL)
|
||||
return 0;
|
||||
|
||||
if ((off = strchr(cpy, '-')) == NULL) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*off = '\0';
|
||||
|
||||
if (pcap_nametoport(cpy, port1, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
save_proto = *proto;
|
||||
|
||||
if (pcap_nametoport(off + 1, port2, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*proto != save_proto)
|
||||
*proto = PROTO_UNDEF;
|
||||
} else {
|
||||
*port1 = p1;
|
||||
*port2 = p2;
|
||||
*proto = PROTO_UNDEF;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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 {
|
||||
const 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;
|
||||
}
|
||||
|
||||
#include "llc.h"
|
||||
|
||||
/* Static data base of LLC values. */
|
||||
static struct eproto llc_db[] = {
|
||||
{ "iso", LLCSAP_ISONS },
|
||||
{ "stp", LLCSAP_8021D },
|
||||
{ "ipx", LLCSAP_IPX },
|
||||
{ "netbeui", LLCSAP_NETBEUI },
|
||||
{ (char *)0, 0 }
|
||||
};
|
||||
|
||||
int
|
||||
pcap_nametollc(const char *s)
|
||||
{
|
||||
struct eproto *p = llc_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(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
|
||||
|
||||
#if !defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON
|
||||
#ifndef HAVE_STRUCT_ETHER_ADDR
|
||||
struct ether_addr {
|
||||
unsigned char ether_addr_octet[6];
|
||||
};
|
||||
#endif
|
||||
extern int ether_hostton(const 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(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);
|
||||
return(0);
|
||||
#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/dist/libpcap/Attic/nlpid.h,v 1.1.1.1 2006/02/27 15:45:46 drochner 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
File diff suppressed because it is too large
Load Diff
|
@ -1,697 +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.
|
||||
*
|
||||
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-bpf.h,v 1.2 2009/09/14 10:36:48 degroote Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is libpcap's cut-down version of bpf.h; it includes only
|
||||
* the stuff needed for the code generator and the userland BPF
|
||||
* interpreter, and the libpcap APIs for setting filters, etc..
|
||||
*
|
||||
* "pcap-bpf.c" will include the native OS version, as it deals with
|
||||
* the OS's BPF implementation.
|
||||
*
|
||||
* XXX - should this all just be moved to "pcap.h"?
|
||||
*/
|
||||
|
||||
#ifndef BPF_MAJOR_VERSION
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* BSD style release date */
|
||||
#define BPF_RELEASE 199606
|
||||
|
||||
#ifdef MSDOS /* must be 32-bit */
|
||||
typedef long bpf_int32;
|
||||
typedef unsigned long bpf_u_int32;
|
||||
#else
|
||||
typedef int bpf_int32;
|
||||
typedef u_int bpf_u_int32;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Alignment macros. BPF_WORDALIGN rounds up to the next
|
||||
* even multiple of BPF_ALIGNMENT.
|
||||
*/
|
||||
#ifndef __NetBSD__
|
||||
#define BPF_ALIGNMENT sizeof(bpf_int32)
|
||||
#else
|
||||
#define BPF_ALIGNMENT sizeof(long)
|
||||
#endif
|
||||
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
|
||||
|
||||
#define BPF_MAXINSNS 512
|
||||
#define BPF_MAXBUFSIZE 0x8000
|
||||
#define BPF_MINBUFSIZE 32
|
||||
|
||||
/*
|
||||
* Structure for "pcap_compile()", "pcap_setfilter()", etc..
|
||||
*/
|
||||
struct bpf_program {
|
||||
u_int bf_len;
|
||||
struct bpf_insn *bf_insns;
|
||||
};
|
||||
|
||||
/*
|
||||
* Struct return by BIOCVERSION. This represents the version number of
|
||||
* the filter language described by the instruction encodings below.
|
||||
* bpf understands a program iff kernel_major == filter_major &&
|
||||
* kernel_minor >= filter_minor, that is, if the value returned by the
|
||||
* running kernel has the same major number and a minor number equal
|
||||
* equal to or less than the filter being downloaded. Otherwise, the
|
||||
* results are undefined, meaning an error may be returned or packets
|
||||
* may be accepted haphazardly.
|
||||
* It has nothing to do with the source code version.
|
||||
*/
|
||||
struct bpf_version {
|
||||
u_short bv_major;
|
||||
u_short bv_minor;
|
||||
};
|
||||
/* Current version number of filter architecture. */
|
||||
#define BPF_MAJOR_VERSION 1
|
||||
#define BPF_MINOR_VERSION 1
|
||||
|
||||
/*
|
||||
* Data-link level type codes.
|
||||
*
|
||||
* Do *NOT* add new values to this list without asking
|
||||
* "tcpdump-workers@tcpdump.org" for a value. Otherwise, you run the
|
||||
* risk of using a value that's already being used for some other purpose,
|
||||
* and of having tools that read libpcap-format captures not being able
|
||||
* to handle captures with your new DLT_ value, with no hope that they
|
||||
* will ever be changed to do so (as that would destroy their ability
|
||||
* to read captures using that value for that other purpose).
|
||||
*/
|
||||
|
||||
/*
|
||||
* These are the types that are the same on all platforms, and that
|
||||
* have been defined by <net/bpf.h> for ages.
|
||||
*/
|
||||
#define DLT_NULL 0 /* BSD loopback encapsulation */
|
||||
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
|
||||
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
|
||||
#define DLT_AX25 3 /* Amateur Radio AX.25 */
|
||||
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
|
||||
#define DLT_CHAOS 5 /* Chaos */
|
||||
#define DLT_IEEE802 6 /* IEEE 802 Networks */
|
||||
#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */
|
||||
#define DLT_SLIP 8 /* Serial Line IP */
|
||||
#define DLT_PPP 9 /* Point-to-point Protocol */
|
||||
#define DLT_FDDI 10 /* FDDI */
|
||||
|
||||
/*
|
||||
* These are types that are different on some platforms, and that
|
||||
* have been defined by <net/bpf.h> for ages. We use #ifdefs to
|
||||
* detect the BSDs that define them differently from the traditional
|
||||
* libpcap <net/bpf.h>
|
||||
*
|
||||
* XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS,
|
||||
* but I don't know what the right #define is for BSD/OS.
|
||||
*/
|
||||
#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
#define DLT_RAW 14 /* raw IP */
|
||||
#else
|
||||
#define DLT_RAW 12 /* raw IP */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Given that the only OS that currently generates BSD/OS SLIP or PPP
|
||||
* is, well, BSD/OS, arguably everybody should have chosen its values
|
||||
* for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they
|
||||
* didn't. So it goes.
|
||||
*/
|
||||
#if defined(__NetBSD__) || defined(__FreeBSD__)
|
||||
#ifndef DLT_SLIP_BSDOS
|
||||
#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
|
||||
#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
|
||||
#endif
|
||||
#else
|
||||
#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
|
||||
#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 17 is used for DLT_OLD_PFLOG in OpenBSD;
|
||||
* OBSOLETE: DLT_PFLOG is 117 in OpenBSD now as well. See below.
|
||||
* 18 is used for DLT_PFSYNC in OpenBSD; don't use it for anything else.
|
||||
*/
|
||||
|
||||
#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
|
||||
|
||||
/*
|
||||
* Apparently Redback uses this for its SmartEdge 400/800. I hope
|
||||
* nobody else decided to use it, too.
|
||||
*/
|
||||
#define DLT_REDBACK_SMARTEDGE 32
|
||||
|
||||
/*
|
||||
* These values are defined by NetBSD; other platforms should refrain from
|
||||
* using them for other purposes, so that NetBSD savefiles with link
|
||||
* types of 50 or 51 can be read as this type on all platforms.
|
||||
*/
|
||||
#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
|
||||
#define DLT_PPP_ETHER 51 /* PPP over Ethernet */
|
||||
|
||||
/*
|
||||
* The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses
|
||||
* a link-layer type of 99 for the tcpdump it supplies. The link-layer
|
||||
* header has 6 bytes of unknown data, something that appears to be an
|
||||
* Ethernet type, and 36 bytes that appear to be 0 in at least one capture
|
||||
* I've seen.
|
||||
*/
|
||||
#define DLT_SYMANTEC_FIREWALL 99
|
||||
|
||||
/*
|
||||
* Values between 100 and 103 are used in capture file headers as
|
||||
* link-layer types corresponding to DLT_ types that differ
|
||||
* between platforms; don't use those values for new DLT_ new types.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This value was defined by libpcap 0.5; platforms that have defined
|
||||
* it with a different value should define it here with that value -
|
||||
* a link type of 104 in a save file will be mapped to DLT_C_HDLC,
|
||||
* whatever value that happens to be, so programs will correctly
|
||||
* handle files with that link type regardless of the value of
|
||||
* DLT_C_HDLC.
|
||||
*
|
||||
* The name DLT_C_HDLC was used by BSD/OS; we use that name for source
|
||||
* compatibility with programs written for BSD/OS.
|
||||
*
|
||||
* libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
|
||||
* for source compatibility with programs written for libpcap 0.5.
|
||||
*/
|
||||
#define DLT_C_HDLC 104 /* Cisco HDLC */
|
||||
#define DLT_CHDLC DLT_C_HDLC
|
||||
|
||||
#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
|
||||
|
||||
/*
|
||||
* 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW,
|
||||
* except when it isn't. (I.e., sometimes it's just raw IP, and
|
||||
* sometimes it isn't.) We currently handle it as DLT_LINUX_SLL,
|
||||
* so that we don't have to worry about the link-layer header.)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
|
||||
* with other values.
|
||||
* DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
|
||||
* (DLCI, etc.).
|
||||
*/
|
||||
#define DLT_FRELAY 107
|
||||
|
||||
/*
|
||||
* OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
|
||||
* that the AF_ type in the link-layer header is in network byte order.
|
||||
*
|
||||
* OpenBSD defines it as 12, but that collides with DLT_RAW, so we
|
||||
* define it as 108 here. If OpenBSD picks up this file, it should
|
||||
* define DLT_LOOP as 12 in its version, as per the comment above -
|
||||
* and should not use 108 as a DLT_ value.
|
||||
*/
|
||||
#define DLT_LOOP 108
|
||||
|
||||
/*
|
||||
* Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
|
||||
* DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
|
||||
* than OpenBSD.
|
||||
*/
|
||||
#ifdef __OpenBSD__
|
||||
#define DLT_ENC 13
|
||||
#else
|
||||
#define DLT_ENC 109
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Values between 110 and 112 are reserved for use in capture file headers
|
||||
* as link-layer types corresponding to DLT_ types that might differ
|
||||
* between platforms; don't use those values for new DLT_ types
|
||||
* other than the corresponding DLT_ types.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is for Linux cooked sockets.
|
||||
*/
|
||||
#define DLT_LINUX_SLL 113
|
||||
|
||||
/*
|
||||
* Apple LocalTalk hardware.
|
||||
*/
|
||||
#define DLT_LTALK 114
|
||||
|
||||
/*
|
||||
* Acorn Econet.
|
||||
*/
|
||||
#define DLT_ECONET 115
|
||||
|
||||
/*
|
||||
* Reserved for use with OpenBSD ipfilter.
|
||||
*/
|
||||
#define DLT_IPFILTER 116
|
||||
|
||||
/*
|
||||
* OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD, but that's DLT_LANE8023
|
||||
* in SuSE 6.3, so we can't use 17 for it in capture-file headers.
|
||||
*
|
||||
* XXX: is there a conflict with DLT_PFSYNC 18 as well?
|
||||
*/
|
||||
#ifdef __OpenBSD__
|
||||
#define DLT_OLD_PFLOG 17
|
||||
#endif
|
||||
#define DLT_PFSYNC 18
|
||||
#define DLT_PFLOG 117
|
||||
|
||||
/*
|
||||
* Registered for Cisco-internal use.
|
||||
*/
|
||||
#define DLT_CISCO_IOS 118
|
||||
|
||||
/*
|
||||
* For 802.11 cards using the Prism II chips, with a link-layer
|
||||
* header including Prism monitor mode information plus an 802.11
|
||||
* header.
|
||||
*/
|
||||
#define DLT_PRISM_HEADER 119
|
||||
|
||||
/*
|
||||
* Reserved for Aironet 802.11 cards, with an Aironet link-layer header
|
||||
* (see Doug Ambrisko's FreeBSD patches).
|
||||
*/
|
||||
#define DLT_AIRONET_HEADER 120
|
||||
|
||||
/*
|
||||
* Reserved for Siemens HiPath HDLC.
|
||||
*/
|
||||
#define DLT_HHDLC 121
|
||||
|
||||
/*
|
||||
* This is for RFC 2625 IP-over-Fibre Channel.
|
||||
*
|
||||
* This is not for use with raw Fibre Channel, where the link-layer
|
||||
* header starts with a Fibre Channel frame header; it's for IP-over-FC,
|
||||
* where the link-layer header starts with an RFC 2625 Network_Header
|
||||
* field.
|
||||
*/
|
||||
#define DLT_IP_OVER_FC 122
|
||||
|
||||
/*
|
||||
* This is for Full Frontal ATM on Solaris with SunATM, with a
|
||||
* pseudo-header followed by an AALn PDU.
|
||||
*
|
||||
* There may be other forms of Full Frontal ATM on other OSes,
|
||||
* with different pseudo-headers.
|
||||
*
|
||||
* If ATM software returns a pseudo-header with VPI/VCI information
|
||||
* (and, ideally, packet type information, e.g. signalling, ILMI,
|
||||
* LANE, LLC-multiplexed traffic, etc.), it should not use
|
||||
* DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump
|
||||
* and the like don't have to infer the presence or absence of a
|
||||
* pseudo-header and the form of the pseudo-header.
|
||||
*/
|
||||
#define DLT_SUNATM 123 /* Solaris+SunATM */
|
||||
|
||||
/*
|
||||
* Reserved as per request from Kent Dahlgren <kent@praesum.com>
|
||||
* for private use.
|
||||
*/
|
||||
#define DLT_RIO 124 /* RapidIO */
|
||||
#define DLT_PCI_EXP 125 /* PCI Express */
|
||||
#define DLT_AURORA 126 /* Xilinx Aurora link layer */
|
||||
|
||||
/*
|
||||
* Header for 802.11 plus a number of bits of link-layer information
|
||||
* including radio information, used by some recent BSD drivers as
|
||||
* well as the madwifi Atheros driver for Linux.
|
||||
*/
|
||||
#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */
|
||||
|
||||
/*
|
||||
* Reserved for the TZSP encapsulation, as per request from
|
||||
* Chris Waters <chris.waters@networkchemistry.com>
|
||||
* TZSP is a generic encapsulation for any other link type,
|
||||
* which includes a means to include meta-information
|
||||
* with the packet, e.g. signal strength and channel
|
||||
* for 802.11 packets.
|
||||
*/
|
||||
#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */
|
||||
|
||||
/*
|
||||
* BSD's ARCNET headers have the source host, destination host,
|
||||
* and type at the beginning of the packet; that's what's handed
|
||||
* up to userland via BPF.
|
||||
*
|
||||
* Linux's ARCNET headers, however, have a 2-byte offset field
|
||||
* between the host IDs and the type; that's what's handed up
|
||||
* to userland via PF_PACKET sockets.
|
||||
*
|
||||
* We therefore have to have separate DLT_ values for them.
|
||||
*/
|
||||
#define DLT_ARCNET_LINUX 129 /* ARCNET */
|
||||
|
||||
/*
|
||||
* Juniper-private data link types, as per request from
|
||||
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||
* for passing on chassis-internal metainformation such as
|
||||
* QOS profiles, etc..
|
||||
*/
|
||||
#define DLT_JUNIPER_MLPPP 130
|
||||
#define DLT_JUNIPER_MLFR 131
|
||||
#define DLT_JUNIPER_ES 132
|
||||
#define DLT_JUNIPER_GGSN 133
|
||||
#define DLT_JUNIPER_MFR 134
|
||||
#define DLT_JUNIPER_ATM2 135
|
||||
#define DLT_JUNIPER_SERVICES 136
|
||||
#define DLT_JUNIPER_ATM1 137
|
||||
|
||||
/*
|
||||
* Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund
|
||||
* <dieter@apple.com>. The header that's presented is an Ethernet-like
|
||||
* header:
|
||||
*
|
||||
* #define FIREWIRE_EUI64_LEN 8
|
||||
* struct firewire_header {
|
||||
* u_char firewire_dhost[FIREWIRE_EUI64_LEN];
|
||||
* u_char firewire_shost[FIREWIRE_EUI64_LEN];
|
||||
* u_short firewire_type;
|
||||
* };
|
||||
*
|
||||
* with "firewire_type" being an Ethernet type value, rather than,
|
||||
* for example, raw GASP frames being handed up.
|
||||
*/
|
||||
#define DLT_APPLE_IP_OVER_IEEE1394 138
|
||||
|
||||
/*
|
||||
* Various SS7 encapsulations, as per a request from Jeff Morriss
|
||||
* <jeff.morriss[AT]ulticom.com> and subsequent discussions.
|
||||
*/
|
||||
#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */
|
||||
#define DLT_MTP2 140 /* MTP2, without pseudo-header */
|
||||
#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */
|
||||
#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */
|
||||
|
||||
/*
|
||||
* DOCSIS MAC frames.
|
||||
*/
|
||||
#define DLT_DOCSIS 143
|
||||
|
||||
/*
|
||||
* Linux-IrDA packets. Protocol defined at http://www.irda.org.
|
||||
* Those packets include IrLAP headers and above (IrLMP...), but
|
||||
* don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy
|
||||
* framing can be handled by the hardware and depend on the bitrate.
|
||||
* This is exactly the format you would get capturing on a Linux-IrDA
|
||||
* interface (irdaX), but not on a raw serial port.
|
||||
* Note the capture is done in "Linux-cooked" mode, so each packet include
|
||||
* a fake packet header (struct sll_header). This is because IrDA packet
|
||||
* decoding is dependant on the direction of the packet (incomming or
|
||||
* outgoing).
|
||||
* When/if other platform implement IrDA capture, we may revisit the
|
||||
* issue and define a real DLT_IRDA...
|
||||
* Jean II
|
||||
*/
|
||||
#define DLT_LINUX_IRDA 144
|
||||
|
||||
/*
|
||||
* Reserved for IBM SP switch and IBM Next Federation switch.
|
||||
*/
|
||||
#define DLT_IBM_SP 145
|
||||
#define DLT_IBM_SN 146
|
||||
|
||||
/*
|
||||
* Reserved for private use. If you have some link-layer header type
|
||||
* that you want to use within your organization, with the capture files
|
||||
* using that link-layer header type not ever be sent outside your
|
||||
* organization, you can use these values.
|
||||
*
|
||||
* No libpcap release will use these for any purpose, nor will any
|
||||
* tcpdump release use them, either.
|
||||
*
|
||||
* Do *NOT* use these in capture files that you expect anybody not using
|
||||
* your private versions of capture-file-reading tools to read; in
|
||||
* particular, do *NOT* use them in products, otherwise you may find that
|
||||
* people won't be able to use tcpdump, or snort, or Ethereal, or... to
|
||||
* read capture files from your firewall/intrusion detection/traffic
|
||||
* monitoring/etc. appliance, or whatever product uses that DLT_ value,
|
||||
* and you may also find that the developers of those applications will
|
||||
* not accept patches to let them read those files.
|
||||
*
|
||||
* Also, do not use them if somebody might send you a capture using them
|
||||
* for *their* private type and tools using them for *your* private type
|
||||
* would have to read them.
|
||||
*
|
||||
* Instead, ask "tcpdump-workers@tcpdump.org" for a new DLT_ value,
|
||||
* as per the comment above, and use the type you're given.
|
||||
*/
|
||||
#define DLT_USER0 147
|
||||
#define DLT_USER1 148
|
||||
#define DLT_USER2 149
|
||||
#define DLT_USER3 150
|
||||
#define DLT_USER4 151
|
||||
#define DLT_USER5 152
|
||||
#define DLT_USER6 153
|
||||
#define DLT_USER7 154
|
||||
#define DLT_USER8 155
|
||||
#define DLT_USER9 156
|
||||
#define DLT_USER10 157
|
||||
#define DLT_USER11 158
|
||||
#define DLT_USER12 159
|
||||
#define DLT_USER13 160
|
||||
#define DLT_USER14 161
|
||||
#define DLT_USER15 162
|
||||
|
||||
/*
|
||||
* For future use with 802.11 captures - defined by AbsoluteValue
|
||||
* Systems to store a number of bits of link-layer information
|
||||
* including radio information:
|
||||
*
|
||||
* http://www.shaftnet.org/~pizza/software/capturefrm.txt
|
||||
*
|
||||
* but it might be used by some non-AVS drivers now or in the
|
||||
* future.
|
||||
*/
|
||||
#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */
|
||||
|
||||
/*
|
||||
* Juniper-private data link type, as per request from
|
||||
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||
* for passing on chassis-internal metainformation such as
|
||||
* QOS profiles, etc..
|
||||
*/
|
||||
#define DLT_JUNIPER_MONITOR 164
|
||||
|
||||
/*
|
||||
* Reserved for BACnet MS/TP.
|
||||
*/
|
||||
#define DLT_BACNET_MS_TP 165
|
||||
|
||||
/*
|
||||
* Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
|
||||
*
|
||||
* This is used in some OSes to allow a kernel socket filter to distinguish
|
||||
* between incoming and outgoing packets, on a socket intended to
|
||||
* supply pppd with outgoing packets so it can do dial-on-demand and
|
||||
* hangup-on-lack-of-demand; incoming packets are filtered out so they
|
||||
* don't cause pppd to hold the connection up (you don't want random
|
||||
* input packets such as port scans, packets from old lost connections,
|
||||
* etc. to force the connection to stay up).
|
||||
*
|
||||
* The first byte of the PPP header (0xff03) is modified to accomodate
|
||||
* the direction - 0x00 = IN, 0x01 = OUT.
|
||||
*/
|
||||
#define DLT_PPP_PPPD 166
|
||||
|
||||
/*
|
||||
* Names for backwards compatibility with older versions of some PPP
|
||||
* software; new software should use DLT_PPP_PPPD.
|
||||
*/
|
||||
#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD
|
||||
#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD
|
||||
|
||||
/*
|
||||
* Juniper-private data link type, as per request from
|
||||
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
|
||||
* for passing on chassis-internal metainformation such as
|
||||
* QOS profiles, cookies, etc..
|
||||
*/
|
||||
#define DLT_JUNIPER_PPPOE 167
|
||||
#define DLT_JUNIPER_PPPOE_ATM 168
|
||||
|
||||
#define DLT_GPRS_LLC 169 /* GPRS LLC */
|
||||
#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
|
||||
#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */
|
||||
|
||||
/*
|
||||
* Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
|
||||
* monitoring equipment.
|
||||
*/
|
||||
#define DLT_GCOM_T1E1 172
|
||||
#define DLT_GCOM_SERIAL 173
|
||||
|
||||
/*
|
||||
* Juniper-private data link type, as per request from
|
||||
* Hannes Gredler <hannes@juniper.net>. The DLT_ is used
|
||||
* for internal communication to Physical Interface Cards (PIC)
|
||||
*/
|
||||
#define DLT_JUNIPER_PIC_PEER 174
|
||||
|
||||
/*
|
||||
* Link types requested by Gregor Maier <gregor@endace.com> of Endace
|
||||
* Measurement Systems. They add an ERF header (see
|
||||
* http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
|
||||
* the link-layer header.
|
||||
*/
|
||||
#define DLT_ERF_ETH 175 /* Ethernet */
|
||||
#define DLT_ERF_POS 176 /* Packet-over-SONET */
|
||||
|
||||
/*
|
||||
* Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
|
||||
* for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
|
||||
* includes additional information before the LAPD header, so it's
|
||||
* not necessarily a generic LAPD header.
|
||||
*/
|
||||
#define DLT_LINUX_LAPD 177
|
||||
|
||||
/*
|
||||
* Juniper-private data link type, as per request from
|
||||
* Hannes Gredler <hannes@juniper.net>.
|
||||
* The DLT_ are used for prepending meta-information
|
||||
* like interface index, interface name
|
||||
* before standard Ethernet, PPP, Frelay & C-HDLC Frames
|
||||
*/
|
||||
#define DLT_JUNIPER_ETHER 178
|
||||
#define DLT_JUNIPER_PPP 179
|
||||
#define DLT_JUNIPER_FRELAY 180
|
||||
#define DLT_JUNIPER_CHDLC 181
|
||||
|
||||
/*
|
||||
* The instruction encodings.
|
||||
*/
|
||||
/* instruction classes */
|
||||
#define BPF_CLASS(code) ((code) & 0x07)
|
||||
#define BPF_LD 0x00
|
||||
#define BPF_LDX 0x01
|
||||
#define BPF_ST 0x02
|
||||
#define BPF_STX 0x03
|
||||
#define BPF_ALU 0x04
|
||||
#define BPF_JMP 0x05
|
||||
#define BPF_RET 0x06
|
||||
#define BPF_MISC 0x07
|
||||
|
||||
/* ld/ldx fields */
|
||||
#define BPF_SIZE(code) ((code) & 0x18)
|
||||
#define BPF_W 0x00
|
||||
#define BPF_H 0x08
|
||||
#define BPF_B 0x10
|
||||
#define BPF_MODE(code) ((code) & 0xe0)
|
||||
#define BPF_IMM 0x00
|
||||
#define BPF_ABS 0x20
|
||||
#define BPF_IND 0x40
|
||||
#define BPF_MEM 0x60
|
||||
#define BPF_LEN 0x80
|
||||
#define BPF_MSH 0xa0
|
||||
|
||||
/* alu/jmp fields */
|
||||
#define BPF_OP(code) ((code) & 0xf0)
|
||||
#define BPF_ADD 0x00
|
||||
#define BPF_SUB 0x10
|
||||
#define BPF_MUL 0x20
|
||||
#define BPF_DIV 0x30
|
||||
#define BPF_OR 0x40
|
||||
#define BPF_AND 0x50
|
||||
#define BPF_LSH 0x60
|
||||
#define BPF_RSH 0x70
|
||||
#define BPF_NEG 0x80
|
||||
#define BPF_JA 0x00
|
||||
#define BPF_JEQ 0x10
|
||||
#define BPF_JGT 0x20
|
||||
#define BPF_JGE 0x30
|
||||
#define BPF_JSET 0x40
|
||||
#define BPF_SRC(code) ((code) & 0x08)
|
||||
#define BPF_K 0x00
|
||||
#define BPF_X 0x08
|
||||
|
||||
/* ret - BPF_K and BPF_X also apply */
|
||||
#define BPF_RVAL(code) ((code) & 0x18)
|
||||
#define BPF_A 0x10
|
||||
|
||||
/* misc */
|
||||
#define BPF_MISCOP(code) ((code) & 0xf8)
|
||||
#define BPF_TAX 0x00
|
||||
#define BPF_TXA 0x80
|
||||
|
||||
/*
|
||||
* The instruction data structure.
|
||||
*/
|
||||
struct bpf_insn {
|
||||
u_short code;
|
||||
u_char jt;
|
||||
u_char jf;
|
||||
bpf_int32 k;
|
||||
};
|
||||
|
||||
/*
|
||||
* Macros for insn array initializers.
|
||||
*/
|
||||
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
|
||||
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
|
||||
|
||||
#if __STDC__ || defined(__cplusplus)
|
||||
extern int bpf_validate(struct bpf_insn *, int);
|
||||
extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
|
||||
#else
|
||||
extern int bpf_validate();
|
||||
extern u_int bpf_filter();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
|
||||
*/
|
||||
#define BPF_MEMWORDS 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,886 +0,0 @@
|
|||
/*
|
||||
* pcap-dag.c: Packet capture interface for Endace DAG card.
|
||||
*
|
||||
* The functionality of this code attempts to mimic that of pcap-linux as much
|
||||
* as possible. This code is compiled in several different ways depending on
|
||||
* whether DAG_ONLY and HAVE_DAG_API are defined. If HAVE_DAG_API is not
|
||||
* defined it should not get compiled in, otherwise if DAG_ONLY is defined then
|
||||
* the 'dag_' function calls are renamed to 'pcap_' equivalents. If DAG_ONLY
|
||||
* is not defined then nothing is altered - the dag_ functions will be
|
||||
* called as required from their pcap-linux/bpf equivalents.
|
||||
*
|
||||
* Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
|
||||
* Modifications: Jesper Peterson <support@endace.com>
|
||||
* Koryn Grant <support@endace.com>
|
||||
* Stephen Donnelly <support@endace.com>
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-dag.c,v 1.1.1.1 2006/02/27 15:45:47 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||
struct rtentry; /* declarations in <net/if.h> */
|
||||
#include <net/if.h>
|
||||
|
||||
#include "dagnew.h"
|
||||
#include "dagapi.h"
|
||||
|
||||
#define MIN_DAG_SNAPLEN 12
|
||||
#define MAX_DAG_SNAPLEN 2040
|
||||
#define ATM_CELL_SIZE 52
|
||||
#define ATM_HDR_SIZE 4
|
||||
|
||||
/* SunATM pseudo header */
|
||||
struct sunatm_hdr {
|
||||
unsigned char flags; /* destination and traffic type */
|
||||
unsigned char vpi; /* VPI */
|
||||
unsigned short vci; /* VCI */
|
||||
};
|
||||
|
||||
typedef struct pcap_dag_node {
|
||||
struct pcap_dag_node *next;
|
||||
pcap_t *p;
|
||||
pid_t pid;
|
||||
} pcap_dag_node_t;
|
||||
|
||||
static pcap_dag_node_t *pcap_dags = NULL;
|
||||
static int atexit_handler_installed = 0;
|
||||
static const unsigned short endian_test_word = 0x0100;
|
||||
|
||||
#define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word))
|
||||
|
||||
/*
|
||||
* Swap byte ordering of unsigned long long timestamp on a big endian
|
||||
* machine.
|
||||
*/
|
||||
#define SWAP_TS(ull) ((ull & 0xff00000000000000LL) >> 56) | \
|
||||
((ull & 0x00ff000000000000LL) >> 40) | \
|
||||
((ull & 0x0000ff0000000000LL) >> 24) | \
|
||||
((ull & 0x000000ff00000000LL) >> 8) | \
|
||||
((ull & 0x00000000ff000000LL) << 8) | \
|
||||
((ull & 0x0000000000ff0000LL) << 24) | \
|
||||
((ull & 0x000000000000ff00LL) << 40) | \
|
||||
((ull & 0x00000000000000ffLL) << 56)
|
||||
|
||||
|
||||
#ifdef DAG_ONLY
|
||||
/* This code is required when compiling for a DAG device only. */
|
||||
#include "pcap-dag.h"
|
||||
|
||||
/* Replace dag function names with pcap equivalent. */
|
||||
#define dag_open_live pcap_open_live
|
||||
#define dag_platform_finddevs pcap_platform_finddevs
|
||||
#endif /* DAG_ONLY */
|
||||
|
||||
static int dag_setfilter(pcap_t *p, struct bpf_program *fp);
|
||||
static int dag_stats(pcap_t *p, struct pcap_stat *ps);
|
||||
static int dag_set_datalink(pcap_t *p, int dlt);
|
||||
static int dag_get_datalink(pcap_t *p);
|
||||
static int dag_setnonblock(pcap_t *p, int nonblock, char *errbuf);
|
||||
|
||||
static void
|
||||
delete_pcap_dag(pcap_t *p)
|
||||
{
|
||||
pcap_dag_node_t *curr = NULL, *prev = NULL;
|
||||
|
||||
for (prev = NULL, curr = pcap_dags; curr != NULL && curr->p != p; prev = curr, curr = curr->next) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
if (curr != NULL && curr->p == p) {
|
||||
if (prev != NULL) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
pcap_dags = curr->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Performs a graceful shutdown of the DAG card, frees dynamic memory held
|
||||
* in the pcap_t structure, and closes the file descriptor for the DAG card.
|
||||
*/
|
||||
|
||||
static void
|
||||
dag_platform_close(pcap_t *p)
|
||||
{
|
||||
|
||||
if (p != NULL) {
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
if(dag_stop_stream(p->fd, p->md.dag_stream) < 0)
|
||||
fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
|
||||
|
||||
if(dag_detach_stream(p->fd, p->md.dag_stream) < 0)
|
||||
fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
|
||||
#else
|
||||
if(dag_stop(p->fd) < 0)
|
||||
fprintf(stderr,"dag_stop: %s\n", strerror(errno));
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
if(dag_close(p->fd) < 0)
|
||||
fprintf(stderr,"dag_close: %s\n", strerror(errno));
|
||||
#ifdef linux
|
||||
free(p->md.device);
|
||||
#endif
|
||||
}
|
||||
delete_pcap_dag(p);
|
||||
/* Note: don't need to call close(p->fd) here as dag_close(p->fd) does this. */
|
||||
}
|
||||
|
||||
static void
|
||||
atexit_handler(void)
|
||||
{
|
||||
while (pcap_dags != NULL) {
|
||||
if (pcap_dags->pid == getpid()) {
|
||||
dag_platform_close(pcap_dags->p);
|
||||
} else {
|
||||
delete_pcap_dag(pcap_dags->p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
new_pcap_dag(pcap_t *p)
|
||||
{
|
||||
pcap_dag_node_t *node = NULL;
|
||||
|
||||
if ((node = malloc(sizeof(pcap_dag_node_t))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!atexit_handler_installed) {
|
||||
atexit(atexit_handler);
|
||||
atexit_handler_installed = 1;
|
||||
}
|
||||
|
||||
node->next = pcap_dags;
|
||||
node->p = p;
|
||||
node->pid = getpid();
|
||||
|
||||
pcap_dags = node;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read at most max_packets from the capture stream and call the callback
|
||||
* for each of them. Returns the number of packets handled, -1 if an
|
||||
* error occured, or -2 if we were told to break out of the loop.
|
||||
*/
|
||||
static int
|
||||
dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
unsigned int processed = 0;
|
||||
int flags = p->md.dag_offset_flags;
|
||||
unsigned int nonblocking = flags & DAGF_NONBLOCK;
|
||||
|
||||
/* Get the next bufferful of packets (if necessary). */
|
||||
while (p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size) {
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
/* dag_advance_stream() will block (unless nonblock is called)
|
||||
* until 64kB of data has accumulated.
|
||||
* If to_ms is set, it will timeout before 64kB has accumulated.
|
||||
* We wait for 64kB because processing a few packets at a time
|
||||
* can cause problems at high packet rates (>200kpps) due
|
||||
* to inefficiencies.
|
||||
* This does mean if to_ms is not specified the capture may 'hang'
|
||||
* for long periods if the data rate is extremely slow (<64kB/sec)
|
||||
* If non-block is specified it will return immediately. The user
|
||||
* is then responsible for efficiency.
|
||||
*/
|
||||
p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, (void**)&(p->md.dag_mem_bottom));
|
||||
#else
|
||||
/* dag_offset does not support timeouts */
|
||||
p->md.dag_mem_top = dag_offset(p->fd, &(p->md.dag_mem_bottom), flags);
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
|
||||
if (nonblocking && (p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size))
|
||||
{
|
||||
/* Pcap is configured to process only available packets, and there aren't any, return immediately. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!nonblocking &&
|
||||
p->md.dag_timeout &&
|
||||
(p->md.dag_mem_top - p->md.dag_mem_bottom < dag_record_size))
|
||||
{
|
||||
/* Blocking mode, but timeout set and no data has arrived, return anyway.*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Process the packets. */
|
||||
while (p->md.dag_mem_top - p->md.dag_mem_bottom >= dag_record_size) {
|
||||
|
||||
unsigned short packet_len = 0;
|
||||
int caplen = 0;
|
||||
struct pcap_pkthdr pcap_header;
|
||||
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
dag_record_t *header = (dag_record_t *)(p->md.dag_mem_bottom);
|
||||
#else
|
||||
dag_record_t *header = (dag_record_t *)(p->md.dag_mem_base + p->md.dag_mem_bottom);
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
|
||||
u_char *dp = ((u_char *)header) + dag_record_size;
|
||||
unsigned short rlen;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
rlen = ntohs(header->rlen);
|
||||
if (rlen < dag_record_size)
|
||||
{
|
||||
strncpy(p->errbuf, "dag_read: record too small", PCAP_ERRBUF_SIZE);
|
||||
return -1;
|
||||
}
|
||||
p->md.dag_mem_bottom += rlen;
|
||||
|
||||
switch(header->type) {
|
||||
case TYPE_AAL5:
|
||||
case TYPE_ATM:
|
||||
#ifdef TYPE_MC_ATM
|
||||
case TYPE_MC_ATM:
|
||||
if (header->type == TYPE_MC_ATM) {
|
||||
caplen = packet_len = ATM_CELL_SIZE;
|
||||
dp+=4;
|
||||
}
|
||||
#endif
|
||||
#ifdef TYPE_MC_AAL5
|
||||
case TYPE_MC_AAL5:
|
||||
if (header->type == TYPE_MC_AAL5) {
|
||||
packet_len = ntohs(header->wlen);
|
||||
caplen = rlen - dag_record_size - 4;
|
||||
dp+=4;
|
||||
}
|
||||
#endif
|
||||
if (header->type == TYPE_AAL5) {
|
||||
packet_len = ntohs(header->wlen);
|
||||
caplen = rlen - dag_record_size;
|
||||
} else if(header->type == TYPE_ATM) {
|
||||
caplen = packet_len = ATM_CELL_SIZE;
|
||||
}
|
||||
if (p->linktype == DLT_SUNATM) {
|
||||
struct sunatm_hdr *sunatm = (struct sunatm_hdr *)dp;
|
||||
unsigned long rawatm;
|
||||
|
||||
rawatm = ntohl(*((unsigned long *)dp));
|
||||
sunatm->vci = htons((rawatm >> 4) & 0xffff);
|
||||
sunatm->vpi = (rawatm >> 20) & 0x00ff;
|
||||
sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) |
|
||||
((sunatm->vpi == 0 && sunatm->vci == htons(5)) ? 6 :
|
||||
((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 :
|
||||
((dp[ATM_HDR_SIZE] == 0xaa &&
|
||||
dp[ATM_HDR_SIZE+1] == 0xaa &&
|
||||
dp[ATM_HDR_SIZE+2] == 0x03) ? 2 : 1)));
|
||||
|
||||
} else {
|
||||
packet_len -= ATM_HDR_SIZE;
|
||||
caplen -= ATM_HDR_SIZE;
|
||||
dp += ATM_HDR_SIZE;
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef TYPE_COLOR_ETH
|
||||
case TYPE_COLOR_ETH:
|
||||
#endif
|
||||
case TYPE_ETH:
|
||||
packet_len = ntohs(header->wlen);
|
||||
packet_len -= (p->md.dag_fcs_bits >> 3);
|
||||
caplen = rlen - dag_record_size - 2;
|
||||
if (caplen > packet_len) {
|
||||
caplen = packet_len;
|
||||
}
|
||||
dp += 2;
|
||||
break;
|
||||
#ifdef TYPE_COLOR_HDLC_POS
|
||||
case TYPE_COLOR_HDLC_POS:
|
||||
#endif
|
||||
case TYPE_HDLC_POS:
|
||||
packet_len = ntohs(header->wlen);
|
||||
packet_len -= (p->md.dag_fcs_bits >> 3);
|
||||
caplen = rlen - dag_record_size;
|
||||
if (caplen > packet_len) {
|
||||
caplen = packet_len;
|
||||
}
|
||||
break;
|
||||
#ifdef TYPE_MC_HDLC
|
||||
case TYPE_MC_HDLC:
|
||||
packet_len = ntohs(header->wlen);
|
||||
packet_len -= (p->md.dag_fcs_bits >> 3);
|
||||
caplen = rlen - dag_record_size - 4;
|
||||
if (caplen > packet_len) {
|
||||
caplen = packet_len;
|
||||
}
|
||||
dp += 4;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
|
||||
/* Count lost packets. */
|
||||
switch(header->type) {
|
||||
#ifdef TYPE_COLOR_HDLC_POS
|
||||
/* in this type the color value overwrites the lctr */
|
||||
case TYPE_COLOR_HDLC_POS:
|
||||
break;
|
||||
#endif
|
||||
#ifdef TYPE_COLOR_ETH
|
||||
/* in this type the color value overwrites the lctr */
|
||||
case TYPE_COLOR_ETH:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (header->lctr) {
|
||||
if (p->md.stat.ps_drop > (UINT_MAX - ntohs(header->lctr))) {
|
||||
p->md.stat.ps_drop = UINT_MAX;
|
||||
} else {
|
||||
p->md.stat.ps_drop += ntohs(header->lctr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the packet filter if there is one. */
|
||||
if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
|
||||
/* convert between timestamp formats */
|
||||
register unsigned long long ts;
|
||||
|
||||
if (IS_BIGENDIAN()) {
|
||||
ts = SWAP_TS(header->ts);
|
||||
} else {
|
||||
ts = header->ts;
|
||||
}
|
||||
|
||||
pcap_header.ts.tv_sec = ts >> 32;
|
||||
ts = (ts & 0xffffffffULL) * 1000000;
|
||||
ts += 0x80000000; /* rounding */
|
||||
pcap_header.ts.tv_usec = ts >> 32;
|
||||
if (pcap_header.ts.tv_usec >= 1000000) {
|
||||
pcap_header.ts.tv_usec -= 1000000;
|
||||
pcap_header.ts.tv_sec++;
|
||||
}
|
||||
|
||||
/* Fill in our own header data */
|
||||
pcap_header.caplen = caplen;
|
||||
pcap_header.len = packet_len;
|
||||
|
||||
/* Count the packet. */
|
||||
p->md.stat.ps_recv++;
|
||||
|
||||
/* Call the user supplied callback function */
|
||||
callback(user, &pcap_header, dp);
|
||||
|
||||
/* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
|
||||
processed++;
|
||||
if (processed == cnt)
|
||||
{
|
||||
/* Reached the user-specified limit. */
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
static int
|
||||
dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
|
||||
{
|
||||
strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a handle for a live capture from the given DAG device. Passing a NULL
|
||||
* device will result in a failure. The promisc flag is ignored because DAG
|
||||
* cards are always promiscuous. The to_ms parameter is also ignored as it is
|
||||
* not supported in hardware.
|
||||
*
|
||||
* See also pcap(3).
|
||||
*/
|
||||
pcap_t *
|
||||
dag_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf)
|
||||
{
|
||||
char conf[30]; /* dag configure string */
|
||||
pcap_t *handle;
|
||||
char *s;
|
||||
int n;
|
||||
daginf_t* daginf;
|
||||
char * newDev;
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
uint32_t mindata;
|
||||
struct timeval maxwait;
|
||||
struct timeval poll;
|
||||
#endif
|
||||
|
||||
if (device == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "device is NULL: %s", pcap_strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate a handle for this session. */
|
||||
|
||||
handle = malloc(sizeof(*handle));
|
||||
if (handle == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc %s: %s", device, pcap_strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize some components of the pcap structure. */
|
||||
|
||||
memset(handle, 0, sizeof(*handle));
|
||||
|
||||
newDev = (char *)malloc(strlen(device) + 16);
|
||||
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
|
||||
/* Parse input name to get dag device and stream number if provided */
|
||||
if (dag_parse_name(device, newDev, strlen(device) + 16, &handle->md.dag_stream) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s\n", pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
device = newDev;
|
||||
|
||||
if (handle->md.dag_stream%2) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture\n");
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
if (strstr(device, "/dev") == NULL) {
|
||||
newDev[0] = '\0';
|
||||
strcat(newDev, "/dev/");
|
||||
strcat(newDev,device);
|
||||
device = newDev;
|
||||
} else {
|
||||
device = strdup(device);
|
||||
}
|
||||
|
||||
if (device == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "str_dup: %s\n", pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
|
||||
/* setup device parameters */
|
||||
if((handle->fd = dag_open((char *)device)) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_open %s: %s", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
/* Open requested stream. Can fail if already locked or on error */
|
||||
if (dag_attach_stream(handle->fd, handle->md.dag_stream, 0, 0) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_attach_stream: %s\n", pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Set up default poll parameters for stream
|
||||
* Can be overridden by pcap_set_nonblock()
|
||||
*/
|
||||
if (dag_get_stream_poll(handle->fd, handle->md.dag_stream,
|
||||
&mindata, &maxwait, &poll) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Amount of data to collect in Bytes before calling callbacks.
|
||||
* Important for efficiency, but can introduce latency
|
||||
* at low packet rates if to_ms not set!
|
||||
*/
|
||||
mindata = 65536;
|
||||
|
||||
/* Obey to_ms if supplied. This is a good idea!
|
||||
* Recommend 10-100ms. Calls will time out even if no data arrived.
|
||||
*/
|
||||
maxwait.tv_sec = to_ms/1000;
|
||||
maxwait.tv_usec = (to_ms%1000) * 1000;
|
||||
|
||||
if (dag_set_stream_poll(handle->fd, handle->md.dag_stream,
|
||||
mindata, &maxwait, &poll) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#else
|
||||
if((handle->md.dag_mem_base = dag_mmap(handle->fd)) == MAP_FAILED) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,"dag_mmap %s: %s\n", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
|
||||
/* set the card snap length to the specified snaplen parameter */
|
||||
if (snaplen == 0 || snaplen > MAX_DAG_SNAPLEN) {
|
||||
snaplen = MAX_DAG_SNAPLEN;
|
||||
} else if (snaplen < MIN_DAG_SNAPLEN) {
|
||||
snaplen = MIN_DAG_SNAPLEN;
|
||||
}
|
||||
/* snap len has to be a multiple of 4 */
|
||||
snprintf(conf, 30, "varlen slen=%d", (snaplen + 3) & ~3);
|
||||
|
||||
if(dag_configure(handle->fd, conf) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,"dag_configure %s: %s\n", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
if(dag_start_stream(handle->fd, handle->md.dag_stream) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s\n", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
if(dag_start(handle->fd) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "dag_start %s: %s\n", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
|
||||
/*
|
||||
* Important! You have to ensure bottom is properly
|
||||
* initialized to zero on startup, it won't give you
|
||||
* a compiler warning if you make this mistake!
|
||||
*/
|
||||
handle->md.dag_mem_bottom = 0;
|
||||
handle->md.dag_mem_top = 0;
|
||||
handle->md.dag_fcs_bits = 32;
|
||||
|
||||
/* Query the card first for special cases. */
|
||||
daginf = dag_info(handle->fd);
|
||||
if ((0x4200 == daginf->device_code) || (0x4230 == daginf->device_code))
|
||||
{
|
||||
/* DAG 4.2S and 4.23S already strip the FCS. Stripping the final word again truncates the packet. */
|
||||
handle->md.dag_fcs_bits = 0;
|
||||
}
|
||||
|
||||
/* Then allow an environment variable to override. */
|
||||
if ((s = getenv("ERF_FCS_BITS")) != NULL) {
|
||||
if ((n = atoi(s)) == 0 || n == 16|| n == 32) {
|
||||
handle->md.dag_fcs_bits = n;
|
||||
} else {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"pcap_open_live %s: bad ERF_FCS_BITS value (%d) in environment\n", device, n);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
handle->snapshot = snaplen;
|
||||
handle->md.dag_timeout = to_ms;
|
||||
|
||||
handle->linktype = -1;
|
||||
if (dag_get_datalink(handle) < 0) {
|
||||
strcpy(ebuf, handle->errbuf);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
handle->bufsize = 0;
|
||||
|
||||
if (new_pcap_dag(handle) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "new_pcap_dag %s: %s\n", device, pcap_strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* "select()" and "poll()" don't work on DAG device descriptors.
|
||||
*/
|
||||
handle->selectable_fd = -1;
|
||||
|
||||
#ifdef linux
|
||||
handle->md.device = (char *)device;
|
||||
handle->md.timeout = to_ms;
|
||||
#else
|
||||
free((char *)device);
|
||||
device = NULL;
|
||||
#endif
|
||||
|
||||
handle->read_op = dag_read;
|
||||
handle->inject_op = dag_inject;
|
||||
handle->setfilter_op = dag_setfilter;
|
||||
handle->setdirection_op = NULL; /* Not implemented.*/
|
||||
handle->set_datalink_op = dag_set_datalink;
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = dag_setnonblock;
|
||||
handle->stats_op = dag_stats;
|
||||
handle->close_op = dag_platform_close;
|
||||
|
||||
return handle;
|
||||
|
||||
fail:
|
||||
if (newDev != NULL) {
|
||||
free((char *)newDev);
|
||||
}
|
||||
if (handle != NULL) {
|
||||
/*
|
||||
* Get rid of any link-layer type list we allocated.
|
||||
*/
|
||||
if (handle->dlt_list != NULL) {
|
||||
free(handle->dlt_list);
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
dag_stats(pcap_t *p, struct pcap_stat *ps) {
|
||||
/* This needs to be filled out correctly. Hopefully a dagapi call will
|
||||
provide all necessary information.
|
||||
*/
|
||||
/*p->md.stat.ps_recv = 0;*/
|
||||
/*p->md.stat.ps_drop = 0;*/
|
||||
|
||||
*ps = p->md.stat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Simply submit all possible dag names as candidates.
|
||||
* pcap_add_if() internally tests each candidate with pcap_open_live(),
|
||||
* so any non-existent devices are dropped.
|
||||
* For 2.5 try all rx stream names as well.
|
||||
*/
|
||||
int
|
||||
dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
|
||||
{
|
||||
char name[12]; /* XXX - pick a size */
|
||||
int ret = 0;
|
||||
int c;
|
||||
|
||||
/* Try all the DAGs 0-9 */
|
||||
for (c = 0; c < 9; c++) {
|
||||
snprintf(name, 12, "dag%d", c);
|
||||
if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
ret = -1;
|
||||
}
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
{
|
||||
int stream;
|
||||
for(stream=0;stream<16;stream+=2) {
|
||||
snprintf(name, 10, "dag%d:%d", c, stream);
|
||||
if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Installs the given bpf filter program in the given pcap structure. There is
|
||||
* no attempt to store the filter in kernel memory as that is not supported
|
||||
* with DAG cards.
|
||||
*/
|
||||
static int
|
||||
dag_setfilter(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
if (!p)
|
||||
return -1;
|
||||
if (!fp) {
|
||||
strncpy(p->errbuf, "setfilter: No filter specified",
|
||||
sizeof(p->errbuf));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Make our private copy of the filter */
|
||||
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
return -1;
|
||||
|
||||
p->md.use_bpf = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
dag_set_datalink(pcap_t *p, int dlt)
|
||||
{
|
||||
p->linktype = dlt;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
/*
|
||||
* Set non-blocking mode on the FD.
|
||||
* XXX - is that necessary? If not, don't bother calling it,
|
||||
* and have a "dag_getnonblock()" function that looks at
|
||||
* "p->md.dag_offset_flags".
|
||||
*/
|
||||
if (pcap_setnonblock_fd(p, nonblock, errbuf) < 0)
|
||||
return (-1);
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
{
|
||||
uint32_t mindata;
|
||||
struct timeval maxwait;
|
||||
struct timeval poll;
|
||||
|
||||
if (dag_get_stream_poll(p->fd, p->md.dag_stream,
|
||||
&mindata, &maxwait, &poll) < 0) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Amount of data to collect in Bytes before calling callbacks.
|
||||
* Important for efficiency, but can introduce latency
|
||||
* at low packet rates if to_ms not set!
|
||||
*/
|
||||
if(nonblock)
|
||||
mindata = 0;
|
||||
else
|
||||
mindata = 65536;
|
||||
|
||||
if (dag_set_stream_poll(p->fd, p->md.dag_stream,
|
||||
mindata, &maxwait, &poll) < 0) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
if (nonblock) {
|
||||
p->md.dag_offset_flags |= DAGF_NONBLOCK;
|
||||
} else {
|
||||
p->md.dag_offset_flags &= ~DAGF_NONBLOCK;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
dag_get_datalink(pcap_t *p)
|
||||
{
|
||||
int daglinktype;
|
||||
|
||||
if (p->dlt_list == NULL && (p->dlt_list = malloc(2*sizeof(*(p->dlt_list)))) == NULL) {
|
||||
(void)snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Check the type through a dagapi call. */
|
||||
daglinktype = dag_linktype(p->fd);
|
||||
|
||||
switch(daglinktype) {
|
||||
|
||||
case TYPE_HDLC_POS:
|
||||
case TYPE_COLOR_HDLC_POS:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_count = 2;
|
||||
p->dlt_list[0] = DLT_CHDLC;
|
||||
p->dlt_list[1] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[2] = DLT_FRELAY;
|
||||
}
|
||||
p->linktype = DLT_CHDLC;
|
||||
break;
|
||||
|
||||
case TYPE_ETH:
|
||||
case TYPE_COLOR_ETH:
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_count = 2;
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
}
|
||||
p->linktype = DLT_EN10MB;
|
||||
break;
|
||||
|
||||
case TYPE_AAL5:
|
||||
case TYPE_ATM:
|
||||
case TYPE_MC_ATM:
|
||||
case TYPE_MC_AAL5:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_count = 2;
|
||||
p->dlt_list[0] = DLT_ATM_RFC1483;
|
||||
p->dlt_list[1] = DLT_SUNATM;
|
||||
}
|
||||
p->linktype = DLT_ATM_RFC1483;
|
||||
break;
|
||||
|
||||
case TYPE_MC_HDLC:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_count = 4;
|
||||
p->dlt_list[0] = DLT_CHDLC;
|
||||
p->dlt_list[1] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[2] = DLT_FRELAY;
|
||||
p->dlt_list[3] = DLT_MTP2;
|
||||
}
|
||||
p->linktype = DLT_CHDLC;
|
||||
break;
|
||||
|
||||
case TYPE_LEGACY:
|
||||
p->linktype = DLT_NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(p->errbuf, sizeof(p->errbuf), "unknown DAG linktype %d\n", daglinktype);
|
||||
return (-1);
|
||||
|
||||
}
|
||||
|
||||
return p->linktype;
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* pcap-dag.c: Packet capture interface for Endace DAG card.
|
||||
*
|
||||
* The functionality of this code attempts to mimic that of pcap-linux as much
|
||||
* as possible. This code is only needed when compiling in the DAG card code
|
||||
* at the same time as another type of device.
|
||||
*
|
||||
* Author: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-dag.h,v 1.1.1.1 2006/02/27 15:45:47 drochner Exp $ (LBL)
|
||||
*/
|
||||
|
||||
pcap_t *dag_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf);
|
||||
int dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf);
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,227 +0,0 @@
|
|||
/*
|
||||
* Internal details for libpcap on DOS.
|
||||
* 32-bit targets: djgpp, Pharlap or DOS4GW.
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-dos.h,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef __PCAP_DOS_H
|
||||
#define __PCAP_DOS_H
|
||||
|
||||
#ifdef __DJGPP__
|
||||
#include <pc.h> /* simple non-conio kbhit */
|
||||
#else
|
||||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
typedef int BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned long DWORD;
|
||||
typedef BYTE ETHER[6];
|
||||
|
||||
#define ETH_ALEN sizeof(ETHER) /* Ether address length */
|
||||
#define ETH_HLEN (2*ETH_ALEN+2) /* Ether header length */
|
||||
#define ETH_MTU 1500
|
||||
#define ETH_MIN 60
|
||||
#define ETH_MAX (ETH_MTU+ETH_HLEN)
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define PHARLAP 1
|
||||
#define DJGPP 2
|
||||
#define DOS4GW 4
|
||||
|
||||
#ifdef __DJGPP__
|
||||
#undef DOSX
|
||||
#define DOSX DJGPP
|
||||
#endif
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
#undef DOSX
|
||||
#define DOSX DOS4GW
|
||||
#endif
|
||||
|
||||
#ifdef __HIGHC__
|
||||
#include <pharlap.h>
|
||||
#undef DOSX
|
||||
#define DOSX PHARLAP
|
||||
#define inline
|
||||
#else
|
||||
typedef unsigned int UINT;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GNUC__) || defined(__HIGHC__)
|
||||
typedef unsigned long long uint64;
|
||||
typedef unsigned long long QWORD;
|
||||
#endif
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
typedef unsigned __int64 uint64;
|
||||
typedef unsigned __int64 QWORD;
|
||||
#endif
|
||||
|
||||
#define ARGSUSED(x) (void) x
|
||||
|
||||
#if defined (__SMALL__) || defined(__LARGE__)
|
||||
#define DOSX 0
|
||||
|
||||
#elif !defined(DOSX)
|
||||
#error DOSX not defined; 1 = PharLap, 2 = djgpp, 4 = DOS4GW
|
||||
#endif
|
||||
|
||||
#ifdef __HIGHC__
|
||||
#define min(a,b) _min(a,b)
|
||||
#define max(a,b) _max(a,b)
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a) < (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#if !defined(_U_) && defined(__GNUC__)
|
||||
#define _U_ __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#ifndef _U_
|
||||
#define _U_
|
||||
#endif
|
||||
|
||||
#if defined(USE_32BIT_DRIVERS)
|
||||
#include "msdos/pm_drvr/lock.h"
|
||||
|
||||
#ifndef RECEIVE_QUEUE_SIZE
|
||||
#define RECEIVE_QUEUE_SIZE 60
|
||||
#endif
|
||||
|
||||
#ifndef RECEIVE_BUF_SIZE
|
||||
#define RECEIVE_BUF_SIZE (ETH_MAX+20)
|
||||
#endif
|
||||
|
||||
extern struct device el2_dev LOCKED_VAR; /* 3Com EtherLink II */
|
||||
extern struct device el3_dev LOCKED_VAR; /* EtherLink III */
|
||||
extern struct device tc59_dev LOCKED_VAR; /* 3Com Vortex Card (?) */
|
||||
extern struct device tc515_dev LOCKED_VAR;
|
||||
extern struct device tc90x_dev LOCKED_VAR;
|
||||
extern struct device tc90bcx_dev LOCKED_VAR;
|
||||
extern struct device wd_dev LOCKED_VAR;
|
||||
extern struct device ne_dev LOCKED_VAR;
|
||||
extern struct device acct_dev LOCKED_VAR;
|
||||
extern struct device cs89_dev LOCKED_VAR;
|
||||
extern struct device rtl8139_dev LOCKED_VAR;
|
||||
|
||||
struct rx_ringbuf {
|
||||
volatile int in_index; /* queue index head */
|
||||
int out_index; /* queue index tail */
|
||||
int elem_size; /* size of each element */
|
||||
int num_elem; /* number of elements */
|
||||
char *buf_start; /* start of buffer pool */
|
||||
};
|
||||
|
||||
struct rx_elem {
|
||||
DWORD size; /* size copied to this element */
|
||||
BYTE data[ETH_MAX+10]; /* add some margin. data[0] should be */
|
||||
}; /* dword aligned */
|
||||
|
||||
extern BYTE *get_rxbuf (int len) LOCKED_FUNC;
|
||||
extern int peek_rxbuf (BYTE **buf);
|
||||
extern int release_rxbuf (BYTE *buf);
|
||||
|
||||
#else
|
||||
#define LOCKED_VAR
|
||||
#define LOCKED_FUNC
|
||||
|
||||
struct device {
|
||||
const char *name;
|
||||
const char *long_name;
|
||||
DWORD base_addr; /* device I/O address */
|
||||
int irq; /* device IRQ number */
|
||||
int dma; /* DMA channel */
|
||||
DWORD mem_start; /* shared mem start */
|
||||
DWORD mem_end; /* shared mem end */
|
||||
DWORD rmem_start; /* shmem "recv" start */
|
||||
DWORD rmem_end; /* shared "recv" end */
|
||||
|
||||
struct device *next; /* next device in list */
|
||||
|
||||
/* interface service routines */
|
||||
int (*probe)(struct device *dev);
|
||||
int (*open) (struct device *dev);
|
||||
void (*close)(struct device *dev);
|
||||
int (*xmit) (struct device *dev, const void *buf, int len);
|
||||
void *(*get_stats)(struct device *dev);
|
||||
void (*set_multicast_list)(struct device *dev);
|
||||
|
||||
/* driver-to-pcap receive buffer routines */
|
||||
int (*copy_rx_buf) (BYTE *buf, int max); /* rx-copy (pktdrvr only) */
|
||||
BYTE *(*get_rx_buf) (int len); /* rx-buf fetch/enqueue */
|
||||
int (*peek_rx_buf) (BYTE **buf); /* rx-non-copy at queue */
|
||||
int (*release_rx_buf) (BYTE *buf); /* release after peek */
|
||||
|
||||
WORD flags; /* Low-level status flags. */
|
||||
void *priv; /* private data */
|
||||
};
|
||||
|
||||
/*
|
||||
* Network device statistics
|
||||
*/
|
||||
typedef struct net_device_stats {
|
||||
DWORD rx_packets; /* total packets received */
|
||||
DWORD tx_packets; /* total packets transmitted */
|
||||
DWORD rx_bytes; /* total bytes received */
|
||||
DWORD tx_bytes; /* total bytes transmitted */
|
||||
DWORD rx_errors; /* bad packets received */
|
||||
DWORD tx_errors; /* packet transmit problems */
|
||||
DWORD rx_dropped; /* no space in Rx buffers */
|
||||
DWORD tx_dropped; /* no space available for Tx */
|
||||
DWORD multicast; /* multicast packets received */
|
||||
|
||||
/* detailed rx_errors: */
|
||||
DWORD rx_length_errors;
|
||||
DWORD rx_over_errors; /* recv'r overrun error */
|
||||
DWORD rx_osize_errors; /* recv'r over-size error */
|
||||
DWORD rx_crc_errors; /* recv'd pkt with crc error */
|
||||
DWORD rx_frame_errors; /* recv'd frame alignment error */
|
||||
DWORD rx_fifo_errors; /* recv'r fifo overrun */
|
||||
DWORD rx_missed_errors; /* recv'r missed packet */
|
||||
|
||||
/* detailed tx_errors */
|
||||
DWORD tx_aborted_errors;
|
||||
DWORD tx_carrier_errors;
|
||||
DWORD tx_fifo_errors;
|
||||
DWORD tx_heartbeat_errors;
|
||||
DWORD tx_window_errors;
|
||||
DWORD tx_collisions;
|
||||
DWORD tx_jabbers;
|
||||
} NET_STATS;
|
||||
#endif
|
||||
|
||||
extern struct device *active_dev LOCKED_VAR;
|
||||
extern const struct device *dev_base LOCKED_VAR;
|
||||
extern struct device *probed_dev;
|
||||
|
||||
extern int pcap_pkt_debug;
|
||||
|
||||
extern void _w32_os_yield (void); /* Watt-32's misc.c */
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define PCAP_ASSERT(x) ((void)0)
|
||||
|
||||
#else
|
||||
void pcap_assert (const char *what, const char *file, unsigned line);
|
||||
|
||||
#define PCAP_ASSERT(x) do { \
|
||||
if (!(x)) \
|
||||
pcap_assert (#x, __FILE__, __LINE__); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __PCAP_DOS_H */
|
|
@ -1,235 +0,0 @@
|
|||
/*
|
||||
* Stanford Enetfilter subroutines for tcpdump
|
||||
*
|
||||
* Based on the MERIT NNstat etherifrt.c and the Ultrix pcap-pf.c
|
||||
* subroutines.
|
||||
*
|
||||
* Rayan Zachariassen, CA*Net
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-enet.c,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <pcap-bpf.h>
|
||||
#include <net/enet.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
struct packet_header {
|
||||
#ifdef IBMRTPC
|
||||
struct LengthWords length;
|
||||
struct tap_header tap;
|
||||
#endif /* IBMRTPC */
|
||||
u_char packet[8]
|
||||
};
|
||||
|
||||
extern int errno;
|
||||
|
||||
#define BUFSPACE (4*1024)
|
||||
|
||||
/* Forwards */
|
||||
static void efReadError(int, char *);
|
||||
|
||||
void
|
||||
readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
|
||||
{
|
||||
#ifdef IBMRTPC
|
||||
register struct packet_header *ph;
|
||||
register u_char *bp;
|
||||
register int inc;
|
||||
#else /* !IBMRTPC */
|
||||
static struct timeval tv = { 0 };
|
||||
#endif /* IBMRTPC */
|
||||
register int cc, caplen;
|
||||
register struct bpf_insn *fcode = fp->bf_insns;
|
||||
union {
|
||||
struct packet_header hdr;
|
||||
u_char p[BUFSPACE];
|
||||
u_short s;
|
||||
} buf;
|
||||
|
||||
while (1) {
|
||||
if ((cc = read(if_fd, (char *)buf.p, sizeof(buf))) < 0)
|
||||
efReadError(if_fd, "reader");
|
||||
|
||||
#ifdef IBMRTPC
|
||||
/*
|
||||
* Loop through each packet.
|
||||
*/
|
||||
bp = buf.p;
|
||||
while (cc > 0) {
|
||||
ph = (struct packet_header *)bp;
|
||||
caplen = ph->tap.th_wirelen > snaplen ? snaplen : ph->tap
|
||||
.th_wirelen ;
|
||||
if (bpf_filter(fcode, (char *)ph->packet,
|
||||
ph->tap.th_wirelen, caplen)) {
|
||||
if (cnt >= 0 && --cnt < 0)
|
||||
goto out;
|
||||
(*printit)((char *)ph->packet,
|
||||
(struct timeval *)ph->tap.th_timestamp,
|
||||
ph->tap.th_wirelen, caplen);
|
||||
}
|
||||
inc = ph->length.PacketOffset;
|
||||
cc -= inc;
|
||||
bp += inc;
|
||||
}
|
||||
#else /* !IBMRTPC */
|
||||
caplen = cc > snaplen ? snaplen : cc ;
|
||||
if (bpf_filter(fcode, buf.hdr.packet, cc, caplen)) {
|
||||
if (cnt >= 0 && --cnt < 0)
|
||||
goto out;
|
||||
(*printit)(buf.hdr.packet, &tv, cc, caplen);
|
||||
}
|
||||
#endif /* IBMRTPC */
|
||||
}
|
||||
out:
|
||||
wrapup(if_fd);
|
||||
}
|
||||
|
||||
/* Call ONLY if read() has returned an error on packet filter */
|
||||
static void
|
||||
efReadError(int fid, char *msg)
|
||||
{
|
||||
if (errno == EINVAL) { /* read MAXINT bytes already! */
|
||||
if (lseek(fid, 0, 0) < 0) {
|
||||
perror("tcpdump: efReadError/lseek");
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
else {
|
||||
(void) fprintf(stderr, "tcpdump: ");
|
||||
perror(msg);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wrapup(int fd)
|
||||
{
|
||||
#ifdef IBMRTPC
|
||||
struct enstats es;
|
||||
|
||||
if (ioctl(fd, EIOSTATS, &es) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOSTATS error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "%d packets queued", es.enStat_Rcnt);
|
||||
if (es.enStat_Rdrops > 0)
|
||||
fprintf(stderr, ", %d dropped", es.enStat_Rdrops);
|
||||
if (es.enStat_Reads > 0)
|
||||
fprintf(stderr, ", %d tcpdump %s", es.enStat_Reads,
|
||||
es.enStat_Reads > 1 ? "reads" : "read");
|
||||
if (es.enStat_MaxRead > 1)
|
||||
fprintf(stderr, ", %d packets in largest read",
|
||||
es.enStat_MaxRead);
|
||||
putc('\n', stderr);
|
||||
#endif /* IBMRTPC */
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int
|
||||
initdevice(char *device, int pflag, int *linktype)
|
||||
{
|
||||
struct eniocb ctl;
|
||||
struct enfilter filter;
|
||||
u_int maxwaiting;
|
||||
int if_fd;
|
||||
|
||||
#ifdef IBMRTPC
|
||||
GETENETDEVICE(0, O_RDONLY, &if_fd);
|
||||
#else /* !IBMRTPC */
|
||||
if_fd = open("/dev/enet", O_RDONLY, 0);
|
||||
#endif /* IBMRTPC */
|
||||
|
||||
if (if_fd == -1) {
|
||||
perror("tcpdump: enet open error");
|
||||
error(
|
||||
"your system may not be properly configured; see \"man enet(4)\"");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Get operating parameters. */
|
||||
|
||||
if (ioctl(if_fd, EIOCGETP, (char *)&ctl) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCGETP error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Set operating parameters. */
|
||||
|
||||
#ifdef IBMRTPC
|
||||
ctl.en_rtout = 1 * ctl.en_hz;
|
||||
ctl.en_tr_etherhead = 1;
|
||||
ctl.en_tap_network = 1;
|
||||
ctl.en_multi_packet = 1;
|
||||
ctl.en_maxlen = BUFSPACE;
|
||||
#else /* !IBMRTPC */
|
||||
ctl.en_rtout = 64; /* randomly picked value for HZ */
|
||||
#endif /* IBMRTPC */
|
||||
if (ioctl(if_fd, EIOCSETP, &ctl) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCSETP error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Flush the receive queue, since we've changed
|
||||
the operating parameters and we otherwise might
|
||||
receive data without headers. */
|
||||
|
||||
if (ioctl(if_fd, EIOCFLUSH) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCFLUSH error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Set the receive queue depth to its maximum. */
|
||||
|
||||
maxwaiting = ctl.en_maxwaiting;
|
||||
if (ioctl(if_fd, EIOCSETW, &maxwaiting) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCSETW error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef IBMRTPC
|
||||
/* Clear statistics. */
|
||||
|
||||
if (ioctl(if_fd, EIOCLRSTAT, 0) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCLRSTAT error");
|
||||
exit(-1);
|
||||
}
|
||||
#endif /* IBMRTPC */
|
||||
|
||||
/* Set the filter (accept all packets). */
|
||||
|
||||
filter.enf_Priority = 3;
|
||||
filter.enf_FilterLen = 0;
|
||||
if (ioctl(if_fd, EIOCSETF, &filter) == -1) {
|
||||
perror("tcpdump: enet ioctl EIOCSETF error");
|
||||
exit(-1);
|
||||
}
|
||||
/*
|
||||
* "enetfilter" supports only ethernets.
|
||||
*/
|
||||
*linktype = DLT_EN10MB;
|
||||
|
||||
return(if_fd);
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/pcap-int.h,v 1.2 2006/02/27 15:50:09 drochner 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 */
|
||||
|
||||
#ifdef MSDOS
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
char *device; /* device name */
|
||||
#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 ifindex; /* interface index of device we're bound to */
|
||||
int lo_ifindex; /* interface index of the loopback device */
|
||||
struct pcap *next; /* list of open promiscuous sock_packet pcaps */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
#ifdef HAVE_DAG_STREAMS_API
|
||||
u_char *dag_mem_bottom; /* DAG card current memory bottom pointer */
|
||||
u_char *dag_mem_top; /* DAG card current memory top pointer */
|
||||
#else
|
||||
void *dag_mem_base; /* DAG card memory base address */
|
||||
u_int dag_mem_bottom; /* DAG card current memory bottom offset */
|
||||
u_int dag_mem_top; /* DAG card current memory top offset */
|
||||
#endif /* HAVE_DAG_STREAMS_API */
|
||||
int dag_fcs_bits; /* Number of checksum bits from link layer */
|
||||
int dag_offset_flags; /* Flags to pass to dag_offset(). */
|
||||
int dag_stream; /* DAG stream number */
|
||||
int dag_timeout; /* timeout specified to pcap_open_live.
|
||||
* Same as in linux above, introduce
|
||||
* generally? */
|
||||
#endif /* HAVE_DAG_API */
|
||||
};
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000)
|
||||
#define PCAP_FDDIPAD 3
|
||||
#endif
|
||||
|
||||
struct pcap {
|
||||
#ifdef WIN32
|
||||
ADAPTER *adapter;
|
||||
LPPACKET Packet;
|
||||
int timeout;
|
||||
int nonblock;
|
||||
#else
|
||||
int fd;
|
||||
int selectable_fd;
|
||||
int send_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 */
|
||||
|
||||
#ifdef PCAP_FDDIPAD
|
||||
int fddipad;
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
int inter_packet_wait; /* offline: wait between packets */
|
||||
void (*wait_proc)(void); /* call proc while waiting */
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
/* We're accepting only packets in this direction/these directions. */
|
||||
pcap_direction_t direction;
|
||||
|
||||
/*
|
||||
* Methods.
|
||||
*/
|
||||
int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
|
||||
int (*inject_op)(pcap_t *, const void *, size_t);
|
||||
int (*setfilter_op)(pcap_t *, struct bpf_program *);
|
||||
int (*setdirection_op)(pcap_t *, pcap_direction_t);
|
||||
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;
|
||||
u_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 *);
|
||||
|
||||
#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.
|
||||
*/
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
int pcap_getnonblock_fd(pcap_t *, char *);
|
||||
int pcap_setnonblock_fd(pcap_t *p, int, char *);
|
||||
#endif
|
||||
|
||||
void pcap_close_common(pcap_t *);
|
||||
|
||||
/*
|
||||
* 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 **, const 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 **, const char *, u_int, const char *, char *);
|
||||
struct sockaddr *dup_sockaddr(struct sockaddr *, size_t);
|
||||
int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int,
|
||||
const char *, char *);
|
||||
|
||||
#ifdef WIN32
|
||||
char *pcap_win32strerror(void);
|
||||
#endif
|
||||
|
||||
int install_bpf_program(pcap_t *, struct bpf_program *);
|
||||
|
||||
int pcap_strcasecmp(const char *, const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,91 +0,0 @@
|
|||
/* $NetBSD: pcap-namedb.h,v 1.2 2006/02/27 15:57:17 drochner 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: /cvsroot/src/dist/libpcap/Attic/pcap-namedb.h,v 1.2 2006/02/27 15:57:17 drochner Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_namedb_h
|
||||
#define lib_pcap_namedb_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_nametoportrange(const char *, int *, int *, int *);
|
||||
int pcap_nametoproto(const char *);
|
||||
int pcap_nametoeproto(const char *);
|
||||
int pcap_nametollc(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
|
|
@ -1,356 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-nit.c,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/nit.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The chunk size for NIT. This is the amount of buffering
|
||||
* done for read calls.
|
||||
*/
|
||||
#define CHUNKSIZE (2*1024)
|
||||
|
||||
/*
|
||||
* The total buffer space used by NIT.
|
||||
*/
|
||||
#define BUFSPACE (4*CHUNKSIZE)
|
||||
|
||||
/* Forwards */
|
||||
static int nit_setflags(int, int, int, char *);
|
||||
|
||||
static int
|
||||
pcap_stats_nit(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
|
||||
/*
|
||||
* "ps_recv" counts packets handed to the filter, not packets
|
||||
* that passed the filter. As filtering is done in userland,
|
||||
* this does not include packets dropped because we ran out
|
||||
* of buffer space.
|
||||
*
|
||||
* "ps_drop" presumably counts packets dropped by the socket
|
||||
* because of flow control requirements or resource exhaustion;
|
||||
* it doesn't count packets dropped by the interface driver.
|
||||
* As filtering is done in userland, it counts packets regardless
|
||||
* of whether they would've passed the filter.
|
||||
*
|
||||
* These statistics don't include packets not yet read from the
|
||||
* kernel by libpcap or packets not yet read from libpcap by the
|
||||
* application.
|
||||
*/
|
||||
*ps = p->md.stat;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
register int cc, n;
|
||||
register struct bpf_insn *fcode = p->fcode.bf_insns;
|
||||
register u_char *bp, *cp, *ep;
|
||||
register struct nit_hdr *nh;
|
||||
register int caplen;
|
||||
|
||||
cc = p->cc;
|
||||
if (cc == 0) {
|
||||
cc = read(p->fd, (char *)p->buffer, p->bufsize);
|
||||
if (cc < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return (0);
|
||||
snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
bp = p->buffer;
|
||||
} else
|
||||
bp = p->bp;
|
||||
|
||||
/*
|
||||
* Loop through each packet. The increment expression
|
||||
* rounds up to the next int boundary past the end of
|
||||
* the previous packet.
|
||||
*/
|
||||
n = 0;
|
||||
ep = bp + cc;
|
||||
while (bp < ep) {
|
||||
/*
|
||||
* 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->cc = ep - bp;
|
||||
p->bp = bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
|
||||
nh = (struct nit_hdr *)bp;
|
||||
cp = bp + sizeof(*nh);
|
||||
|
||||
switch (nh->nh_state) {
|
||||
|
||||
case NIT_CATCH:
|
||||
break;
|
||||
|
||||
case NIT_NOMBUF:
|
||||
case NIT_NOCLUSTER:
|
||||
case NIT_NOSPACE:
|
||||
p->md.stat.ps_drop = nh->nh_dropped;
|
||||
continue;
|
||||
|
||||
case NIT_SEQNO:
|
||||
continue;
|
||||
|
||||
default:
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"bad nit state %d", nh->nh_state);
|
||||
return (-1);
|
||||
}
|
||||
++p->md.stat.ps_recv;
|
||||
bp += ((sizeof(struct nit_hdr) + nh->nh_datalen +
|
||||
sizeof(int) - 1) & ~(sizeof(int) - 1));
|
||||
|
||||
caplen = nh->nh_wirelen;
|
||||
if (caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
if (bpf_filter(fcode, cp, nh->nh_wirelen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
h.ts = nh->nh_timestamp;
|
||||
h.len = nh->nh_wirelen;
|
||||
h.caplen = caplen;
|
||||
(*callback)(user, &h, cp);
|
||||
if (++n >= cnt && cnt >= 0) {
|
||||
p->cc = ep - bp;
|
||||
p->bp = bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
}
|
||||
p->cc = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_inject_nit(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
int ret;
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
strncpy(sa.sa_data, device, sizeof(sa.sa_data));
|
||||
ret = sendto(p->fd, buf, size, 0, &sa, sizeof(sa));
|
||||
if (ret == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
|
||||
{
|
||||
struct nit_ioc nioc;
|
||||
|
||||
memset(&nioc, 0, sizeof(nioc));
|
||||
nioc.nioc_bufspace = BUFSPACE;
|
||||
nioc.nioc_chunksize = CHUNKSIZE;
|
||||
nioc.nioc_typetomatch = NT_ALLTYPES;
|
||||
nioc.nioc_snaplen = p->snapshot;
|
||||
nioc.nioc_bufalign = sizeof(int);
|
||||
nioc.nioc_bufoffset = 0;
|
||||
|
||||
if (to_ms != 0) {
|
||||
nioc.nioc_flags |= NF_TIMEOUT;
|
||||
nioc.nioc_timeout.tv_sec = to_ms / 1000;
|
||||
nioc.nioc_timeout.tv_usec = (to_ms * 1000) % 1000000;
|
||||
}
|
||||
if (promisc)
|
||||
nioc.nioc_flags |= NF_PROMISC;
|
||||
|
||||
if (ioctl(fd, SIOCSNIT, &nioc) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNIT: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_close_nit(pcap_t *p)
|
||||
{
|
||||
pcap_close_common(p);
|
||||
if (p->device != NULL)
|
||||
free(p->device);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_nit snit;
|
||||
register pcap_t *p;
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (snaplen < 96)
|
||||
/*
|
||||
* NIT requires a snapshot length of at least 96.
|
||||
*/
|
||||
snaplen = 96;
|
||||
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->fd = fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW);
|
||||
if (fd < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"socket: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
snit.snit_family = AF_NIT;
|
||||
(void)strncpy(snit.snit_ifname, device, NITIFSIZ);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&snit, sizeof(snit))) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"bind: %s: %s", snit.snit_ifname, pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->snapshot = snaplen;
|
||||
nit_setflags(p->fd, promisc, to_ms, ebuf);
|
||||
|
||||
/*
|
||||
* NIT supports only ethernets.
|
||||
*/
|
||||
p->linktype = DLT_EN10MB;
|
||||
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = (u_char *)malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need the device name in order to send packets.
|
||||
*/
|
||||
p->device = strdup(device);
|
||||
if (p->device == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
free(p->buffer);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* "p->fd" is a socket, so "select()" should work on it.
|
||||
*/
|
||||
p->selectable_fd = p->fd;
|
||||
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
}
|
||||
|
||||
p->read_op = pcap_read_nit;
|
||||
p->inject_op = pcap_inject_nit;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_nit;
|
||||
p->close_op = pcap_close_nit;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1990, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Lawrence Berkeley Laboratory,
|
||||
* Berkeley, CA. The name of the University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-nit.h,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)
|
||||
*/
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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: (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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-null.c,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
static char nosup[] = "live packet capture not supported on this system";
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
(void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
|
@ -1,610 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* packet filter subroutines for tcpdump
|
||||
* Extraction/creation by Jeffrey Mogul, DECWRL
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-pf.c,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/pfilt.h>
|
||||
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* Make "pcap.h" not include "pcap-bpf.h"; we are going to include the
|
||||
* native OS version, as we need various BPF ioctls from it.
|
||||
*/
|
||||
#define PCAP_DONT_INCLUDE_PCAP_BPF_H
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static int pcap_setfilter_pf(pcap_t *, struct bpf_program *);
|
||||
|
||||
/*
|
||||
* BUFSPACE is the size in bytes of the packet read buffer. Most tcpdump
|
||||
* applications aren't going to need more than 200 bytes of packet header
|
||||
* and the read shouldn't return more packets than packetfilter's internal
|
||||
* queue limit (bounded at 256).
|
||||
*/
|
||||
#define BUFSPACE (200 * 256)
|
||||
|
||||
static int
|
||||
pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
register u_char *p, *bp;
|
||||
struct bpf_insn *fcode;
|
||||
register int cc, n, buflen, inc;
|
||||
register struct enstamp *sp;
|
||||
#ifdef LBL_ALIGN
|
||||
struct enstamp stamp;
|
||||
#endif
|
||||
#ifdef PCAP_FDDIPAD
|
||||
register int pad;
|
||||
#endif
|
||||
|
||||
fcode = pc->md.use_bpf ? NULL : pc->fcode.bf_insns;
|
||||
again:
|
||||
cc = pc->cc;
|
||||
if (cc == 0) {
|
||||
cc = read(pc->fd, (char *)pc->buffer + pc->offset, pc->bufsize);
|
||||
if (cc < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return (0);
|
||||
if (errno == EINVAL &&
|
||||
lseek(pc->fd, 0L, SEEK_CUR) + pc->bufsize < 0) {
|
||||
/*
|
||||
* Due to a kernel bug, after 2^31 bytes,
|
||||
* the kernel file offset overflows and
|
||||
* read fails with EINVAL. The lseek()
|
||||
* to 0 will fix things.
|
||||
*/
|
||||
(void)lseek(pc->fd, 0L, SEEK_SET);
|
||||
goto again;
|
||||
}
|
||||
snprintf(pc->errbuf, sizeof(pc->errbuf), "pf read: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
bp = pc->buffer + pc->offset;
|
||||
} else
|
||||
bp = pc->bp;
|
||||
/*
|
||||
* Loop through each packet.
|
||||
*/
|
||||
n = 0;
|
||||
#ifdef PCAP_FDDIPAD
|
||||
pad = pc->fddipad;
|
||||
#endif
|
||||
while (cc > 0) {
|
||||
/*
|
||||
* 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 (pc->break_loop) {
|
||||
if (n == 0) {
|
||||
pc->break_loop = 0;
|
||||
return (-2);
|
||||
} else {
|
||||
pc->cc = cc;
|
||||
pc->bp = bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
if (cc < sizeof(*sp)) {
|
||||
snprintf(pc->errbuf, sizeof(pc->errbuf),
|
||||
"pf short read (%d)", cc);
|
||||
return (-1);
|
||||
}
|
||||
#ifdef LBL_ALIGN
|
||||
if ((long)bp & 3) {
|
||||
sp = &stamp;
|
||||
memcpy((char *)sp, (char *)bp, sizeof(*sp));
|
||||
} else
|
||||
#endif
|
||||
sp = (struct enstamp *)bp;
|
||||
if (sp->ens_stamplen != sizeof(*sp)) {
|
||||
snprintf(pc->errbuf, sizeof(pc->errbuf),
|
||||
"pf short stamplen (%d)",
|
||||
sp->ens_stamplen);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
p = bp + sp->ens_stamplen;
|
||||
buflen = sp->ens_count;
|
||||
if (buflen > pc->snapshot)
|
||||
buflen = pc->snapshot;
|
||||
|
||||
/* Calculate inc before possible pad update */
|
||||
inc = ENALIGN(buflen + sp->ens_stamplen);
|
||||
cc -= inc;
|
||||
bp += inc;
|
||||
pc->md.TotPkts++;
|
||||
pc->md.TotDrops += sp->ens_dropped;
|
||||
pc->md.TotMissed = sp->ens_ifoverflows;
|
||||
if (pc->md.OrigMissed < 0)
|
||||
pc->md.OrigMissed = pc->md.TotMissed;
|
||||
|
||||
/*
|
||||
* Short-circuit evaluation: if using BPF filter
|
||||
* in kernel, no need to do it now.
|
||||
*
|
||||
#ifdef PCAP_FDDIPAD
|
||||
* Note: the filter code was generated assuming
|
||||
* that pc->fddipad was the amount of padding
|
||||
* before the header, as that's what's required
|
||||
* in the kernel, so we run the filter before
|
||||
* skipping that padding.
|
||||
#endif
|
||||
*/
|
||||
if (fcode == NULL ||
|
||||
bpf_filter(fcode, p, sp->ens_count, buflen)) {
|
||||
struct pcap_pkthdr h;
|
||||
pc->md.TotAccepted++;
|
||||
h.ts = sp->ens_tstamp;
|
||||
#ifdef PCAP_FDDIPAD
|
||||
h.len = sp->ens_count - pad;
|
||||
#else
|
||||
h.len = sp->ens_count;
|
||||
#endif
|
||||
#ifdef PCAP_FDDIPAD
|
||||
p += pad;
|
||||
buflen -= pad;
|
||||
#endif
|
||||
h.caplen = buflen;
|
||||
(*callback)(user, &h, p);
|
||||
if (++n >= cnt && cnt > 0) {
|
||||
pc->cc = cc;
|
||||
pc->bp = bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
}
|
||||
pc->cc = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_inject_pf(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);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
|
||||
/*
|
||||
* If packet filtering is being done in the kernel:
|
||||
*
|
||||
* "ps_recv" counts only packets that passed the filter.
|
||||
* This does not include packets dropped because we
|
||||
* ran out of buffer space. (XXX - perhaps it should,
|
||||
* by adding "ps_drop" to "ps_recv", for compatibility
|
||||
* with some other platforms. On the other hand, on
|
||||
* some platforms "ps_recv" counts only packets that
|
||||
* passed the filter, and on others it counts packets
|
||||
* that didn't pass the filter....)
|
||||
*
|
||||
* "ps_drop" counts packets that passed the kernel filter
|
||||
* (if any) but were dropped because the input queue was
|
||||
* full.
|
||||
*
|
||||
* "ps_ifdrop" counts packets dropped by the network
|
||||
* inteface (regardless of whether they would have passed
|
||||
* the input filter, of course).
|
||||
*
|
||||
* If packet filtering is not being done in the kernel:
|
||||
*
|
||||
* "ps_recv" counts only packets that passed the filter.
|
||||
*
|
||||
* "ps_drop" counts packets that were dropped because the
|
||||
* input queue was full, regardless of whether they passed
|
||||
* the userland filter.
|
||||
*
|
||||
* "ps_ifdrop" counts packets dropped by the network
|
||||
* inteface (regardless of whether they would have passed
|
||||
* the input filter, of course).
|
||||
*
|
||||
* These statistics don't include packets not yet read from
|
||||
* the kernel by libpcap, but they may include packets not
|
||||
* yet read from libpcap by the application.
|
||||
*/
|
||||
ps->ps_recv = p->md.TotAccepted;
|
||||
ps->ps_drop = p->md.TotDrops;
|
||||
ps->ps_ifdrop = p->md.TotMissed - p->md.OrigMissed;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We include the OS's <net/bpf.h>, not our "pcap-bpf.h", so we probably
|
||||
* don't get DLT_DOCSIS defined.
|
||||
*/
|
||||
#ifndef DLT_DOCSIS
|
||||
#define DLT_DOCSIS 143
|
||||
#endif
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
short enmode;
|
||||
int backlog = -1; /* request the most */
|
||||
struct enfilter Filter;
|
||||
struct endevp devparams;
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"pcap_open_live: %s", pcap_strerror(errno));
|
||||
return (0);
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
/*
|
||||
* Initially try a read/write open (to allow the inject
|
||||
* method to work). If that fails due to permission
|
||||
* issues, fall back to read-only. This allows a
|
||||
* non-root user to be granted specific access to pcap
|
||||
* capabilities via file permissions.
|
||||
*
|
||||
* XXX - we should have an API that has a flag that
|
||||
* controls whether to open read-only or read-write,
|
||||
* so that denial of permission to send (or inability
|
||||
* to send, if sending packets isn't supported on
|
||||
* the device in question) can be indicated at open
|
||||
* time.
|
||||
*
|
||||
* XXX - we assume here that "pfopen()" does not, in fact, modify
|
||||
* its argument, even though it takes a "char *" rather than a
|
||||
* "const char *" as its first argument. That appears to be
|
||||
* the case, at least on Digital UNIX 4.0.
|
||||
*/
|
||||
p->fd = pfopen(device, O_RDWR);
|
||||
if (p->fd == -1 && errno == EACCES)
|
||||
p->fd = pfopen(device, O_RDONLY);
|
||||
if (p->fd < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "pf open: %s: %s\n\
|
||||
your system may not be properly configured; see the packetfilter(4) man page\n",
|
||||
device, pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->md.OrigMissed = -1;
|
||||
enmode = ENTSTAMP|ENBATCH|ENNONEXCL;
|
||||
if (promisc)
|
||||
enmode |= ENPROMISC;
|
||||
if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCMBIS: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
#ifdef ENCOPYALL
|
||||
/* Try to set COPYALL mode so that we see packets to ourself */
|
||||
enmode = ENCOPYALL;
|
||||
(void)ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode);/* OK if this fails */
|
||||
#endif
|
||||
/* set the backlog */
|
||||
if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCSETW: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
/* discover interface type */
|
||||
if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCDEVP: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
/* HACK: to compile prior to Ultrix 4.2 */
|
||||
#ifndef ENDT_FDDI
|
||||
#define ENDT_FDDI 4
|
||||
#endif
|
||||
switch (devparams.end_dev_type) {
|
||||
|
||||
case ENDT_10MB:
|
||||
p->linktype = DLT_EN10MB;
|
||||
p->offset = 2;
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case ENDT_FDDI:
|
||||
p->linktype = DLT_FDDI;
|
||||
break;
|
||||
|
||||
#ifdef ENDT_SLIP
|
||||
case ENDT_SLIP:
|
||||
p->linktype = DLT_SLIP;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef ENDT_PPP
|
||||
case ENDT_PPP:
|
||||
p->linktype = DLT_PPP;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef ENDT_LOOPBACK
|
||||
case ENDT_LOOPBACK:
|
||||
/*
|
||||
* It appears to use Ethernet framing, at least on
|
||||
* Digital UNIX 4.0.
|
||||
*/
|
||||
p->linktype = DLT_EN10MB;
|
||||
p->offset = 2;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef ENDT_TRN
|
||||
case ENDT_TRN:
|
||||
p->linktype = DLT_IEEE802;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
/*
|
||||
* XXX - what about ENDT_IEEE802? The pfilt.h header
|
||||
* file calls this "IEEE 802 networks (non-Ethernet)",
|
||||
* but that doesn't specify a specific link layer type;
|
||||
* it could be 802.4, or 802.5 (except that 802.5 is
|
||||
* ENDT_TRN), or 802.6, or 802.11, or.... That's why
|
||||
* DLT_IEEE802 was hijacked to mean Token Ring in various
|
||||
* BSDs, and why we went along with that hijacking.
|
||||
*
|
||||
* XXX - what about ENDT_HDLC and ENDT_NULL?
|
||||
* Presumably, as ENDT_OTHER is just "Miscellaneous
|
||||
* framing", there's not much we can do, as that
|
||||
* doesn't specify a particular type of header.
|
||||
*/
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "unknown data-link type %u",
|
||||
devparams.end_dev_type);
|
||||
goto bad;
|
||||
}
|
||||
/* set truncation */
|
||||
#ifdef PCAP_FDDIPAD
|
||||
if (p->linktype == DLT_FDDI) {
|
||||
p->fddipad = PCAP_FDDIPAD;
|
||||
|
||||
/* packetfilter includes the padding in the snapshot */
|
||||
snaplen += PCAP_FDDIPAD;
|
||||
} else
|
||||
p->fddipad = 0;
|
||||
#endif
|
||||
if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&snaplen) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCTRUNCATE: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->snapshot = snaplen;
|
||||
/* accept all packets */
|
||||
memset(&Filter, 0, sizeof(Filter));
|
||||
Filter.enf_Priority = 37; /* anything > 2 */
|
||||
Filter.enf_FilterLen = 0; /* means "always true" */
|
||||
if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCSETF: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (to_ms != 0) {
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = to_ms / 1000;
|
||||
timeout.tv_usec = (to_ms * 1000) % 1000000;
|
||||
if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCSRTIMEOUT: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = (u_char*)malloc(p->bufsize + p->offset);
|
||||
if (p->buffer == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* "select()" and "poll()" work on packetfilter devices.
|
||||
*/
|
||||
p->selectable_fd = p->fd;
|
||||
|
||||
p->read_op = pcap_read_pf;
|
||||
p->inject_op = pcap_inject_pf;
|
||||
p->setfilter_op = pcap_setfilter_pf;
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_pf;
|
||||
p->close_op = pcap_close_common;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
if (p->fd >= 0)
|
||||
close(p->fd);
|
||||
/*
|
||||
* Get rid of any link-layer type list we allocated.
|
||||
*/
|
||||
if (p->dlt_list != NULL)
|
||||
free(p->dlt_list);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
struct bpf_version bv;
|
||||
|
||||
/*
|
||||
* See if BIOCVERSION works. If not, we assume the kernel doesn't
|
||||
* support BPF-style filters (it's not documented in the bpf(7)
|
||||
* or packetfiler(7) man pages, but the code used to fail if
|
||||
* BIOCSETF worked but BIOCVERSION didn't, and I've seen it do
|
||||
* kernel filtering in DU 4.0, so presumably BIOCVERSION works
|
||||
* there, at least).
|
||||
*/
|
||||
if (ioctl(p->fd, BIOCVERSION, (caddr_t)&bv) >= 0) {
|
||||
/*
|
||||
* OK, we have the version of the BPF interpreter;
|
||||
* is it the same major version as us, and the same
|
||||
* or better minor version?
|
||||
*/
|
||||
if (bv.bv_major == BPF_MAJOR_VERSION &&
|
||||
bv.bv_minor >= BPF_MINOR_VERSION) {
|
||||
/*
|
||||
* Yes. Try to install the filter.
|
||||
*/
|
||||
if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"BIOCSETF: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, that succeeded. We're doing filtering in
|
||||
* the kernel. (We assume we don't have a
|
||||
* userland filter installed - that'd require
|
||||
* a previous version check to have failed but
|
||||
* this one to succeed.)
|
||||
*
|
||||
* XXX - this message should be supplied to the
|
||||
* application as a warning of some sort,
|
||||
* except that if it's a GUI application, it's
|
||||
* not clear that it should be displayed in
|
||||
* a window to annoy the user.
|
||||
*/
|
||||
fprintf(stderr, "tcpdump: Using kernel BPF filter\n");
|
||||
p->md.use_bpf = 1;
|
||||
|
||||
/*
|
||||
* Discard any previously-received packets,
|
||||
* as they might have passed whatever filter
|
||||
* was formerly in effect, but might not pass
|
||||
* this filter (BIOCSETF discards packets buffered
|
||||
* in the kernel, so you can lose packets in any
|
||||
* case).
|
||||
*/
|
||||
p->cc = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We can't use the kernel's BPF interpreter; don't give
|
||||
* up, just log a message and be inefficient.
|
||||
*
|
||||
* XXX - this should really be supplied to the application
|
||||
* as a warning of some sort.
|
||||
*/
|
||||
fprintf(stderr,
|
||||
"tcpdump: Requires BPF language %d.%d or higher; kernel is %d.%d\n",
|
||||
BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
|
||||
bv.bv_major, bv.bv_minor);
|
||||
}
|
||||
|
||||
/*
|
||||
* We couldn't do filtering in the kernel; do it in userland.
|
||||
*/
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* XXX - this message should be supplied by the application as
|
||||
* a warning of some sort.
|
||||
*/
|
||||
fprintf(stderr, "tcpdump: Filtering in user process\n");
|
||||
p->md.use_bpf = 0;
|
||||
return (0);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1990, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Lawrence Berkeley Laboratory,
|
||||
* Berkeley, CA. The name of the University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-pf.h,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $ (LBL)
|
||||
*/
|
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
* pcap-septel.c: Packet capture interface for Intel/Septel card.
|
||||
*
|
||||
* The functionality of this code attempts to mimic that of pcap-linux as much
|
||||
* as possible. This code is compiled in several different ways depending on
|
||||
* whether SEPTEL_ONLY and HAVE_SEPTEL_API are defined. If HAVE_SEPTEL_API is
|
||||
* not defined it should not get compiled in, otherwise if SEPTEL_ONLY is
|
||||
* defined then the 'septel_' function calls are renamed to 'pcap_'
|
||||
* equivalents. If SEPTEL_ONLY is not defined then nothing is altered - the
|
||||
* septel_ functions will be called as required from their
|
||||
* pcap-linux/equivalents.
|
||||
*
|
||||
* Authors: Gilbert HOYEK (gil_hoyek@hotmail.com), Elias M. KHOURY
|
||||
* (+961 3 485243)
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-septel.c,v 1.1.1.1 2006/02/27 15:45:48 drochner Exp $";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_SEPTEL_API
|
||||
#include <msg.h>
|
||||
#include <ss7_inc.h>
|
||||
#include <sysgct.h>
|
||||
#include <pack.h>
|
||||
#include <system.h>
|
||||
#endif /* HAVE_SEPTEL_API */
|
||||
|
||||
#ifdef SEPTEL_ONLY
|
||||
/* This code is required when compiling for a Septel device only. */
|
||||
#include "pcap-septel.h"
|
||||
|
||||
/* Replace dag function names with pcap equivalent. */
|
||||
#define septel_open_live pcap_open_live
|
||||
#define septel_platform_finddevs pcap_platform_finddevs
|
||||
#endif /* SEPTEL_ONLY */
|
||||
|
||||
static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
|
||||
static int septel_stats(pcap_t *p, struct pcap_stat *ps);
|
||||
static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
|
||||
|
||||
static void septel_platform_close(pcap_t *p) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read at most max_packets from the capture queue and call the callback
|
||||
* for each of them. Returns the number of packets handled, -1 if an
|
||||
* error occured, or -2 if we were told to break out of the loop.
|
||||
*/
|
||||
static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) {
|
||||
|
||||
HDR *h;
|
||||
MSG *m;
|
||||
int processed = 0 ;
|
||||
int t = 0 ;
|
||||
|
||||
/* identifier for the message queue of the module(upe) from which we are capturing
|
||||
* packets.These IDs are defined in system.txt . By default it is set to 0x2d
|
||||
* so change it to 0xdd for technical reason and therefore the module id for upe becomes:
|
||||
* LOCAL 0xdd * upe - Example user part task */
|
||||
unsigned int id = 0xdd;
|
||||
|
||||
/* process the packets */
|
||||
do {
|
||||
|
||||
unsigned short packet_len = 0;
|
||||
int caplen = 0;
|
||||
int counter = 0;
|
||||
struct pcap_pkthdr pcap_header;
|
||||
u_char *dp ;
|
||||
|
||||
/*
|
||||
* Has "pcap_breakloop()" been called?
|
||||
*/
|
||||
loop:
|
||||
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;
|
||||
}
|
||||
|
||||
/*repeat until a packet is read
|
||||
*a NULL message means :
|
||||
* when no packet is in queue or all packets in queue already read */
|
||||
do {
|
||||
/* receive packet in non-blocking mode
|
||||
* GCT_grab is defined in the septel library software */
|
||||
h = GCT_grab(id);
|
||||
|
||||
m = (MSG*)h;
|
||||
/* a couter is added here to avoid an infinite loop
|
||||
* that will cause our capture program GUI to freeze while waiting
|
||||
* for a packet*/
|
||||
counter++ ;
|
||||
|
||||
}
|
||||
while ((m == NULL)&& (counter< 100)) ;
|
||||
|
||||
if (m != NULL) {
|
||||
|
||||
t = h->type ;
|
||||
|
||||
/* catch only messages with type = 0xcf00 or 0x8f01 corrsponding to ss7 messages*/
|
||||
/* XXX = why not use API_MSG_TX_REQ for 0xcf00 and API_MSG_RX_IND
|
||||
* for 0x8f01? */
|
||||
if ((t != 0xcf00) && (t != 0x8f01)) {
|
||||
relm(h);
|
||||
goto loop ;
|
||||
}
|
||||
|
||||
/* XXX - is API_MSG_RX_IND for an MTP2 or MTP3 message? */
|
||||
dp = get_param(m);/* get pointer to MSG parameter area (m->param) */
|
||||
packet_len = m->len;
|
||||
caplen = p->snapshot ;
|
||||
|
||||
|
||||
if (caplen > packet_len) {
|
||||
|
||||
caplen = packet_len;
|
||||
}
|
||||
/* Run the packet filter if there is one. */
|
||||
if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
|
||||
|
||||
/* get a time stamp , consisting of :
|
||||
*
|
||||
* pcap_header.ts.tv_sec:
|
||||
* ----------------------
|
||||
* a UNIX format time-in-seconds when he packet was captured,
|
||||
* i.e. the number of seconds since Epoch time (January 1,1970, 00:00:00 GMT)
|
||||
*
|
||||
* pcap_header.ts.tv_usec :
|
||||
* ------------------------
|
||||
* the number of microseconds since that second
|
||||
* when the packet was captured
|
||||
*/
|
||||
|
||||
(void)gettimeofday(&pcap_header.ts, NULL);
|
||||
|
||||
/* Fill in our own header data */
|
||||
pcap_header.caplen = caplen;
|
||||
pcap_header.len = packet_len;
|
||||
|
||||
/* Count the packet. */
|
||||
p->md.stat.ps_recv++;
|
||||
|
||||
/* Call the user supplied callback function */
|
||||
callback(user, &pcap_header, dp);
|
||||
|
||||
processed++ ;
|
||||
|
||||
}
|
||||
/* after being processed the packet must be
|
||||
*released in order to receive another one */
|
||||
relm(h);
|
||||
}else
|
||||
processed++;
|
||||
|
||||
}
|
||||
while (processed < cnt) ;
|
||||
|
||||
return processed ;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
|
||||
{
|
||||
strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a handle for a live capture from the given Septel device. Always pass a NULL device
|
||||
* The promisc flag is ignored because Septel cards have built-in tracing.
|
||||
* The to_ms parameter is also ignored as it is
|
||||
* not supported in hardware.
|
||||
*
|
||||
* See also pcap(3).
|
||||
*/
|
||||
pcap_t *septel_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf) {
|
||||
pcap_t *handle;
|
||||
|
||||
handle = malloc(sizeof(*handle));
|
||||
if (handle == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc %s: %s", device, pcap_strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize some components of the pcap structure. */
|
||||
|
||||
memset(handle, 0, sizeof(*handle));
|
||||
|
||||
handle->snapshot = snaplen;
|
||||
|
||||
handle->linktype = DLT_MTP2;
|
||||
|
||||
handle->bufsize = 0;
|
||||
|
||||
/*
|
||||
* "select()" and "poll()" don't work on Septel queues
|
||||
*/
|
||||
handle->selectable_fd = -1;
|
||||
|
||||
handle->read_op = septel_read;
|
||||
handle->inject_op = septel_inject;
|
||||
handle->setfilter_op = septel_setfilter;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = septel_setnonblock;
|
||||
handle->stats_op = septel_stats;
|
||||
handle->close_op = septel_platform_close;
|
||||
|
||||
return handle;
|
||||
|
||||
fail:
|
||||
if (handle != NULL) {
|
||||
free(handle);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int septel_stats(pcap_t *p, struct pcap_stat *ps) {
|
||||
/*p->md.stat.ps_recv = 0;*/
|
||||
/*p->md.stat.ps_drop = 0;*/
|
||||
|
||||
*ps = p->md.stat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
septel_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
|
||||
{
|
||||
unsigned char *p;
|
||||
const char description[512]= "Intel/Septel device";
|
||||
char name[512]="septel" ;
|
||||
int ret = 0;
|
||||
pcap_add_if(devlistp,name,0,description,errbuf);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Installs the given bpf filter program in the given pcap structure. There is
|
||||
* no attempt to store the filter in kernel memory as that is not supported
|
||||
* with Septel cards.
|
||||
*/
|
||||
static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
|
||||
if (!p)
|
||||
return -1;
|
||||
if (!fp) {
|
||||
strncpy(p->errbuf, "setfilter: No filter specified",
|
||||
sizeof(p->errbuf));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Make our private copy of the filter */
|
||||
|
||||
if (install_bpf_program(p, fp) < 0) {
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"malloc: %s", pcap_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->md.use_bpf = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
septel_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/*
|
||||
* pcap-septel.c: Packet capture interface for Intel Septel card
|
||||
*
|
||||
* The functionality of this code attempts to mimic that of pcap-linux as much
|
||||
* as possible. This code is only needed when compiling in the Intel/Septel
|
||||
* card code at the same time as another type of device.
|
||||
*
|
||||
* Authors: Gilbert HOYEK (gil_hoyek@hotmail.com), Elias M. KHOURY
|
||||
* (+961 3 485343);
|
||||
*
|
||||
* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-septel.h,v 1.1.1.1 2006/02/27 15:45:49 drochner Exp $
|
||||
*/
|
||||
|
||||
pcap_t *septel_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf);
|
||||
|
|
@ -1,419 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* Modifications made to accommodate the new SunOS4.0 NIT facility by
|
||||
* Micky Liu, micky@cunixc.cc.columbia.edu, Columbia University in May, 1989.
|
||||
* This module now handles the STREAMS based NIT.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-snit.c,v 1.1.1.1 2006/02/27 15:45:49 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/dir.h>
|
||||
#include <sys/fcntlcom.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stropts.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/nit.h>
|
||||
#include <net/nit_if.h>
|
||||
#include <net/nit_pf.h>
|
||||
#include <net/nit_buf.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The chunk size for NIT. This is the amount of buffering
|
||||
* done for read calls.
|
||||
*/
|
||||
#define CHUNKSIZE (2*1024)
|
||||
|
||||
/*
|
||||
* The total buffer space used by NIT.
|
||||
*/
|
||||
#define BUFSPACE (4*CHUNKSIZE)
|
||||
|
||||
/* Forwards */
|
||||
static int nit_setflags(int, int, int, char *);
|
||||
|
||||
static int
|
||||
pcap_stats_snit(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
|
||||
/*
|
||||
* "ps_recv" counts packets handed to the filter, not packets
|
||||
* that passed the filter. As filtering is done in userland,
|
||||
* this does not include packets dropped because we ran out
|
||||
* of buffer space.
|
||||
*
|
||||
* "ps_drop" counts packets dropped inside the "/dev/nit"
|
||||
* device because of flow control requirements or resource
|
||||
* exhaustion; it doesn't count packets dropped by the
|
||||
* interface driver, or packets dropped upstream. As filtering
|
||||
* is done in userland, it counts packets regardless of whether
|
||||
* they would've passed the filter.
|
||||
*
|
||||
* These statistics don't include packets not yet read from the
|
||||
* kernel by libpcap or packets not yet read from libpcap by the
|
||||
* application.
|
||||
*/
|
||||
*ps = p->md.stat;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
register int cc, n;
|
||||
register struct bpf_insn *fcode = p->fcode.bf_insns;
|
||||
register u_char *bp, *cp, *ep;
|
||||
register struct nit_bufhdr *hdrp;
|
||||
register struct nit_iftime *ntp;
|
||||
register struct nit_iflen *nlp;
|
||||
register struct nit_ifdrops *ndp;
|
||||
register int caplen;
|
||||
|
||||
cc = p->cc;
|
||||
if (cc == 0) {
|
||||
cc = read(p->fd, (char *)p->buffer, p->bufsize);
|
||||
if (cc < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return (0);
|
||||
snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
bp = p->buffer;
|
||||
} else
|
||||
bp = p->bp;
|
||||
|
||||
/*
|
||||
* loop through each snapshot in the chunk
|
||||
*/
|
||||
n = 0;
|
||||
ep = bp + cc;
|
||||
while (bp < ep) {
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
++p->md.stat.ps_recv;
|
||||
cp = bp;
|
||||
|
||||
/* get past NIT buffer */
|
||||
hdrp = (struct nit_bufhdr *)cp;
|
||||
cp += sizeof(*hdrp);
|
||||
|
||||
/* get past NIT timer */
|
||||
ntp = (struct nit_iftime *)cp;
|
||||
cp += sizeof(*ntp);
|
||||
|
||||
ndp = (struct nit_ifdrops *)cp;
|
||||
p->md.stat.ps_drop = ndp->nh_drops;
|
||||
cp += sizeof *ndp;
|
||||
|
||||
/* get past packet len */
|
||||
nlp = (struct nit_iflen *)cp;
|
||||
cp += sizeof(*nlp);
|
||||
|
||||
/* next snapshot */
|
||||
bp += hdrp->nhb_totlen;
|
||||
|
||||
caplen = nlp->nh_pktlen;
|
||||
if (caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
|
||||
if (bpf_filter(fcode, cp, nlp->nh_pktlen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
h.ts = ntp->nh_timestamp;
|
||||
h.len = nlp->nh_pktlen;
|
||||
h.caplen = caplen;
|
||||
(*callback)(user, &h, cp);
|
||||
if (++n >= cnt && cnt >= 0) {
|
||||
p->cc = ep - bp;
|
||||
p->bp = bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
}
|
||||
p->cc = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_inject_snit(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
struct strbuf ctl, data;
|
||||
|
||||
/*
|
||||
* XXX - can we just do
|
||||
*
|
||||
ret = write(pd->f, buf, size);
|
||||
*/
|
||||
ctl.len = sizeof(*sa); /* XXX - what was this? */
|
||||
ctl.buf = (char *)sa;
|
||||
data.buf = buf;
|
||||
data.len = size;
|
||||
ret = putmsg(p->fd, &ctl, &data);
|
||||
if (ret == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
|
||||
{
|
||||
bpf_u_int32 flags;
|
||||
struct strioctl si;
|
||||
struct timeval timeout;
|
||||
|
||||
si.ic_timout = INFTIM;
|
||||
if (to_ms != 0) {
|
||||
timeout.tv_sec = to_ms / 1000;
|
||||
timeout.tv_usec = (to_ms * 1000) % 1000000;
|
||||
si.ic_cmd = NIOCSTIME;
|
||||
si.ic_len = sizeof(timeout);
|
||||
si.ic_dp = (char *)&timeout;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSTIME: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
flags = NI_TIMESTAMP | NI_LEN | NI_DROPS;
|
||||
if (promisc)
|
||||
flags |= NI_PROMISC;
|
||||
si.ic_cmd = NIOCSFLAGS;
|
||||
si.ic_len = sizeof(flags);
|
||||
si.ic_dp = (char *)&flags;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSFLAGS: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
struct strioctl si; /* struct for ioctl() */
|
||||
struct ifreq ifr; /* interface request struct */
|
||||
int chunksize = CHUNKSIZE;
|
||||
int fd;
|
||||
static char dev[] = "/dev/nit";
|
||||
register pcap_t *p;
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (snaplen < 96)
|
||||
/*
|
||||
* NIT requires a snapshot length of at least 96.
|
||||
*/
|
||||
snaplen = 96;
|
||||
|
||||
memset(p, 0, sizeof(*p));
|
||||
/*
|
||||
* Initially try a read/write open (to allow the inject
|
||||
* method to work). If that fails due to permission
|
||||
* issues, fall back to read-only. This allows a
|
||||
* non-root user to be granted specific access to pcap
|
||||
* capabilities via file permissions.
|
||||
*
|
||||
* XXX - we should have an API that has a flag that
|
||||
* controls whether to open read-only or read-write,
|
||||
* so that denial of permission to send (or inability
|
||||
* to send, if sending packets isn't supported on
|
||||
* the device in question) can be indicated at open
|
||||
* time.
|
||||
*/
|
||||
p->fd = fd = open(dev, O_RDWR);
|
||||
if (fd < 0 && errno == EACCES)
|
||||
p->fd = fd = open(dev, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s", dev,
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* arrange to get discrete messages from the STREAM and use NIT_BUF */
|
||||
if (ioctl(fd, I_SRDOPT, (char *)RMSGD) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "I_SRDOPT: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
if (ioctl(fd, I_PUSH, "nbuf") < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "push nbuf: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
/* set the chunksize */
|
||||
si.ic_cmd = NIOCSCHUNK;
|
||||
si.ic_timout = INFTIM;
|
||||
si.ic_len = sizeof(chunksize);
|
||||
si.ic_dp = (char *)&chunksize;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSCHUNK: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* request the interface */
|
||||
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
|
||||
si.ic_cmd = NIOCBIND;
|
||||
si.ic_len = sizeof(ifr);
|
||||
si.ic_dp = (char *)𝔦
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCBIND: %s: %s",
|
||||
ifr.ifr_name, pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* set the snapshot length */
|
||||
si.ic_cmd = NIOCSSNAP;
|
||||
si.ic_len = sizeof(snaplen);
|
||||
si.ic_dp = (char *)&snaplen;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "NIOCSSNAP: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->snapshot = snaplen;
|
||||
if (nit_setflags(p->fd, promisc, to_ms, ebuf) < 0)
|
||||
goto bad;
|
||||
|
||||
(void)ioctl(fd, I_FLUSH, (char *)FLUSHR);
|
||||
/*
|
||||
* NIT supports only ethernets.
|
||||
*/
|
||||
p->linktype = DLT_EN10MB;
|
||||
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = (u_char *)malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
strlcpy(ebuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* "p->fd" is an FD for a STREAMS device, so "select()" and
|
||||
* "poll()" should work on it.
|
||||
*/
|
||||
p->selectable_fd = p->fd;
|
||||
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
}
|
||||
|
||||
p->read_op = pcap_read_snit;
|
||||
p->inject_op = pcap_inject_snit;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_snit;
|
||||
p->close_op = pcap_close_common;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
|
@ -1,405 +0,0 @@
|
|||
/*
|
||||
* 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: (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.
|
||||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-snoop.c,v 1.1.1.1 2006/02/27 15:45:49 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/raw.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcpip.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static int
|
||||
pcap_read_snoop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
int cc;
|
||||
register struct snoopheader *sh;
|
||||
register u_int datalen;
|
||||
register u_int caplen;
|
||||
register u_char *cp;
|
||||
|
||||
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 = read(p->fd, (char *)p->buffer, p->bufsize);
|
||||
if (cc < 0) {
|
||||
/* Don't choke when we get ptraced */
|
||||
switch (errno) {
|
||||
|
||||
case EINTR:
|
||||
goto again;
|
||||
|
||||
case EWOULDBLOCK:
|
||||
return (0); /* XXX */
|
||||
}
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"read: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
sh = (struct snoopheader *)p->buffer;
|
||||
datalen = sh->snoop_packetlen;
|
||||
|
||||
/*
|
||||
* XXX - Sigh, snoop_packetlen is a 16 bit quantity. If we
|
||||
* got a short length, but read a full sized snoop pakcet,
|
||||
* assume we overflowed and add back the 64K...
|
||||
*/
|
||||
if (cc == (p->snapshot + sizeof(struct snoopheader)) &&
|
||||
(datalen < p->snapshot))
|
||||
datalen += (64 * 1024);
|
||||
|
||||
caplen = (datalen < p->snapshot) ? datalen : p->snapshot;
|
||||
cp = (u_char *)(sh + 1) + p->offset; /* XXX */
|
||||
|
||||
/*
|
||||
* XXX unfortunately snoop loopback isn't exactly like
|
||||
* BSD's. The address family is encoded in the first 2
|
||||
* bytes rather than the first 4 bytes! Luckily the last
|
||||
* two snoop loopback bytes are zeroed.
|
||||
*/
|
||||
if (p->linktype == DLT_NULL && *((short *)(cp + 2)) == 0) {
|
||||
u_int *uip = (u_int *)cp;
|
||||
*uip >>= 16;
|
||||
}
|
||||
|
||||
if (p->fcode.bf_insns == NULL ||
|
||||
bpf_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
++p->md.stat.ps_recv;
|
||||
h.ts.tv_sec = sh->snoop_timestamp.tv_sec;
|
||||
h.ts.tv_usec = sh->snoop_timestamp.tv_usec;
|
||||
h.len = datalen;
|
||||
h.caplen = caplen;
|
||||
(*callback)(user, &h, cp);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_inject_snoop(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* XXX - libnet overwrites the source address with what I
|
||||
* presume is the interface's address; is that required?
|
||||
*/
|
||||
ret = write(p->fd, buf, size);
|
||||
if (ret == -1) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
|
||||
pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
register struct rawstats *rs;
|
||||
struct rawstats rawstats;
|
||||
|
||||
rs = &rawstats;
|
||||
memset(rs, 0, sizeof(*rs));
|
||||
if (ioctl(p->fd, SIOCRAWSTATS, (char *)rs) < 0) {
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"SIOCRAWSTATS: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* "ifdrops" are those dropped by the network interface
|
||||
* due to resource shortages or hardware errors.
|
||||
*
|
||||
* "sbdrops" are those dropped due to socket buffer limits.
|
||||
*
|
||||
* As filter is done in userland, "sbdrops" counts packets
|
||||
* regardless of whether they would've passed the filter.
|
||||
*
|
||||
* XXX - does this count *all* Snoop or Drain sockets,
|
||||
* rather than just this socket? If not, why does it have
|
||||
* both Snoop and Drain statistics?
|
||||
*/
|
||||
p->md.stat.ps_drop =
|
||||
rs->rs_snoop.ss_ifdrops + rs->rs_snoop.ss_sbdrops +
|
||||
rs->rs_drain.ds_ifdrops + rs->rs_drain.ds_sbdrops;
|
||||
|
||||
/*
|
||||
* "ps_recv" counts only packets that passed the filter.
|
||||
* As filtering is done in userland, this does not include
|
||||
* packets dropped because we ran out of buffer space.
|
||||
*/
|
||||
*ps = p->md.stat;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* XXX can't disable promiscuous */
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_raw sr;
|
||||
struct snoopfilter sf;
|
||||
u_int v;
|
||||
int ll_hdrlen;
|
||||
int snooplen;
|
||||
pcap_t *p;
|
||||
struct ifreq ifr;
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
|
||||
pcap_strerror(errno));
|
||||
return (NULL);
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP);
|
||||
if (fd < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "snoop socket: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->fd = fd;
|
||||
memset(&sr, 0, sizeof(sr));
|
||||
sr.sr_family = AF_RAW;
|
||||
(void)strncpy(sr.sr_ifname, device, sizeof(sr.sr_ifname));
|
||||
if (bind(fd, (struct sockaddr *)&sr, sizeof(sr))) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "snoop bind: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
memset(&sf, 0, sizeof(sf));
|
||||
if (ioctl(fd, SIOCADDSNOOP, &sf) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCADDSNOOP: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
v = 64 * 1024;
|
||||
(void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&v, sizeof(v));
|
||||
/*
|
||||
* XXX hack - map device name to link layer type
|
||||
*/
|
||||
if (strncmp("et", device, 2) == 0 || /* Challenge 10 Mbit */
|
||||
strncmp("ec", device, 2) == 0 || /* Indigo/Indy 10 Mbit,
|
||||
O2 10/100 */
|
||||
strncmp("ef", device, 2) == 0 || /* O200/2000 10/100 Mbit */
|
||||
strncmp("eg", device, 2) == 0 || /* Octane/O2xxx/O3xxx Gigabit */
|
||||
strncmp("gfe", device, 3) == 0 || /* GIO 100 Mbit */
|
||||
strncmp("fxp", device, 3) == 0 || /* Challenge VME Enet */
|
||||
strncmp("ep", device, 2) == 0 || /* Challenge 8x10 Mbit EPLEX */
|
||||
strncmp("vfe", device, 3) == 0 || /* Challenge VME 100Mbit */
|
||||
strncmp("fa", device, 2) == 0 ||
|
||||
strncmp("qaa", device, 3) == 0 ||
|
||||
strncmp("cip", device, 3) == 0 ||
|
||||
strncmp("el", device, 2) == 0) {
|
||||
p->linktype = DLT_EN10MB;
|
||||
p->offset = RAW_HDRPAD(sizeof(struct ether_header));
|
||||
ll_hdrlen = sizeof(struct ether_header);
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*
|
||||
* XXX - are there any sorts of "fake Ethernet" that have
|
||||
* Ethernet link-layer headers but that *shouldn't offer
|
||||
* DLT_DOCSIS as a Cisco CMTS won't put traffic onto it
|
||||
* or get traffic bridged onto it? "el" is for ATM LANE
|
||||
* Ethernet devices, so that might be the case for them;
|
||||
* the same applies for "qaa" classical IP devices. If
|
||||
* "fa" devices are for FORE SPANS, that'd apply to them
|
||||
* as well; what are "cip" devices - some other ATM
|
||||
* Classical IP devices?
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
}
|
||||
} else if (strncmp("ipg", device, 3) == 0 ||
|
||||
strncmp("rns", device, 3) == 0 || /* O2/200/2000 FDDI */
|
||||
strncmp("xpi", device, 3) == 0) {
|
||||
p->linktype = DLT_FDDI;
|
||||
p->offset = 3; /* XXX yeah? */
|
||||
ll_hdrlen = 13;
|
||||
} else if (strncmp("ppp", device, 3) == 0) {
|
||||
p->linktype = DLT_RAW;
|
||||
ll_hdrlen = 0; /* DLT_RAW meaning "no PPP header, just the IP packet"? */
|
||||
} else if (strncmp("qfa", device, 3) == 0) {
|
||||
p->linktype = DLT_IP_OVER_FC;
|
||||
ll_hdrlen = 24;
|
||||
} else if (strncmp("pl", device, 2) == 0) {
|
||||
p->linktype = DLT_RAW;
|
||||
ll_hdrlen = 0; /* Cray UNICOS/mp pseudo link */
|
||||
} else if (strncmp("lo", device, 2) == 0) {
|
||||
p->linktype = DLT_NULL;
|
||||
ll_hdrlen = 4;
|
||||
} else {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"snoop: unknown physical layer type");
|
||||
goto bad;
|
||||
}
|
||||
#ifdef SIOCGIFMTU
|
||||
/*
|
||||
* XXX - IRIX appears to give you an error if you try to set the
|
||||
* capture length to be greater than the MTU, so let's try to get
|
||||
* the MTU first and, if that succeeds, trim the snap length
|
||||
* to be no greater than the MTU.
|
||||
*/
|
||||
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFMTU, (char *)&ifr) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCGIFMTU: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
/*
|
||||
* OK, we got it.
|
||||
*
|
||||
* XXX - some versions of IRIX 6.5 define "ifr_mtu" and have an
|
||||
* "ifru_metric" member of the "ifr_ifru" union in an "ifreq"
|
||||
* structure, others don't.
|
||||
*
|
||||
* I've no idea what's going on, so, if "ifr_mtu" isn't defined,
|
||||
* we define it as "ifr_metric", as using that field appears to
|
||||
* work on the versions that lack "ifr_mtu" (and, on those that
|
||||
* don't lack it, "ifru_metric" and "ifru_mtu" are both "int"
|
||||
* members of the "ifr_ifru" union, which suggests that they
|
||||
* may be interchangeable in this case).
|
||||
*/
|
||||
#ifndef ifr_mtu
|
||||
#define ifr_mtu ifr_metric
|
||||
#endif
|
||||
if (snaplen > ifr.ifr_mtu + ll_hdrlen)
|
||||
snaplen = ifr.ifr_mtu + ll_hdrlen;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The argument to SIOCSNOOPLEN is the number of link-layer
|
||||
* payload bytes to capture - it doesn't count link-layer
|
||||
* header bytes.
|
||||
*/
|
||||
snooplen = snaplen - ll_hdrlen;
|
||||
if (snooplen < 0)
|
||||
snooplen = 0;
|
||||
if (ioctl(fd, SIOCSNOOPLEN, &snooplen) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNOOPLEN: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
p->snapshot = snaplen;
|
||||
v = 1;
|
||||
if (ioctl(fd, SIOCSNOOPING, &v) < 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNOOPING: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
p->bufsize = 4096; /* XXX */
|
||||
p->buffer = (u_char *)malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
|
||||
pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* "p->fd" is a socket, so "select()" should work on it.
|
||||
*/
|
||||
p->selectable_fd = p->fd;
|
||||
|
||||
p->read_op = pcap_read_snoop;
|
||||
p->inject_op = pcap_inject_snoop;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_snoop;
|
||||
p->close_op = pcap_close_common;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
(void)close(fd);
|
||||
/*
|
||||
* Get rid of any link-layer type list we allocated.
|
||||
*/
|
||||
if (p->dlt_list != NULL)
|
||||
free(p->dlt_list);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 - 2003
|
||||
* NetGroup, Politecnico di Torino (Italy)
|
||||
* 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. Neither the name of the Politecnico di Torino 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#define SIZEOF_CHAR 1
|
||||
#define SIZEOF_SHORT 2
|
||||
#define SIZEOF_INT 4
|
||||
#ifndef _MSC_EXTENSIONS
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Avoids a compiler warning in case this was already defined
|
||||
* (someone defined _WINSOCKAPI_ when including 'windows.h', in order
|
||||
* to prevent it from including 'winsock.h')
|
||||
*/
|
||||
#ifdef _WINSOCKAPI_
|
||||
#undef _WINSOCKAPI_
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "bittypes.h"
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
|
||||
#ifndef __MINGW32__
|
||||
#include "IP6_misc.h"
|
||||
#endif
|
||||
|
||||
#define caddr_t char*
|
||||
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define inline __inline
|
|
@ -1,775 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1999 - 2003
|
||||
* NetGroup, Politecnico di Torino (Italy)
|
||||
* 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. Neither the name of the Politecnico di Torino 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap-win32.c,v 1.1.1.1 2006/02/27 15:45:49 drochner Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <pcap-int.h>
|
||||
#include <packet32.h>
|
||||
#include <Ntddndis.h>
|
||||
#ifdef HAVE_DAG_API
|
||||
#include <dagnew.h>
|
||||
#include <dagapi.h>
|
||||
#endif /* HAVE_DAG_API */
|
||||
#ifdef __MINGW32__
|
||||
int* _errno();
|
||||
#define errno (*_errno())
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
static int pcap_setfilter_win32_npf(pcap_t *, struct bpf_program *);
|
||||
static int pcap_setfilter_win32_dag(pcap_t *, struct bpf_program *);
|
||||
static int pcap_getnonblock_win32(pcap_t *, char *);
|
||||
static int pcap_setnonblock_win32(pcap_t *, int, char *);
|
||||
|
||||
#define PcapBufSize 256000 /*dimension of the buffer in the pcap_t structure*/
|
||||
#define SIZE_BUF 1000000
|
||||
|
||||
/* Equivalent to ntohs(), but a lot faster under Windows */
|
||||
#define SWAPS(_X) ((_X & 0xff) << 8) | (_X >> 8)
|
||||
|
||||
/*
|
||||
* Header that the WinPcap driver associates to the packets.
|
||||
* Once was in bpf.h
|
||||
*/
|
||||
struct bpf_hdr {
|
||||
struct timeval bh_tstamp; /* time stamp */
|
||||
bpf_u_int32 bh_caplen; /* length of captured portion */
|
||||
bpf_u_int32 bh_datalen; /* original length of packet */
|
||||
u_short bh_hdrlen; /* length of bpf header (this struct
|
||||
plus alignment padding) */
|
||||
};
|
||||
|
||||
/* Start winsock */
|
||||
int
|
||||
wsockinit()
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
wVersionRequested = MAKEWORD( 1, 1);
|
||||
err = WSAStartup( wVersionRequested, &wsaData );
|
||||
if ( err != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
|
||||
if(PacketGetStats(p->adapter, (struct bpf_stat*)ps) != TRUE){
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "PacketGetStats error: %s", pcap_win32strerror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
int cc;
|
||||
int n = 0;
|
||||
register u_char *bp, *ep;
|
||||
|
||||
cc = p->cc;
|
||||
if (p->cc == 0) {
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
/* capture the packets */
|
||||
if(PacketReceivePacket(p->adapter,p->Packet,TRUE)==FALSE){
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cc = p->Packet->ulBytesReceived;
|
||||
|
||||
bp = p->Packet->Buffer;
|
||||
}
|
||||
else
|
||||
bp = p->bp;
|
||||
|
||||
/*
|
||||
* Loop through each packet.
|
||||
*/
|
||||
#define bhp ((struct bpf_hdr *)bp)
|
||||
ep = bp + cc;
|
||||
while (1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (bp >= ep)
|
||||
break;
|
||||
|
||||
caplen = bhp->bh_caplen;
|
||||
hdrlen = bhp->bh_hdrlen;
|
||||
|
||||
/*
|
||||
* XXX A bpf_hdr matches a pcap_pkthdr.
|
||||
*/
|
||||
(*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen);
|
||||
bp += BPF_WORDALIGN(caplen + hdrlen);
|
||||
if (++n >= cnt && cnt > 0) {
|
||||
p->bp = bp;
|
||||
p->cc = ep - bp;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
#undef bhp
|
||||
p->cc = 0;
|
||||
return (n);
|
||||
}
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
static int
|
||||
pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
u_char *dp = NULL;
|
||||
int packet_len = 0, caplen = 0;
|
||||
struct pcap_pkthdr pcap_header;
|
||||
u_char *endofbuf;
|
||||
int n = 0;
|
||||
dag_record_t *header;
|
||||
unsigned erf_record_len;
|
||||
ULONGLONG ts;
|
||||
int cc;
|
||||
unsigned swt;
|
||||
unsigned dfp = p->adapter->DagFastProcess;
|
||||
|
||||
cc = p->cc;
|
||||
if (cc == 0) /* Get new packets only if we have processed all the ones of the previous read */
|
||||
{
|
||||
/* Get new packets from the network */
|
||||
if(PacketReceivePacket(p->adapter, p->Packet, TRUE)==FALSE){
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cc = p->Packet->ulBytesReceived;
|
||||
if(cc == 0)
|
||||
/* The timeout has expired but we no packets arrived */
|
||||
return 0;
|
||||
header = (dag_record_t*)p->adapter->DagBuffer;
|
||||
}
|
||||
else
|
||||
header = (dag_record_t*)p->bp;
|
||||
|
||||
endofbuf = (char*)header + cc;
|
||||
|
||||
/*
|
||||
* Cycle through the packets
|
||||
*/
|
||||
do
|
||||
{
|
||||
erf_record_len = SWAPS(header->rlen);
|
||||
if((char*)header + erf_record_len > endofbuf)
|
||||
break;
|
||||
|
||||
/* Increase the number of captured packets */
|
||||
p->md.stat.ps_recv++;
|
||||
|
||||
/* Find the beginning of the packet */
|
||||
dp = ((u_char *)header) + dag_record_size;
|
||||
|
||||
/* Determine actual packet len */
|
||||
switch(header->type)
|
||||
{
|
||||
case TYPE_ATM:
|
||||
packet_len = ATM_SNAPLEN;
|
||||
caplen = ATM_SNAPLEN;
|
||||
dp += 4;
|
||||
|
||||
break;
|
||||
|
||||
case TYPE_ETH:
|
||||
swt = SWAPS(header->wlen);
|
||||
packet_len = swt - (p->md.dag_fcs_bits);
|
||||
caplen = erf_record_len - dag_record_size - 2;
|
||||
if (caplen > packet_len)
|
||||
{
|
||||
caplen = packet_len;
|
||||
}
|
||||
dp += 2;
|
||||
|
||||
break;
|
||||
|
||||
case TYPE_HDLC_POS:
|
||||
swt = SWAPS(header->wlen);
|
||||
packet_len = swt - (p->md.dag_fcs_bits);
|
||||
caplen = erf_record_len - dag_record_size;
|
||||
if (caplen > packet_len)
|
||||
{
|
||||
caplen = packet_len;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
|
||||
/*
|
||||
* 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 = (char*)header;
|
||||
p->cc = endofbuf - (char*)header;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
|
||||
if(!dfp)
|
||||
{
|
||||
/* convert between timestamp formats */
|
||||
ts = header->ts;
|
||||
pcap_header.ts.tv_sec = (int)(ts >> 32);
|
||||
ts = (ts & 0xffffffffi64) * 1000000;
|
||||
ts += 0x80000000; /* rounding */
|
||||
pcap_header.ts.tv_usec = (int)(ts >> 32);
|
||||
if (pcap_header.ts.tv_usec >= 1000000) {
|
||||
pcap_header.ts.tv_usec -= 1000000;
|
||||
pcap_header.ts.tv_sec++;
|
||||
}
|
||||
}
|
||||
|
||||
/* No underlaying filtering system. We need to filter on our own */
|
||||
if (p->fcode.bf_insns)
|
||||
{
|
||||
if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
|
||||
{
|
||||
/* Move to next packet */
|
||||
header = (dag_record_t*)((char*)header + erf_record_len);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill the header for the user suppplied callback function */
|
||||
pcap_header.caplen = caplen;
|
||||
pcap_header.len = packet_len;
|
||||
|
||||
/* Call the callback function */
|
||||
(*callback)(user, &pcap_header, dp);
|
||||
|
||||
/* Move to next packet */
|
||||
header = (dag_record_t*)((char*)header + erf_record_len);
|
||||
|
||||
/* Stop if the number of packets requested by user has been reached*/
|
||||
if (++n >= cnt && cnt > 0)
|
||||
{
|
||||
p->bp = (char*)header;
|
||||
p->cc = endofbuf - (char*)header;
|
||||
return (n);
|
||||
}
|
||||
}
|
||||
while((u_char*)header < endofbuf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
/* Send a packet to the network */
|
||||
static int
|
||||
pcap_inject_win32(pcap_t *p, const void *buf, size_t size){
|
||||
LPPACKET PacketToSend;
|
||||
|
||||
PacketToSend=PacketAllocatePacket();
|
||||
|
||||
if (PacketToSend == NULL)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketAllocatePacket failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PacketInitPacket(PacketToSend,(PVOID)buf,size);
|
||||
if(PacketSendPacket(p->adapter,PacketToSend,TRUE) == FALSE){
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketSendPacket failed");
|
||||
PacketFreePacket(PacketToSend);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PacketFreePacket(PacketToSend);
|
||||
|
||||
/*
|
||||
* We assume it all got sent if "PacketSendPacket()" succeeded.
|
||||
* "pcap_inject()" is expected to return the number of bytes
|
||||
* sent.
|
||||
*/
|
||||
return size;
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_close_win32(pcap_t *p)
|
||||
{
|
||||
pcap_close_common(p);
|
||||
if (p->adapter != NULL) {
|
||||
PacketCloseAdapter(p->adapter);
|
||||
p->adapter = NULL;
|
||||
}
|
||||
if (p->Packet) {
|
||||
PacketFreePacket(p->Packet);
|
||||
p->Packet = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
|
||||
char *ebuf)
|
||||
{
|
||||
register pcap_t *p;
|
||||
NetType type;
|
||||
|
||||
/* Init WinSock */
|
||||
wsockinit();
|
||||
|
||||
p = (pcap_t *)malloc(sizeof(*p));
|
||||
if (p == NULL)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
|
||||
return (NULL);
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->adapter=NULL;
|
||||
|
||||
p->adapter = PacketOpenAdapter((char*)device);
|
||||
|
||||
if (p->adapter == NULL)
|
||||
{
|
||||
free(p);
|
||||
/* Adapter detected but we are not able to open it. Return failure. */
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "Error opening adapter: %s", pcap_win32strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*get network type*/
|
||||
if(PacketGetNetType (p->adapter,&type) == FALSE)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "Cannot determine the network type: %s", pcap_win32strerror());
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*Set the linktype*/
|
||||
switch (type.LinkType)
|
||||
{
|
||||
case NdisMediumWan:
|
||||
p->linktype = DLT_EN10MB;
|
||||
break;
|
||||
|
||||
case NdisMedium802_3:
|
||||
p->linktype = DLT_EN10MB;
|
||||
/*
|
||||
* This is (presumably) a real Ethernet capture; give it a
|
||||
* link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
|
||||
* that an application can let you choose it, in case you're
|
||||
* capturing DOCSIS traffic that a Cisco Cable Modem
|
||||
* Termination System is putting out onto an Ethernet (it
|
||||
* doesn't put an Ethernet header onto the wire, it puts raw
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case NdisMediumFddi:
|
||||
p->linktype = DLT_FDDI;
|
||||
break;
|
||||
|
||||
case NdisMedium802_5:
|
||||
p->linktype = DLT_IEEE802;
|
||||
break;
|
||||
|
||||
case NdisMediumArcnetRaw:
|
||||
p->linktype = DLT_ARCNET;
|
||||
break;
|
||||
|
||||
case NdisMediumArcnet878_2:
|
||||
p->linktype = DLT_ARCNET;
|
||||
break;
|
||||
|
||||
case NdisMediumAtm:
|
||||
p->linktype = DLT_ATM_RFC1483;
|
||||
break;
|
||||
|
||||
case NdisMediumCHDLC:
|
||||
p->linktype = DLT_CHDLC;
|
||||
break;
|
||||
|
||||
case NdisMediumPPPSerial:
|
||||
p->linktype = DLT_PPP_SERIAL;
|
||||
break;
|
||||
|
||||
case NdisMediumNull:
|
||||
p->linktype = DLT_NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
p->linktype = DLT_EN10MB; /*an unknown adapter is assumed to be ethernet*/
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set promisquous mode */
|
||||
if (promisc) PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS);
|
||||
else PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL);
|
||||
|
||||
/* Set the buffer size */
|
||||
p->bufsize = PcapBufSize;
|
||||
|
||||
/* Store the timeout. Used by pcap_setnonblock() */
|
||||
p->timeout= to_ms;
|
||||
|
||||
/* allocate Packet structure used during the capture */
|
||||
if((p->Packet = PacketAllocatePacket())==NULL)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "failed to allocate the PACKET structure");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if(!(p->adapter->Flags & INFO_FLAG_DAG_CARD))
|
||||
{
|
||||
/*
|
||||
* Traditional Adapter
|
||||
*/
|
||||
|
||||
p->buffer = (u_char *)malloc(PcapBufSize);
|
||||
if (p->buffer == NULL)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
|
||||
|
||||
p->snapshot = snaplen;
|
||||
|
||||
/* allocate the standard buffer in the driver */
|
||||
if(PacketSetBuff( p->adapter, SIZE_BUF)==FALSE)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,"driver error: not enough memory to allocate the kernel buffer\n");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* tell the driver to copy the buffer only if it contains at least 16K */
|
||||
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
|
||||
{
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s\n", pcap_win32strerror());
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
else
|
||||
#ifdef HAVE_DAG_API
|
||||
{
|
||||
/*
|
||||
* Dag Card
|
||||
*/
|
||||
LONG status;
|
||||
HKEY dagkey;
|
||||
DWORD lptype;
|
||||
DWORD lpcbdata;
|
||||
int postype = 0;
|
||||
char keyname[512];
|
||||
|
||||
snprintf(keyname, sizeof(keyname), "%s\\CardParams\\%s",
|
||||
"SYSTEM\\CurrentControlSet\\Services\\DAG",
|
||||
strstr(_strlwr((char*)device), "dag"));
|
||||
do
|
||||
{
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname, 0, KEY_READ, &dagkey);
|
||||
if(status != ERROR_SUCCESS)
|
||||
break;
|
||||
|
||||
status = RegQueryValueEx(dagkey,
|
||||
"PosType",
|
||||
NULL,
|
||||
&lptype,
|
||||
(char*)&postype,
|
||||
&lpcbdata);
|
||||
|
||||
if(status != ERROR_SUCCESS)
|
||||
{
|
||||
postype = 0;
|
||||
}
|
||||
|
||||
RegCloseKey(dagkey);
|
||||
}
|
||||
while(FALSE);
|
||||
|
||||
|
||||
p->snapshot = PacketSetSnapLen(p->adapter, snaplen);
|
||||
|
||||
/* Set the length of the FCS associated to any packet. This value
|
||||
* will be subtracted to the packet length */
|
||||
p->md.dag_fcs_bits = p->adapter->DagFcsLen;
|
||||
}
|
||||
#else
|
||||
goto bad;
|
||||
#endif /* HAVE_DAG_API */
|
||||
|
||||
PacketSetReadTimeout(p->adapter, to_ms);
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
if(p->adapter->Flags & INFO_FLAG_DAG_CARD)
|
||||
{
|
||||
/* install dag specific handlers for read and setfilter */
|
||||
p->read_op = pcap_read_win32_dag;
|
||||
p->setfilter_op = pcap_setfilter_win32_dag;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* HAVE_DAG_API */
|
||||
/* install traditional npf handlers for read and setfilter */
|
||||
p->read_op = pcap_read_win32_npf;
|
||||
p->setfilter_op = pcap_setfilter_win32_npf;
|
||||
#ifdef HAVE_DAG_API
|
||||
}
|
||||
#endif /* HAVE_DAG_API */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
/* XXX - can this be implemented on some versions of Windows? */
|
||||
p->inject_op = pcap_inject_win32;
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_win32;
|
||||
p->setnonblock_op = pcap_setnonblock_win32;
|
||||
p->stats_op = pcap_stats_win32;
|
||||
p->close_op = pcap_close_win32;
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
if (p->adapter)
|
||||
PacketCloseAdapter(p->adapter);
|
||||
if (p->buffer != NULL)
|
||||
free(p->buffer);
|
||||
if(p->Packet)
|
||||
PacketFreePacket(p->Packet);
|
||||
/*
|
||||
* Get rid of any link-layer type list we allocated.
|
||||
*/
|
||||
if (p->dlt_list != NULL)
|
||||
free(p->dlt_list);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_setfilter_win32_npf(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
if(PacketSetBpf(p->adapter,fp)==FALSE){
|
||||
/*
|
||||
* Kernel filter not installed.
|
||||
* XXX - fall back on userland filtering, as is done
|
||||
* on other platforms?
|
||||
*/
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Driver error: cannot set bpf filter: %s", pcap_win32strerror());
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Discard any previously-received packets, as they might have
|
||||
* passed whatever filter was formerly in effect, but might
|
||||
* not pass this filter (BIOCSETF discards packets buffered
|
||||
* in the kernel, so you can lose packets in any case).
|
||||
*/
|
||||
p->cc = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We filter at user level, since the kernel driver does't process the packets
|
||||
*/
|
||||
static int
|
||||
pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
|
||||
|
||||
if(!fp)
|
||||
{
|
||||
strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Install a user level filter */
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
{
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"setfilter, unable to install the filter: %s", pcap_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->md.use_bpf = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_getnonblock_win32(pcap_t *p, char *errbuf)
|
||||
{
|
||||
/*
|
||||
* XXX - if there were a PacketGetReadTimeout() call, we
|
||||
* would use it, and return 1 if the timeout is -1
|
||||
* and 0 otherwise.
|
||||
*/
|
||||
return (p->nonblock);
|
||||
}
|
||||
|
||||
static int
|
||||
pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
|
||||
{
|
||||
int newtimeout;
|
||||
|
||||
if (nonblock) {
|
||||
/*
|
||||
* Set the read timeout to -1 for non-blocking mode.
|
||||
*/
|
||||
newtimeout = -1;
|
||||
} else {
|
||||
/*
|
||||
* Restore the timeout set when the device was opened.
|
||||
* (Note that this may be -1, in which case we're not
|
||||
* really leaving non-blocking mode.)
|
||||
*/
|
||||
newtimeout = p->timeout;
|
||||
}
|
||||
if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"PacketSetReadTimeout: %s", pcap_win32strerror());
|
||||
return (-1);
|
||||
}
|
||||
p->nonblock = (newtimeout == -1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set the driver working mode */
|
||||
int
|
||||
pcap_setmode(pcap_t *p, int mode){
|
||||
|
||||
if (p->adapter==NULL)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "impossible to set mode while reading from a file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(PacketSetMode(p->adapter,mode)==FALSE)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: working mode not recognized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the dimension of the kernel-level capture buffer */
|
||||
int
|
||||
pcap_setbuff(pcap_t *p, int dim)
|
||||
{
|
||||
if (p->adapter==NULL)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(PacketSetBuff(p->adapter,dim)==FALSE)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*set the minimum amount of data that will release a read call*/
|
||||
int
|
||||
pcap_setmintocopy(pcap_t *p, int size)
|
||||
{
|
||||
if (p->adapter==NULL)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Impossible to set the mintocopy parameter on an offline capture");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(PacketSetMinToCopy(p->adapter, size)==FALSE)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: unable to set the requested mintocopy size");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,909 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/pcap.c,v 1.4 2009/09/14 10:36:48 degroote Exp $ (LBL)";
|
||||
#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>
|
||||
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
#include "pcap-dos.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->dlt_count == 2 && p->dlt_list[0] == DLT_EN10MB &&
|
||||
dlt == DLT_DOCSIS) {
|
||||
/*
|
||||
* This is presumably an Ethernet device, as the first
|
||||
* link-layer type it offers is DLT_EN10MB, and the only
|
||||
* other type it offers is DLT_DOCSIS. That means that
|
||||
* we can't tell the driver to supply DOCSIS link-layer
|
||||
* headers - we're just pretending that's what we're
|
||||
* getting, as, presumably, we're capturing on a dedicated
|
||||
* link to a Cisco Cable Modem Termination System, and
|
||||
* it's putting raw DOCSIS frames on the wire inside low-level
|
||||
* Ethernet framing.
|
||||
*/
|
||||
p->linktype = dlt;
|
||||
return (0);
|
||||
}
|
||||
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 LLC-encapsulated 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_PFSYNC, "Packet filter state syncing"),
|
||||
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_DOCSIS, "DOCSIS"),
|
||||
DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
|
||||
DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS, "802.11 plus AVS radio information header"),
|
||||
DLT_CHOICE(DLT_SYMANTEC_FIREWALL, "Symantec Firewall"),
|
||||
DLT_CHOICE(DLT_JUNIPER_ATM1, "Juniper ATM1 PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_ATM2, "Juniper ATM2 PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_MLPPP, "Juniper Multi-Link PPP"),
|
||||
DLT_CHOICE(DLT_PPP_PPPD, "PPP for pppd, with direction flag"),
|
||||
DLT_CHOICE(DLT_JUNIPER_PPPOE, "Juniper PPPoE"),
|
||||
DLT_CHOICE(DLT_JUNIPER_PPPOE_ATM, "Juniper PPPoE/ATM"),
|
||||
DLT_CHOICE(DLT_GPRS_LLC, "GPRS LLC"),
|
||||
DLT_CHOICE(DLT_GPF_T, "GPF-T"),
|
||||
DLT_CHOICE(DLT_GPF_F, "GPF-F"),
|
||||
DLT_CHOICE(DLT_JUNIPER_PIC_PEER, "Juniper PIC Peer"),
|
||||
DLT_CHOICE(DLT_JUNIPER_MLFR, "Juniper Multi-Link Frame Relay"),
|
||||
DLT_CHOICE(DLT_ERF_ETH, "Ethernet with Endace ERF header"),
|
||||
DLT_CHOICE(DLT_ERF_POS, "Packet-over-SONET with Endace ERF header"),
|
||||
DLT_CHOICE(DLT_JUNIPER_GGSN, "Juniper GGSN PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_ES, "Juniper Encryption Services PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_MONITOR, "Juniper Passive Monitor PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_SERVICES, "Juniper Advanced Services PIC"),
|
||||
DLT_CHOICE(DLT_JUNIPER_MFR, "Juniper FRF.16 Frame Relay"),
|
||||
DLT_CHOICE(DLT_JUNIPER_ETHER, "Juniper Ethernet"),
|
||||
DLT_CHOICE(DLT_JUNIPER_PPP, "Juniper PPP"),
|
||||
DLT_CHOICE(DLT_JUNIPER_FRELAY, "Juniper Frame Relay"),
|
||||
DLT_CHOICE(DLT_JUNIPER_CHDLC, "Juniper C-HDLC"),
|
||||
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 = (const u_char *)s1,
|
||||
*us2 = (const 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
|
||||
}
|
||||
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
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.
|
||||
*/
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
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);
|
||||
}
|
||||
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
/*
|
||||
* 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;
|
||||
char *p;
|
||||
|
||||
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';
|
||||
}
|
||||
p = strchr(errbuf, '\0');
|
||||
snprintf (p, sizeof(errbuf)-(p-errbuf), " (%lu)", error);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set direction flag, which controls whether we accept only incoming
|
||||
* packets, only outgoing packets, or both.
|
||||
* Note that, depending on the platform, some or all direction arguments
|
||||
* might not be supported.
|
||||
*/
|
||||
int
|
||||
pcap_setdirection(pcap_t *p, pcap_direction_t d)
|
||||
{
|
||||
if (p->setdirection_op == NULL) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Setting direction is not implemented on this platform");
|
||||
return -1;
|
||||
} else
|
||||
return p->setdirection_op(p, d);
|
||||
}
|
||||
|
||||
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 _U_)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Statistics aren't available from a pcap_open_dead pcap_t");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
pcap_close_common(pcap_t *p)
|
||||
{
|
||||
if (p->buffer != NULL)
|
||||
free(p->buffer);
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
if (p->fd >= 0)
|
||||
close(p->fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_close_dead(pcap_t *p _U_)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* API compatible with WinPcap's "send a packet" routine - returns -1
|
||||
* on error, 0 otherwise.
|
||||
*
|
||||
* XXX - what if we get a short write?
|
||||
*/
|
||||
int
|
||||
pcap_sendpacket(pcap_t *p, const u_char *buf, int size)
|
||||
{
|
||||
if (p->inject_op(p, buf, size) == -1)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* API compatible with OpenBSD's "send a packet" routine - returns -1 on
|
||||
* error, number of bytes written otherwise.
|
||||
*/
|
||||
int
|
||||
pcap_inject(pcap_t *p, const void *buf, size_t size)
|
||||
{
|
||||
return (p->inject_op(p, buf, size));
|
||||
}
|
||||
|
||||
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 HAVE_VERSION_H
|
||||
#include "version.h"
|
||||
#else
|
||||
static const char pcap_version_string[] = "libpcap version 0.9[.x]";
|
||||
#endif
|
||||
|
||||
#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.1";
|
||||
static const char pcap_version_string_fmt[] =
|
||||
"WinPcap version %s, based on %s";
|
||||
static const char pcap_version_string_packet_dll_fmt[] =
|
||||
"WinPcap version %s (packet.dll version %s), based on %s";
|
||||
static char *full_pcap_version_string;
|
||||
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
char *packet_version_string;
|
||||
size_t full_pcap_version_string_len;
|
||||
|
||||
if (full_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.
|
||||
*/
|
||||
full_pcap_version_string_len =
|
||||
(sizeof pcap_version_string_fmt - 4) +
|
||||
strlen(wpcap_version_string) +
|
||||
strlen(pcap_version_string);
|
||||
full_pcap_version_string =
|
||||
malloc(full_pcap_version_string_len);
|
||||
sprintf(full_pcap_version_string,
|
||||
pcap_version_string_fmt, wpcap_version_string,
|
||||
pcap_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.
|
||||
*/
|
||||
full_pcap_version_string_len =
|
||||
(sizeof pcap_version_string_packet_dll_fmt - 6) +
|
||||
strlen(wpcap_version_string) +
|
||||
strlen(packet_version_string) +
|
||||
strlen(pcap_version_string);
|
||||
full_pcap_version_string = malloc(full_pcap_version_string_len);
|
||||
|
||||
sprintf(full_pcap_version_string,
|
||||
pcap_version_string_packet_dll_fmt,
|
||||
wpcap_version_string, packet_version_string,
|
||||
pcap_version_string);
|
||||
}
|
||||
}
|
||||
return (full_pcap_version_string);
|
||||
}
|
||||
|
||||
#elif defined(MSDOS)
|
||||
|
||||
static char *full_pcap_version_string;
|
||||
|
||||
const char *
|
||||
pcap_lib_version (void)
|
||||
{
|
||||
char *packet_version_string;
|
||||
size_t full_pcap_version_string_len;
|
||||
static char dospfx[] = "DOS-";
|
||||
|
||||
if (full_pcap_version_string == NULL) {
|
||||
/*
|
||||
* Generate the version string.
|
||||
*/
|
||||
full_pcap_version_string_len =
|
||||
sizeof dospfx + strlen(pcap_version_string);
|
||||
full_pcap_version_string =
|
||||
malloc(full_pcap_version_string_len);
|
||||
strcpy(full_pcap_version_string, dospfx);
|
||||
strcat(full_pcap_version_string, pcap_version_string);
|
||||
}
|
||||
return (full_pcap_version_string);
|
||||
}
|
||||
|
||||
#else /* UN*X */
|
||||
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
return (pcap_version_string);
|
||||
}
|
||||
#endif
|
|
@ -1,319 +0,0 @@
|
|||
/* $NetBSD: pcap.h,v 1.4 2010/12/05 05:20:28 christos 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: /cvsroot/src/dist/libpcap/Attic/pcap.h,v 1.4 2010/12/05 05:20:28 christos Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_h
|
||||
#define lib_pcap_h
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <pcap-stdinc.h>
|
||||
#elif defined(MSDOS)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h> /* u_int, u_char etc. */
|
||||
#else /* UN*X */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#endif /* WIN32/MSDOS/UN*X */
|
||||
|
||||
#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 int bpf_int32;
|
||||
typedef u_int 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_*) */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
PCAP_D_INOUT = 0,
|
||||
PCAP_D_IN,
|
||||
PCAP_D_OUT
|
||||
} pcap_direction_t;
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
};
|
||||
|
||||
#ifdef MSDOS
|
||||
/*
|
||||
* As returned by the pcap_stats_ex()
|
||||
*/
|
||||
struct pcap_stat_ex {
|
||||
u_long rx_packets; /* total packets received */
|
||||
u_long tx_packets; /* total packets transmitted */
|
||||
u_long rx_bytes; /* total bytes received */
|
||||
u_long tx_bytes; /* total bytes transmitted */
|
||||
u_long rx_errors; /* bad packets received */
|
||||
u_long tx_errors; /* packet transmit problems */
|
||||
u_long rx_dropped; /* no space in Rx buffers */
|
||||
u_long tx_dropped; /* no space available for Tx */
|
||||
u_long multicast; /* multicast packets received */
|
||||
u_long collisions;
|
||||
|
||||
/* detailed rx_errors: */
|
||||
u_long rx_length_errors;
|
||||
u_long rx_over_errors; /* receiver ring buff overflow */
|
||||
u_long rx_crc_errors; /* recv'd pkt with crc error */
|
||||
u_long rx_frame_errors; /* recv'd frame alignment error */
|
||||
u_long rx_fifo_errors; /* recv'r fifo overrun */
|
||||
u_long rx_missed_errors; /* recv'r missed packet */
|
||||
|
||||
/* detailed tx_errors */
|
||||
u_long tx_aborted_errors;
|
||||
u_long tx_carrier_errors;
|
||||
u_long tx_fifo_errors;
|
||||
u_long tx_heartbeat_errors;
|
||||
u_long tx_window_errors;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 *);
|
||||
pcap_t *pcap_fopen_offline(FILE *, 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_setdirection(pcap_t *, pcap_direction_t);
|
||||
int pcap_getnonblock(pcap_t *, char *);
|
||||
int pcap_setnonblock(pcap_t *, int, char *);
|
||||
void pcap_perror(pcap_t *, char *);
|
||||
int pcap_inject(pcap_t *, const void *, size_t);
|
||||
int pcap_sendpacket(pcap_t *, const u_char *, int);
|
||||
const char *pcap_strerror(int);
|
||||
char *pcap_geterr(pcap_t *);
|
||||
int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
|
||||
bpf_u_int32);
|
||||
int pcap_compile_nopcap(int, int, struct bpf_program *,
|
||||
const char *, int, bpf_u_int32);
|
||||
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 *);
|
||||
pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
|
||||
FILE *pcap_dump_file(pcap_dumper_t *);
|
||||
long pcap_dump_ftell(pcap_dumper_t *);
|
||||
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 *);
|
||||
|
||||
int pcap_findalldevs(pcap_if_t **, char *);
|
||||
void pcap_freealldevs(pcap_if_t *);
|
||||
|
||||
const char *pcap_lib_version(void);
|
||||
|
||||
#if 0
|
||||
/* 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(const struct bpf_insn *f, int len);
|
||||
char *bpf_image(struct bpf_insn *, int);
|
||||
void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
/*
|
||||
* Win32 definitions
|
||||
*/
|
||||
|
||||
int pcap_setbuff(pcap_t *p, int dim);
|
||||
int pcap_setmode(pcap_t *p, int mode);
|
||||
int pcap_setmintocopy(pcap_t *p, int size);
|
||||
|
||||
#ifdef WPCAP
|
||||
/* Include file with the wpcap-specific extensions */
|
||||
#include <Win32-Extensions.h>
|
||||
#endif /* WPCAP */
|
||||
|
||||
#define MODE_CAPT 0
|
||||
#define MODE_STAT 1
|
||||
#define MODE_MON 2
|
||||
|
||||
#elif defined(MSDOS)
|
||||
|
||||
/*
|
||||
* MS-DOS definitions
|
||||
*/
|
||||
|
||||
int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
|
||||
void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
|
||||
u_long pcap_mac_packets (void);
|
||||
|
||||
#else /* UN*X */
|
||||
|
||||
/*
|
||||
* UN*X definitions
|
||||
*/
|
||||
|
||||
int pcap_get_selectable_fd(pcap_t *);
|
||||
|
||||
#endif /* WIN32/MSDOS/UN*X */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,302 +0,0 @@
|
|||
/* -*- 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: /cvsroot/src/dist/libpcap/Attic/pcap1.h,v 1.1.1.1 2006/02/27 15:45:49 drochner 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 */
|
||||
|
||||
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
|
||||
#include <pcap-bpf.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PCAP_VERSION_MAJOR 3
|
||||
#define PCAP_VERSION_MINOR 0
|
||||
|
||||
#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 int bpf_int32;
|
||||
typedef u_int 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.
|
||||
*/
|
||||
|
||||
enum pcap1_info_types {
|
||||
PCAP_DATACAPTURE,
|
||||
PCAP_TIMESTAMP,
|
||||
PCAP_WALLTIME,
|
||||
PCAP_TIMESKEW,
|
||||
PCAP_PROBEPLACE, /* aka direction */
|
||||
PCAP_COMMENT, /* comment */
|
||||
};
|
||||
|
||||
struct pcap1_info_container {
|
||||
bpf_u_int32 info_len; /* in bytes */
|
||||
bpf_u_int32 info_type; /* enum pcap1_info_types */
|
||||
unsigned char info_data[0];
|
||||
};
|
||||
|
||||
struct pcap1_info_timestamp {
|
||||
struct pcap1_info_container pic;
|
||||
bpf_u_int32 nanoseconds; /* 10^-9 of seconds */
|
||||
bpf_u_int32 seconds; /* seconds since Unix epoch - GMT */
|
||||
bpf_u_int16 macroseconds; /* 16 bits more of MSB of time */
|
||||
bpf_u_int16 sigfigs; /* accuracy of timestamps - LSB bits */
|
||||
};
|
||||
|
||||
struct pcap1_info_packet {
|
||||
struct pcap1_info_container pic;
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length this packet (off wire) */
|
||||
bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
|
||||
bpf_u_int32 ifIndex; /* abstracted interface index */
|
||||
unsigned char packet_data[0];
|
||||
};
|
||||
|
||||
enum pcap1_probe {
|
||||
INBOUND =1,
|
||||
OUTBOUND =2,
|
||||
FORWARD =3,
|
||||
PREENCAP =4,
|
||||
POSTDECAP=5,
|
||||
};
|
||||
|
||||
struct pcap1_info_probe {
|
||||
struct pcap1_info_container pic;
|
||||
bpf_u_int32 probeloc; /* enum pcap1_probe */
|
||||
unsigned char probe_desc[0];
|
||||
};
|
||||
|
||||
struct pcap1_info_comment {
|
||||
struct pcap1_info_container pic;
|
||||
unsigned char comment[0];
|
||||
};
|
||||
|
||||
struct pcap1_packet_header {
|
||||
bpf_u_int32 magic;
|
||||
u_short version_major;
|
||||
u_short version_minor;
|
||||
bpf_u_int32 block_len;
|
||||
struct pcap1_info_container pics[0];
|
||||
};
|
||||
|
||||
/*
|
||||
* Each packet in the dump file is prepended with this generic header.
|
||||
* This gets around the problem of different headers for different
|
||||
* packet interfaces.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 *);
|
||||
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);
|
||||
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);
|
||||
|
||||
/* XXX this guy lives in the bpf tree */
|
||||
u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
|
||||
int bpf_validate(struct bpf_insn *f, int len);
|
||||
char *bpf_image(struct bpf_insn *, int);
|
||||
void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
#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
|
||||
|
||||
#else
|
||||
/*
|
||||
* UN*X definitions
|
||||
*/
|
||||
|
||||
int pcap_get_selectable_fd(pcap_t *);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001 Daniel Hartmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS 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/dist/libpcap/Attic/pf.h,v 1.2 2010/02/12 21:16:56 drochner Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/* from $OpenBSD: pfvar.h,v 1.170 2003/08/22 21:50:34 david Exp $ */
|
||||
|
||||
enum { PF_INOUT=0, PF_IN=1, PF_OUT=2 };
|
||||
enum { PF_PASS=0, PF_DROP=1, PF_SCRUB=2, PF_NAT=3, PF_NONAT=4,
|
||||
PF_BINAT=5, PF_NOBINAT=6, PF_RDR=7, PF_NORDR=8, PF_SYNPROXY_DROP=9 };
|
||||
|
||||
/* Reasons code for passing/dropping a packet */
|
||||
#define PFRES_MATCH 0 /* Explicit match of a rule */
|
||||
#define PFRES_BADOFF 1 /* Bad offset for pull_hdr */
|
||||
#define PFRES_FRAG 2 /* Dropping following fragment */
|
||||
#define PFRES_SHORT 3 /* Dropping short packet */
|
||||
#define PFRES_NORM 4 /* Dropping by normalizer */
|
||||
#define PFRES_MEMORY 5 /* Dropped due to lacking mem */
|
||||
#define PFRES_MAX 6 /* total+1 */
|
||||
|
||||
#define PFRES_NAMES { \
|
||||
"match", \
|
||||
"bad-offset", \
|
||||
"fragment", \
|
||||
"short", \
|
||||
"normalize", \
|
||||
"memory", \
|
||||
NULL \
|
||||
}
|
||||
|
||||
#define PF_RULESET_NAME_SIZE 16
|
||||
|
||||
/* from $OpenBSD: if_pflog.h,v 1.9 2003/07/15 20:27:27 dhartmei Exp $ */
|
||||
|
||||
#ifndef IFNAMSIZ
|
||||
#define IFNAMSIZ 16
|
||||
#endif
|
||||
|
||||
struct pfloghdr {
|
||||
u_int8_t length;
|
||||
u_int8_t af;
|
||||
u_int8_t action;
|
||||
u_int8_t reason;
|
||||
char ifname[IFNAMSIZ];
|
||||
char ruleset[PF_RULESET_NAME_SIZE];
|
||||
u_int32_t rulenr;
|
||||
u_int32_t subrulenr;
|
||||
u_int32_t uid;
|
||||
int32_t pid;
|
||||
u_int32_t rule_uid;
|
||||
int32_t rule_pid;
|
||||
u_int8_t dir;
|
||||
u_int8_t pad[3];
|
||||
};
|
||||
#define PFLOG_HDRLEN sizeof(struct pfloghdr)
|
|
@ -1,58 +0,0 @@
|
|||
/* @(#) $Header: /cvsroot/src/dist/libpcap/Attic/ppp.h,v 1.1.1.1 2006/02/27 15:45:49 drochner 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 */
|
||||
|
||||
#define PPP_PPPD_IN 0x00 /* non-standard for DLT_PPP_PPPD */
|
||||
#define PPP_PPPD_OUT 0x01 /* non-standard for DLT_PPP_PPPD */
|
||||
|
||||
/* 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_MPLS_UCAST 0x0281 /* rfc 3032 */
|
||||
#define PPP_MPLS_MCAST 0x0283 /* rfc 3022 */
|
||||
|
||||
#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_MPLSCP 0x8281 /* rfc 3022 */
|
||||
|
||||
#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,431 +0,0 @@
|
|||
%{
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /cvsroot/src/dist/libpcap/Attic/scanner.l,v 1.3 2009/10/29 14:49:03 christos Exp $ (LBL)";
|
||||
#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>
|
||||
#include "tokdefs.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static int stoi(char *);
|
||||
static inline int xdtoi(int);
|
||||
|
||||
#ifdef FLEX_SCANNER
|
||||
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
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
%}
|
||||
|
||||
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})
|
||||
|
||||
%option nounput
|
||||
|
||||
%%
|
||||
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;
|
||||
radio return RADIO;
|
||||
|
||||
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;
|
||||
portrange return PORTRANGE;
|
||||
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;
|
||||
mpls return MPLS;
|
||||
pppoed return PPPOED;
|
||||
pppoes return PPPOES;
|
||||
|
||||
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;
|
||||
|
||||
sio return SIO;
|
||||
opc return OPC;
|
||||
dpc return DPC;
|
||||
sls return SLS;
|
||||
|
||||
[ \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)
|
||||
const 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,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/dist/libpcap/Attic/sll.h,v 1.1.1.1 2006/02/27 15:45:49 drochner 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,45 +0,0 @@
|
|||
/*
|
||||
* 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: /cvsroot/src/dist/libpcap/Attic/sunatmpos.h,v 1.1.1.1 2006/02/27 15:45:49 drochner 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,932 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
This file lists all bug fixes, changes, etc., made since the AWK book
|
||||
was sent to the printers in August, 1987.
|
||||
|
||||
May 1, 2007:
|
||||
fiddle in makefile to fix for BSD make; thanks to igor sobrado.
|
||||
|
||||
Mar 31, 2007:
|
||||
fixed some null pointer refs calling adjbuf.
|
||||
|
||||
Feb 21, 2007:
|
||||
fixed a bug in matching the null RE in sub and gsub. thanks to al aho
|
||||
who actually did the fix (in b.c), and to wolfgang seeberg for finding
|
||||
it and providing a very compact test case.
|
||||
|
||||
fixed quotation in b.c; thanks to Hal Pratt and the Princeton Dante
|
||||
Project.
|
||||
|
||||
removed some no-effect asserts in run.c.
|
||||
|
||||
fiddled maketab.c to not complain about bison-generated values.
|
||||
|
||||
removed the obsolete -V argument; fixed --version to print the
|
||||
version and exit.
|
||||
|
||||
fixed wording and an outright error in the usage message; thanks to igor
|
||||
sobrado and jason mcintyre.
|
||||
|
||||
fixed a bug in -d that caused core dump if no program followed.
|
||||
|
||||
Jan 1, 2007:
|
||||
dropped mac.code from makefile; there are few non-MacOSX
|
||||
mac's these days.
|
||||
|
||||
Jan 17, 2006:
|
||||
system() not flagged as unsafe in the unadvertised -safe option.
|
||||
found it while enhancing tests before shipping the ;login: article.
|
||||
practice what you preach.
|
||||
|
||||
removed the 9-years-obsolete -mr and -mf flags.
|
||||
|
||||
added -version and --version options.
|
||||
|
||||
core dump on linux with BEGIN {nextfile}, now fixed.
|
||||
|
||||
removed some #ifdef's in run.c and lex.c that appear to no
|
||||
longer be necessary.
|
||||
|
||||
Apr 24, 2005:
|
||||
modified lib.c so that values of $0 et al are preserved in the END
|
||||
block, apparently as required by posix. thanks to havard eidnes
|
||||
for the report and code.
|
||||
|
||||
Jan 14, 2005:
|
||||
fixed infinite loop in parsing, originally found by brian tsang.
|
||||
thanks to arnold robbins for a suggestion that started me
|
||||
rethinking it.
|
||||
|
||||
Dec 31, 2004:
|
||||
prevent overflow of -f array in main, head off potential error in
|
||||
call of SYNTAX(), test malloc return in lib.c, all with thanks to
|
||||
todd miller.
|
||||
|
||||
Dec 22, 2004:
|
||||
cranked up size of NCHARS; coverity thinks it can be overrun with
|
||||
smaller size, and i think that's right. added some assertions to b.c
|
||||
to catch places where it might overrun. the RE code is still fragile.
|
||||
|
||||
Dec 5, 2004:
|
||||
fixed a couple of overflow problems with ridiculous field numbers:
|
||||
e.g., print $(2^32-1). thanks to ruslan ermilov, giorgos keramidas
|
||||
and david o'brien at freebsd.org for patches. this really should
|
||||
be re-done from scratch.
|
||||
|
||||
Nov 21, 2004:
|
||||
fixed another 25-year-old RE bug, in split. it's another failure
|
||||
to (re-)initialize. thanks to steve fisher for spotting this and
|
||||
providing a good test case.
|
||||
|
||||
Nov 22, 2003:
|
||||
fixed a bug in regular expressions that dates (so help me) from 1977;
|
||||
it's been there from the beginning. an anchored longest match that
|
||||
was longer than the number of states triggered a failure to initialize
|
||||
the machine properly. many thanks to moinak ghosh for not only finding
|
||||
this one but for providing a fix, in some of the most mysterious
|
||||
code known to man.
|
||||
|
||||
fixed a storage leak in call() that appears to have been there since
|
||||
1983 or so -- a function without an explicit return that assigns a
|
||||
string to a parameter leaked a Cell. thanks to moinak ghosh for
|
||||
spotting this very subtle one.
|
||||
|
||||
Jul 31, 2003:
|
||||
fixed, thanks to andrey chernov and ruslan ermilov, a bug in lex.c
|
||||
that mis-handled the character 255 in input. (it was being compared
|
||||
to EOF with a signed comparison.)
|
||||
|
||||
Jul 29, 2003:
|
||||
fixed (i think) the long-standing botch that included the beginning of
|
||||
line state ^ for RE's in the set of valid characters; this led to a
|
||||
variety of odd problems, including failure to properly match certain
|
||||
regular expressions in non-US locales. thanks to ruslan for keeping
|
||||
at this one.
|
||||
|
||||
Jul 28, 2003:
|
||||
n-th try at getting internationalization right, with thanks to volker
|
||||
kiefel, arnold robbins and ruslan ermilov for advice, though they
|
||||
should not be blamed for the outcome. according to posix, "." is the
|
||||
radix character in programs and command line arguments regardless of
|
||||
the locale; otherwise, the locale should prevail for input and output
|
||||
of numbers. so it's intended to work that way.
|
||||
|
||||
i have rescinded the attempt to use strcoll in expanding shorthands in
|
||||
regular expressions (cclenter). its properties are much too
|
||||
surprising; for example [a-c] matches aAbBc in locale en_US but abBcC
|
||||
in locale fr_CA. i can see how this might arise by implementation
|
||||
but i cannot explain it to a human user. (this behavior can be seen
|
||||
in gawk as well; we're leaning on the same library.)
|
||||
|
||||
the issue appears to be that strcoll is meant for sorting, where
|
||||
merging upper and lower case may make sense (though note that unix
|
||||
sort does not do this by default either). it is not appropriate
|
||||
for regular expressions, where the goal is to match specific
|
||||
patterns of characters. in any case, the notations [:lower:], etc.,
|
||||
are available in awk, and they are more likely to work correctly in
|
||||
most locales.
|
||||
|
||||
a moratorium is hereby declared on internationalization changes.
|
||||
i apologize to friends and colleagues in other parts of the world.
|
||||
i would truly like to get this "right", but i don't know what
|
||||
that is, and i do not want to keep making changes until it's clear.
|
||||
|
||||
Jul 4, 2003:
|
||||
fixed bug that permitted non-terminated RE, as in "awk /x".
|
||||
|
||||
Jun 1, 2003:
|
||||
subtle change to split: if source is empty, number of elems
|
||||
is always 0 and the array is not set.
|
||||
|
||||
Mar 21, 2003:
|
||||
added some parens to isblank, in another attempt to make things
|
||||
internationally portable.
|
||||
|
||||
Mar 14, 2003:
|
||||
the internationalization changes, somewhat modified, are now
|
||||
reinstated. in theory awk will now do character comparisons
|
||||
and case conversions in national language, but "." will always
|
||||
be the decimal point separator on input and output regardless
|
||||
of national language. isblank(){} has an #ifndef.
|
||||
|
||||
this no longer compiles on windows: LC_MESSAGES isn't defined
|
||||
in vc6++.
|
||||
|
||||
fixed subtle behavior in field and record splitting: if FS is
|
||||
a single character and RS is not empty, \n is NOT a separator.
|
||||
this tortuous reading is found in the awk book; behavior now
|
||||
matches gawk and mawk.
|
||||
|
||||
Dec 13, 2002:
|
||||
for the moment, the internationalization changes of nov 29 are
|
||||
rolled back -- programs like x = 1.2 don't work in some locales,
|
||||
because the parser is expecting x = 1,2. until i understand this
|
||||
better, this will have to wait.
|
||||
|
||||
Nov 29, 2002:
|
||||
modified b.c (with tiny changes in main and run) to support
|
||||
locales, using strcoll and iswhatever tests for posix character
|
||||
classes. thanks to ruslan ermilov (ru@freebsd.org) for code.
|
||||
the function isblank doesn't seem to have propagated to any
|
||||
header file near me, so it's there explicitly. not properly
|
||||
tested on non-ascii character sets by me.
|
||||
|
||||
Jun 28, 2002:
|
||||
modified run/format() and tran/getsval() to do a slightly better
|
||||
job on using OFMT for output from print and CONVFMT for other
|
||||
number->string conversions, as promised by posix and done by
|
||||
gawk and mawk. there are still places where it doesn't work
|
||||
right if CONVFMT is changed; by then the STR attribute of the
|
||||
variable has been irrevocably set. thanks to arnold robbins for
|
||||
code and examples.
|
||||
|
||||
fixed subtle bug in format that could get core dump. thanks to
|
||||
Jaromir Dolecek <jdolecek@NetBSD.org> for finding and fixing.
|
||||
minor cleanup in run.c / format() at the same time.
|
||||
|
||||
added some tests for null pointers to debugging printf's, which
|
||||
were never intended for external consumption. thanks to dave
|
||||
kerns (dkerns@lucent.com) for pointing this out.
|
||||
|
||||
GNU compatibility: an empty regexp matches anything (thanks to
|
||||
dag-erling smorgrav, des@ofug.org). subject to reversion if
|
||||
this does more harm than good.
|
||||
|
||||
pervasive small changes to make things more const-correct, as
|
||||
reported by gcc's -Wwrite-strings. as it says in the gcc manual,
|
||||
this may be more nuisance than useful. provoked by a suggestion
|
||||
and code from arnaud desitter, arnaud@nimbus.geog.ox.ac.uk
|
||||
|
||||
minor documentation changes to note that this now compiles out
|
||||
of the box on Mac OS X.
|
||||
|
||||
Feb 10, 2002:
|
||||
changed types in posix chars structure to quiet solaris cc.
|
||||
|
||||
Jan 1, 2002:
|
||||
fflush() or fflush("") flushes all files and pipes.
|
||||
|
||||
length(arrayname) returns number of elements; thanks to
|
||||
arnold robbins for suggestion.
|
||||
|
||||
added a makefile.win to make it easier to build on windows.
|
||||
based on dan allen's buildwin.bat.
|
||||
|
||||
Nov 16, 2001:
|
||||
added support for posix character class names like [:digit:],
|
||||
which are not exactly shorter than [0-9] and perhaps no more
|
||||
portable. thanks to dag-erling smorgrav for code.
|
||||
|
||||
Feb 16, 2001:
|
||||
removed -m option; no longer needed, and it was actually
|
||||
broken (noted thanks to volker kiefel).
|
||||
|
||||
Feb 10, 2001:
|
||||
fixed an appalling bug in gettok: any sequence of digits, +,-, E, e,
|
||||
and period was accepted as a valid number if it started with a period.
|
||||
this would never have happened with the lex version.
|
||||
|
||||
other 1-character botches, now fixed, include a bare $ and a
|
||||
bare " at the end of the input.
|
||||
|
||||
Feb 7, 2001:
|
||||
more (const char *) casts in b.c and tran.c to silence warnings.
|
||||
|
||||
Nov 15, 2000:
|
||||
fixed a bug introduced in august 1997 that caused expressions
|
||||
like $f[1] to be syntax errors. thanks to arnold robbins for
|
||||
noticing this and providing a fix.
|
||||
|
||||
Oct 30, 2000:
|
||||
fixed some nextfile bugs: not handling all cases. thanks to
|
||||
arnold robbins for pointing this out. new regressions added.
|
||||
|
||||
close() is now a function. it returns whatever the library
|
||||
fclose returns, and -1 for closing a file or pipe that wasn't
|
||||
opened.
|
||||
|
||||
Sep 24, 2000:
|
||||
permit \n explicitly in character classes; won't work right
|
||||
if comes in as "[\n]" but ok as /[\n]/, because of multiple
|
||||
processing of \'s. thanks to arnold robbins.
|
||||
|
||||
July 5, 2000:
|
||||
minor fiddles in tran.c to keep compilers happy about uschar.
|
||||
thanks to norman wilson.
|
||||
|
||||
May 25, 2000:
|
||||
yet another attempt at making 8-bit input work, with another
|
||||
band-aid in b.c (member()), and some (uschar) casts to head
|
||||
off potential errors in subscripts (like isdigit). also
|
||||
changed HAT to NCHARS-2. thanks again to santiago vila.
|
||||
|
||||
changed maketab.c to ignore apparently out of range definitions
|
||||
instead of halting; new freeBSD generates one. thanks to
|
||||
jon snader <jsnader@ix.netcom.com> for pointing out the problem.
|
||||
|
||||
May 2, 2000:
|
||||
fixed an 8-bit problem in b.c by making several char*'s into
|
||||
unsigned char*'s. not clear i have them all yet. thanks to
|
||||
Santiago Vila <sanvila@unex.es> for the bug report.
|
||||
|
||||
Apr 21, 2000:
|
||||
finally found and fixed a memory leak in function call; it's
|
||||
been there since functions were added ~1983. thanks to
|
||||
jon bentley for the test case that found it.
|
||||
|
||||
added test in envinit to catch environment "variables" with
|
||||
names beginning with '='; thanks to Berend Hasselman.
|
||||
|
||||
Jul 28, 1999:
|
||||
added test in defn() to catch function foo(foo), which
|
||||
otherwise recurses until core dump. thanks to arnold
|
||||
robbins for noticing this.
|
||||
|
||||
Jun 20, 1999:
|
||||
added *bp in gettok in lex.c; appears possible to exit function
|
||||
without terminating the string. thanks to russ cox.
|
||||
|
||||
Jun 2, 1999:
|
||||
added function stdinit() to run to initialize files[] array,
|
||||
in case stdin, etc., are not constants; some compilers care.
|
||||
|
||||
May 10, 1999:
|
||||
replaced the ERROR ... FATAL, etc., macros with functions
|
||||
based on vprintf, to avoid problems caused by overrunning
|
||||
fixed-size errbuf array. thanks to ralph corderoy for the
|
||||
impetus, and for pointing out a string termination bug in
|
||||
qstring as well.
|
||||
|
||||
Apr 21, 1999:
|
||||
fixed bug that caused occasional core dumps with commandline
|
||||
variable with value ending in \. (thanks to nelson beebe for
|
||||
the test case.)
|
||||
|
||||
Apr 16, 1999:
|
||||
with code kindly provided by Bruce Lilly, awk now parses
|
||||
/=/ and similar constructs more sensibly in more places.
|
||||
Bruce also provided some helpful test cases.
|
||||
|
||||
Apr 5, 1999:
|
||||
changed true/false to True/False in run.c to make it
|
||||
easier to compile with C++. Added some casts on malloc
|
||||
and realloc to be honest about casts; ditto. changed
|
||||
ltype int to long in struct rrow to reduce some 64-bit
|
||||
complaints; other changes scattered throughout for the
|
||||
same purpose. thanks to Nelson Beebe for these portability
|
||||
improvements.
|
||||
|
||||
removed some horrible pointer-int casting in b.c and elsewhere
|
||||
by adding ptoi and itonp to localize the casts, which are
|
||||
all benign. fixed one incipient bug that showed up on sgi
|
||||
in 64-bit mode.
|
||||
|
||||
reset lineno for new source file; include filename in error
|
||||
message. also fixed line number error in continuation lines.
|
||||
(thanks to Nelson Beebe for both of these.)
|
||||
|
||||
Mar 24, 1999:
|
||||
Nelson Beebe notes that irix 5.3 yacc dies with a bogus
|
||||
error; use a newer version or switch to bison, since sgi
|
||||
is unlikely to fix it.
|
||||
|
||||
Mar 5, 1999:
|
||||
changed isnumber to is_number to avoid the problem caused by
|
||||
versions of ctype.h that include the name isnumber.
|
||||
|
||||
distribution now includes a script for building on a Mac,
|
||||
thanks to Dan Allen.
|
||||
|
||||
Feb 20, 1999:
|
||||
fixed memory leaks in run.c (call) and tran.c (setfval).
|
||||
thanks to Stephen Nutt for finding these and providing the fixes.
|
||||
|
||||
Jan 13, 1999:
|
||||
replaced srand argument by (unsigned int) in run.c;
|
||||
avoids problem on Mac and potentially on Unix & Windows.
|
||||
thanks to Dan Allen.
|
||||
|
||||
added a few (int) casts to silence useless compiler warnings.
|
||||
e.g., errorflag= in run.c jump().
|
||||
|
||||
added proctab.c to the bundle outout; one less thing
|
||||
to have to compile out of the box.
|
||||
|
||||
added calls to _popen and _pclose to the win95 stub for
|
||||
pipes (thanks to Steve Adams for this helpful suggestion).
|
||||
seems to work, though properties are not well understood
|
||||
by me, and it appears that under some circumstances the
|
||||
pipe output is truncated. Be careful.
|
||||
|
||||
Oct 19, 1998:
|
||||
fixed a couple of bugs in getrec: could fail to update $0
|
||||
after a getline var; because inputFS wasn't initialized,
|
||||
could split $0 on every character, a misleading diversion.
|
||||
|
||||
fixed caching bug in makedfa: LRU was actually removing
|
||||
least often used.
|
||||
|
||||
thanks to ross ridge for finding these, and for providing
|
||||
great bug reports.
|
||||
|
||||
May 12, 1998:
|
||||
fixed potential bug in readrec: might fail to update record
|
||||
pointer after growing. thanks to dan levy for spotting this
|
||||
and suggesting the fix.
|
||||
|
||||
Mar 12, 1998:
|
||||
added -V to print version number and die.
|
||||
|
||||
Feb 11, 1998:
|
||||
subtle silent bug in lex.c: if the program ended with a number
|
||||
longer than 1 digit, part of the input would be pushed back and
|
||||
parsed again because token buffer wasn't terminated right.
|
||||
example: awk 'length($0) > 10'. blush. at least i found it
|
||||
myself.
|
||||
|
||||
Aug 31, 1997:
|
||||
s/adelete/awkdelete/: SGI uses this in malloc.h.
|
||||
thanks to nelson beebe for pointing this one out.
|
||||
|
||||
Aug 21, 1997:
|
||||
fixed some bugs in sub and gsub when replacement includes \\.
|
||||
this is a dark, horrible corner, but at least now i believe that
|
||||
the behavior is the same as gawk and the intended posix standard.
|
||||
thanks to arnold robbins for advice here.
|
||||
|
||||
Aug 9, 1997:
|
||||
somewhat regretfully, replaced the ancient lex-based lexical
|
||||
analyzer with one written in C. it's longer, generates less code,
|
||||
and more portable; the old one depended too much on mysterious
|
||||
properties of lex that were not preserved in other environments.
|
||||
in theory these recognize the same language.
|
||||
|
||||
now using strtod to test whether a string is a number, instead of
|
||||
the convoluted original function. should be more portable and
|
||||
reliable if strtod is implemented right.
|
||||
|
||||
removed now-pointless optimization in makefile that tries to avoid
|
||||
recompilation when awkgram.y is changed but symbols are not.
|
||||
|
||||
removed most fixed-size arrays, though a handful remain, some
|
||||
of which are unchecked. you have been warned.
|
||||
|
||||
Aug 4, 1997:
|
||||
with some trepidation, replaced the ancient code that managed
|
||||
fields and $0 in fixed-size arrays with arrays that grow on
|
||||
demand. there is still some tension between trying to make this
|
||||
run fast and making it clean; not sure it's right yet.
|
||||
|
||||
the ill-conceived -mr and -mf arguments are now useful only
|
||||
for debugging. previous dynamic string code removed.
|
||||
|
||||
numerous other minor cleanups along the way.
|
||||
|
||||
Jul 30, 1997:
|
||||
using code provided by dan levy (to whom profuse thanks), replaced
|
||||
fixed-size arrays and awkward kludges by a fairly uniform mechanism
|
||||
to grow arrays as needed for printf, sub, gsub, etc.
|
||||
|
||||
Jul 23, 1997:
|
||||
falling off the end of a function returns "" and 0, not 0.
|
||||
thanks to arnold robbins.
|
||||
|
||||
Jun 17, 1997:
|
||||
replaced several fixed-size arrays by dynamically-created ones
|
||||
in run.c; added overflow tests to some previously unchecked cases.
|
||||
getline, toupper, tolower.
|
||||
|
||||
getline code is still broken in that recursive calls may wind
|
||||
up using the same space. [fixed later]
|
||||
|
||||
increased RECSIZE to 8192 to push problems further over the horizon.
|
||||
|
||||
added \r to \n as input line separator for programs, not data.
|
||||
damn CRLFs.
|
||||
|
||||
modified format() to permit explicit printf("%c", 0) to include
|
||||
a null byte in output. thanks to ken stailey for the fix.
|
||||
|
||||
added a "-safe" argument that disables file output (print >,
|
||||
print >>), process creation (cmd|getline, print |, system), and
|
||||
access to the environment (ENVIRON). this is a first approximation
|
||||
to a "safe" version of awk, but don't rely on it too much. thanks
|
||||
to joan feigenbaum and matt blaze for the inspiration long ago.
|
||||
|
||||
Jul 8, 1996:
|
||||
fixed long-standing bug in sub, gsub(/a/, "\\\\&"); thanks to
|
||||
ralph corderoy.
|
||||
|
||||
Jun 29, 1996:
|
||||
fixed awful bug in new field splitting; didn't get all the places
|
||||
where input was done.
|
||||
|
||||
Jun 28, 1996:
|
||||
changed field-splitting to conform to posix definition: fields are
|
||||
split using the value of FS at the time of input; it used to be
|
||||
the value when the field or NF was first referred to, a much less
|
||||
predictable definition. thanks to arnold robbins for encouragement
|
||||
to do the right thing.
|
||||
|
||||
May 28, 1996:
|
||||
fixed appalling but apparently unimportant bug in parsing octal
|
||||
numbers in reg exprs.
|
||||
|
||||
explicit hex in reg exprs now limited to 2 chars: \xa, \xaa.
|
||||
|
||||
May 27, 1996:
|
||||
cleaned up some declarations so gcc -Wall is now almost silent.
|
||||
|
||||
makefile now includes backup copies of ytab.c and lexyy.c in case
|
||||
one makes before looking; it also avoids recreating lexyy.c unless
|
||||
really needed.
|
||||
|
||||
s/aprintf/awkprint, s/asprintf/awksprintf/ to avoid some name clashes
|
||||
with unwisely-written header files.
|
||||
|
||||
thanks to jeffrey friedl for several of these.
|
||||
|
||||
May 26, 1996:
|
||||
an attempt to rationalize the (unsigned) char issue. almost all
|
||||
instances of unsigned char have been removed; the handful of places
|
||||
in b.c where chars are used as table indices have been hand-crafted.
|
||||
added some latin-1 tests to the regression, but i'm not confident;
|
||||
none of my compilers seem to care much. thanks to nelson beebe for
|
||||
pointing out some others that do care.
|
||||
|
||||
May 2, 1996:
|
||||
removed all register declarations.
|
||||
|
||||
enhanced split(), as in gawk, etc: split(s, a, "") splits s into
|
||||
a[1]...a[length(s)] with each character a single element.
|
||||
|
||||
made the same changes for field-splitting if FS is "".
|
||||
|
||||
added nextfile, as in gawk: causes immediate advance to next
|
||||
input file. (thanks to arnold robbins for inspiration and code).
|
||||
|
||||
small fixes to regexpr code: can now handle []], [[], and
|
||||
variants; [] is now a syntax error, rather than matching
|
||||
everything; [z-a] is now empty, not z. far from complete
|
||||
or correct, however. (thanks to jeffrey friedl for pointing out
|
||||
some awful behaviors.)
|
||||
|
||||
Apr 29, 1996:
|
||||
replaced uchar by uschar everywhere; apparently some compilers
|
||||
usurp this name and this causes conflicts.
|
||||
|
||||
fixed call to time in run.c (bltin); arg is time_t *.
|
||||
|
||||
replaced horrible pointer/long punning in b.c by a legitimate
|
||||
union. should be safer on 64-bit machines and cleaner everywhere.
|
||||
(thanks to nelson beebe for pointing out some of these problems.)
|
||||
|
||||
replaced nested comments by #if 0...#endif in run.c, lib.c.
|
||||
|
||||
removed getsval, setsval, execute macros from run.c and lib.c.
|
||||
machines are 100x faster than they were when these macros were
|
||||
first used.
|
||||
|
||||
revised filenames: awk.g.y => awkgram.y, awk.lx.l => awklex.l,
|
||||
y.tab.[ch] => ytab.[ch], lex.yy.c => lexyy.c, all in the aid of
|
||||
portability to nameless systems.
|
||||
|
||||
"make bundle" now includes yacc and lex output files for recipients
|
||||
who don't have yacc or lex.
|
||||
|
||||
Aug 15, 1995:
|
||||
initialized Cells in setsymtab more carefully; some fields
|
||||
were not set. (thanks to purify, all of whose complaints i
|
||||
think i now understand.)
|
||||
|
||||
fixed at least one error in gsub that looked at -1-th element
|
||||
of an array when substituting for a null match (e.g., $).
|
||||
|
||||
delete arrayname is now legal; it clears the elements but leaves
|
||||
the array, which may not be the right behavior.
|
||||
|
||||
modified makefile: my current make can't cope with the test used
|
||||
to avoid unnecessary yacc invocations.
|
||||
|
||||
Jul 17, 1995:
|
||||
added dynamically growing strings to awk.lx.l and b.c
|
||||
to permit regular expressions to be much bigger.
|
||||
the state arrays can still overflow.
|
||||
|
||||
Aug 24, 1994:
|
||||
detect duplicate arguments in function definitions (mdm).
|
||||
|
||||
May 11, 1994:
|
||||
trivial fix to printf to limit string size in sub().
|
||||
|
||||
Apr 22, 1994:
|
||||
fixed yet another subtle self-assignment problem:
|
||||
$1 = $2; $1 = $1 clobbered $1.
|
||||
|
||||
Regression tests now use private echo, to avoid quoting problems.
|
||||
|
||||
Feb 2, 1994:
|
||||
changed error() to print line number as %d, not %g.
|
||||
|
||||
Jul 23, 1993:
|
||||
cosmetic changes: increased sizes of some arrays,
|
||||
reworded some error messages.
|
||||
|
||||
added CONVFMT as in posix (just replaced OFMT in getsval)
|
||||
|
||||
FILENAME is now "" until the first thing that causes a file
|
||||
to be opened.
|
||||
|
||||
Nov 28, 1992:
|
||||
deleted yyunput and yyoutput from proto.h;
|
||||
different versions of lex give these different declarations.
|
||||
|
||||
May 31, 1992:
|
||||
added -mr N and -mf N options: more record and fields.
|
||||
these really ought to adjust automatically.
|
||||
|
||||
cleaned up some error messages; "out of space" now means
|
||||
malloc returned NULL in all cases.
|
||||
|
||||
changed rehash so that if it runs out, it just returns;
|
||||
things will continue to run slow, but maybe a bit longer.
|
||||
|
||||
Apr 24, 1992:
|
||||
remove redundant close of stdin when using -f -.
|
||||
|
||||
got rid of core dump with -d; awk -d just prints date.
|
||||
|
||||
Apr 12, 1992:
|
||||
added explicit check for /dev/std(in,out,err) in redirection.
|
||||
unlike gawk, no /dev/fd/n yet.
|
||||
|
||||
added (file/pipe) builtin. hard to test satisfactorily.
|
||||
not posix.
|
||||
|
||||
Feb 20, 1992:
|
||||
recompile after abortive changes; should be unchanged.
|
||||
|
||||
Dec 2, 1991:
|
||||
die-casting time: converted to ansi C, installed that.
|
||||
|
||||
Nov 30, 1991:
|
||||
fixed storage leak in freefa, failing to recover [N]CCL.
|
||||
thanks to Bill Jones (jones@cs.usask.ca)
|
||||
|
||||
Nov 19, 1991:
|
||||
use RAND_MAX instead of literal in builtin().
|
||||
|
||||
Nov 12, 1991:
|
||||
cranked up some fixed-size arrays in b.c, and added a test for
|
||||
overflow in penter. thanks to mark larsen.
|
||||
|
||||
Sep 24, 1991:
|
||||
increased buffer in gsub. a very crude fix to a general problem.
|
||||
and again on Sep 26.
|
||||
|
||||
Aug 18, 1991:
|
||||
enforce variable name syntax for commandline variables: has to
|
||||
start with letter or _.
|
||||
|
||||
Jul 27, 1991:
|
||||
allow newline after ; in for statements.
|
||||
|
||||
Jul 21, 1991:
|
||||
fixed so that in self-assignment like $1=$1, side effects
|
||||
like recomputing $0 take place. (this is getting subtle.)
|
||||
|
||||
Jun 30, 1991:
|
||||
better test for detecting too-long output record.
|
||||
|
||||
Jun 2, 1991:
|
||||
better defense against very long printf strings.
|
||||
made break and continue illegal outside of loops.
|
||||
|
||||
May 13, 1991:
|
||||
removed extra arg on gettemp, tempfree. minor error message rewording.
|
||||
|
||||
May 6, 1991:
|
||||
fixed silly bug in hex parsing in hexstr().
|
||||
removed an apparently unnecessary test in isnumber().
|
||||
warn about weird printf conversions.
|
||||
fixed unchecked array overwrite in relex().
|
||||
|
||||
changed for (i in array) to access elements in sorted order.
|
||||
then unchanged it -- it really does run slower in too many cases.
|
||||
left the code in place, commented out.
|
||||
|
||||
Feb 10, 1991:
|
||||
check error status on all writes, to avoid banging on full disks.
|
||||
|
||||
Jan 28, 1991:
|
||||
awk -f - reads the program from stdin.
|
||||
|
||||
Jan 11, 1991:
|
||||
failed to set numeric state on $0 in cmd|getline context in run.c.
|
||||
|
||||
Nov 2, 1990:
|
||||
fixed sleazy test for integrality in getsval; use modf.
|
||||
|
||||
Oct 29, 1990:
|
||||
fixed sleazy buggy code in lib.c that looked (incorrectly) for
|
||||
too long input lines.
|
||||
|
||||
Oct 14, 1990:
|
||||
fixed the bug on p. 198 in which it couldn't deduce that an
|
||||
argument was an array in some contexts. replaced the error
|
||||
message in intest() by code that damn well makes it an array.
|
||||
|
||||
Oct 8, 1990:
|
||||
fixed horrible bug: types and values were not preserved in
|
||||
some kinds of self-assignment. (in assign().)
|
||||
|
||||
Aug 24, 1990:
|
||||
changed NCHARS to 256 to handle 8-bit characters in strings
|
||||
presented to match(), etc.
|
||||
|
||||
Jun 26, 1990:
|
||||
changed struct rrow (awk.h) to use long instead of int for lval,
|
||||
since cfoll() stores a pointer in it. now works better when int's
|
||||
are smaller than pointers!
|
||||
|
||||
May 6, 1990:
|
||||
AVA fixed the grammar so that ! is uniformly of the same precedence as
|
||||
unary + and -. This renders illegal some constructs like !x=y, which
|
||||
now has to be parenthesized as !(x=y), and makes others work properly:
|
||||
!x+y is (!x)+y, and x!y is x !y, not two pattern-action statements.
|
||||
(These problems were pointed out by Bob Lenk of Posix.)
|
||||
|
||||
Added \x to regular expressions (already in strings).
|
||||
Limited octal to octal digits; \8 and \9 are not octal.
|
||||
Centralized the code for parsing escapes in regular expressions.
|
||||
Added a bunch of tests to T.re and T.sub to verify some of this.
|
||||
|
||||
Feb 9, 1990:
|
||||
fixed null pointer dereference bug in main.c: -F[nothing]. sigh.
|
||||
|
||||
restored srand behavior: it returns the current seed.
|
||||
|
||||
Jan 18, 1990:
|
||||
srand now returns previous seed value (0 to start).
|
||||
|
||||
Jan 5, 1990:
|
||||
fix potential problem in tran.c -- something was freed,
|
||||
then used in freesymtab.
|
||||
|
||||
Oct 18, 1989:
|
||||
another try to get the max number of open files set with
|
||||
relatively machine-independent code.
|
||||
|
||||
small fix to input() in case of multiple reads after EOF.
|
||||
|
||||
Oct 11, 1989:
|
||||
FILENAME is now defined in the BEGIN block -- too many old
|
||||
programs broke.
|
||||
|
||||
"-" means stdin in getline as well as on the commandline.
|
||||
|
||||
added a bunch of casts to the code to tell the truth about
|
||||
char * vs. unsigned char *, a right royal pain. added a
|
||||
setlocale call to the front of main, though probably no one
|
||||
has it usefully implemented yet.
|
||||
|
||||
Aug 24, 1989:
|
||||
removed redundant relational tests against nullnode if parse
|
||||
tree already had a relational at that point.
|
||||
|
||||
Aug 11, 1989:
|
||||
fixed bug: commandline variable assignment has to look like
|
||||
var=something. (consider the man page for =, in file =.1)
|
||||
|
||||
changed number of arguments to functions to static arrays
|
||||
to avoid repeated malloc calls.
|
||||
|
||||
Aug 2, 1989:
|
||||
restored -F (space) separator
|
||||
|
||||
Jul 30, 1989:
|
||||
added -v x=1 y=2 ... for immediate commandline variable assignment;
|
||||
done before the BEGIN block for sure. they have to precede the
|
||||
program if the program is on the commandline.
|
||||
Modified Aug 2 to require a separate -v for each assignment.
|
||||
|
||||
Jul 10, 1989:
|
||||
fixed ref-thru-zero bug in environment code in tran.c
|
||||
|
||||
Jun 23, 1989:
|
||||
add newline to usage message.
|
||||
|
||||
Jun 14, 1989:
|
||||
added some missing ansi printf conversion letters: %i %X %E %G.
|
||||
no sensible meaning for h or L, so they may not do what one expects.
|
||||
|
||||
made %* conversions work.
|
||||
|
||||
changed x^y so that if n is a positive integer, it's done
|
||||
by explicit multiplication, thus achieving maximum accuracy.
|
||||
(this should be done by pow() but it seems not to be locally.)
|
||||
done to x ^= y as well.
|
||||
|
||||
Jun 4, 1989:
|
||||
ENVIRON array contains environment: if shell variable V=thing,
|
||||
ENVIRON["V"] is "thing"
|
||||
|
||||
multiple -f arguments permitted. error reporting is naive.
|
||||
(they were permitted before, but only the last was used.)
|
||||
|
||||
fixed a really stupid botch in the debugging macro dprintf
|
||||
|
||||
fixed order of evaluation of commandline assignments to match
|
||||
what the book claims: an argument of the form x=e is evaluated
|
||||
at the time it would have been opened if it were a filename (p 63).
|
||||
this invalidates the suggested answer to ex 4-1 (p 195).
|
||||
|
||||
removed some code that permitted -F (space) fieldseparator,
|
||||
since it didn't quite work right anyway. (restored aug 2)
|
||||
|
||||
Apr 27, 1989:
|
||||
Line number now accumulated correctly for comment lines.
|
||||
|
||||
Apr 26, 1989:
|
||||
Debugging output now includes a version date,
|
||||
if one compiles it into the source each time.
|
||||
|
||||
Apr 9, 1989:
|
||||
Changed grammar to prohibit constants as 3rd arg of sub and gsub;
|
||||
prevents class of overwriting-a-constant errors. (Last one?)
|
||||
This invalidates the "banana" example on page 43 of the book.
|
||||
|
||||
Added \a ("alert"), \v (vertical tab), \xhhh (hexadecimal),
|
||||
as in ANSI, for strings. Rescinded the sloppiness that permitted
|
||||
non-octal digits in \ooo. Warning: not all compilers and libraries
|
||||
will be able to deal with \x correctly.
|
||||
|
||||
Jan 9, 1989:
|
||||
Fixed bug that caused tempcell list to contain a duplicate.
|
||||
The fix is kludgy.
|
||||
|
||||
Dec 17, 1988:
|
||||
Catches some more commandline errors in main.
|
||||
Removed redundant decl of modf in run.c (confuses some compilers).
|
||||
Warning: there's no single declaration of malloc, etc., in awk.h
|
||||
that seems to satisfy all compilers.
|
||||
|
||||
Dec 7, 1988:
|
||||
Added a bit of code to error printing to avoid printing nulls.
|
||||
(Not clear that it actually would.)
|
||||
|
||||
Nov 27, 1988:
|
||||
With fear and trembling, modified the grammar to permit
|
||||
multiple pattern-action statements on one line without
|
||||
an explicit separator. By definition, this capitulation
|
||||
to the ghost of ancient implementations remains undefined
|
||||
and thus subject to change without notice or apology.
|
||||
DO NOT COUNT ON IT.
|
||||
|
||||
Oct 30, 1988:
|
||||
Fixed bug in call() that failed to recover storage.
|
||||
|
||||
A warning is now generated if there are more arguments
|
||||
in the call than in the definition (in lieu of fixing
|
||||
another storage leak).
|
||||
|
||||
Oct 20, 1988:
|
||||
Fixed %c: if expr is numeric, use numeric value;
|
||||
otherwise print 1st char of string value. still
|
||||
doesn't work if the value is 0 -- won't print \0.
|
||||
|
||||
Added a few more checks for running out of malloc.
|
||||
|
||||
Oct 12, 1988:
|
||||
Fixed bug in call() that freed local arrays twice.
|
||||
|
||||
Fixed to handle deletion of non-existent array right;
|
||||
complains about attempt to delete non-array element.
|
||||
|
||||
Sep 30, 1988:
|
||||
Now guarantees to evaluate all arguments of built-in
|
||||
functions, as in C; the appearance is that arguments
|
||||
are evaluated before the function is called. Places
|
||||
affected are sub (gsub was ok), substr, printf, and
|
||||
all the built-in arithmetic functions in bltin().
|
||||
A warning is generated if a bltin() is called with
|
||||
the wrong number of arguments.
|
||||
|
||||
This requires changing makeprof on p167 of the book.
|
||||
|
||||
Aug 23, 1988:
|
||||
setting FILENAME in BEGIN caused core dump, apparently
|
||||
because it was freeing space not allocated by malloc.
|
||||
|
||||
July 24, 1988:
|
||||
fixed egregious error in toupper/tolower functions.
|
||||
still subject to rescinding, however.
|
||||
|
||||
July 2, 1988:
|
||||
flush stdout before opening file or pipe
|
||||
|
||||
July 2, 1988:
|
||||
performance bug in b.c/cgoto(): not freeing some sets of states.
|
||||
partial fix only right now, and the number of states increased
|
||||
to make it less obvious.
|
||||
|
||||
June 1, 1988:
|
||||
check error status on close
|
||||
|
||||
May 28, 1988:
|
||||
srand returns seed value it's using.
|
||||
see 1/18/90
|
||||
|
||||
May 22, 1988:
|
||||
Removed limit on depth of function calls.
|
||||
|
||||
May 10, 1988:
|
||||
Fixed lib.c to permit _ in commandline variable names.
|
||||
|
||||
Mar 25, 1988:
|
||||
main.c fixed to recognize -- as terminator of command-
|
||||
line options. Illegal options flagged.
|
||||
Error reporting slightly cleaned up.
|
||||
|
||||
Dec 2, 1987:
|
||||
Newer C compilers apply a strict scope rule to extern
|
||||
declarations within functions. Two extern declarations in
|
||||
lib.c and tran.c have been moved to obviate this problem.
|
||||
|
||||
Oct xx, 1987:
|
||||
Reluctantly added toupper and tolower functions.
|
||||
Subject to rescinding without notice.
|
||||
|
||||
Sep 17, 1987:
|
||||
Error-message printer had printf(s) instead of
|
||||
printf("%s",s); got core dumps when the message
|
||||
included a %.
|
||||
|
||||
Sep 12, 1987:
|
||||
Very long printf strings caused core dump;
|
||||
fixed aprintf, asprintf, format to catch them.
|
||||
Can still get a core dump in printf itself.
|
||||
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
This is the version of awk described in "The AWK Programming Language",
|
||||
by Al Aho, Brian Kernighan, and Peter Weinberger
|
||||
(Addison-Wesley, 1988, ISBN 0-201-07981-X).
|
||||
|
||||
Changes, mostly bug fixes and occasional enhancements, are listed
|
||||
in FIXES. If you distribute this code further, please please please
|
||||
distribute FIXES with it. If you find errors, please report them
|
||||
to bwk@bell-labs.com. Thanks.
|
||||
|
||||
The program itself is created by
|
||||
make
|
||||
which should produce a sequence of messages roughly like this:
|
||||
|
||||
yacc -d awkgram.y
|
||||
|
||||
conflicts: 43 shift/reduce, 85 reduce/reduce
|
||||
mv y.tab.c ytab.c
|
||||
mv y.tab.h ytab.h
|
||||
cc -c ytab.c
|
||||
cc -c b.c
|
||||
cc -c main.c
|
||||
cc -c parse.c
|
||||
cc maketab.c -o maketab
|
||||
./maketab >proctab.c
|
||||
cc -c proctab.c
|
||||
cc -c tran.c
|
||||
cc -c lib.c
|
||||
cc -c run.c
|
||||
cc -c lex.c
|
||||
cc ytab.o b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o -lm
|
||||
|
||||
This produces an executable a.out; you will eventually want to
|
||||
move this to some place like /usr/bin/awk.
|
||||
|
||||
If your system does not have yacc or bison (the GNU
|
||||
equivalent), you must compile the pieces manually. We have
|
||||
included yacc output in ytab.c and ytab.h, and backup copies in
|
||||
case you overwrite them. We have also included a copy of
|
||||
proctab.c so you do not need to run maketab.
|
||||
|
||||
NOTE: This version uses ANSI C, as you should also. We have
|
||||
compiled this without any changes using gcc -Wall and/or local C
|
||||
compilers on a variety of systems, but new systems or compilers
|
||||
may raise some new complaint; reports of difficulties are
|
||||
welcome.
|
||||
|
||||
This also compiles with Visual C++ on all flavors of Windows,
|
||||
*if* you provide versions of popen and pclose. The file
|
||||
missing95.c contains versions that can be used to get started
|
||||
with, though the underlying support has mysterious properties,
|
||||
the symptom of which can be truncated pipe output. Beware. The
|
||||
file makefile.win gives hints on how to proceed; if you run
|
||||
vcvars32.bat, it will set up necessary paths and parameters so
|
||||
you can subsequently run nmake -f makefile.win. Beware also that
|
||||
when running on Windows under command.com, various quoting
|
||||
conventions are different from Unix systems: single quotes won't
|
||||
work around arguments, and various characters like % are
|
||||
interpreted within double quotes.
|
||||
|
||||
This compiles without change on Macintosh OS X using gcc and
|
||||
the standard developer tools.
|
||||
|
||||
This is also said to compile on Macintosh OS 9 systems, using the
|
||||
file "buildmac" provided by Dan Allen (danallen@microsoft.com),
|
||||
to whom many thanks.
|
||||
|
||||
The version of malloc that comes with some systems is sometimes
|
||||
astonishly slow. If awk seems slow, you might try fixing that.
|
||||
More generally, turning on optimization can significantly improve
|
||||
awk's speed, perhaps by 1/3 for highest levels.
|
|
@ -1,529 +0,0 @@
|
|||
.de EX
|
||||
.nf
|
||||
.ft CW
|
||||
..
|
||||
.de EE
|
||||
.br
|
||||
.fi
|
||||
.ft 1
|
||||
..
|
||||
awk
|
||||
.TH AWK 1
|
||||
.CT 1 files prog_other
|
||||
.SH NAME
|
||||
awk \- pattern-directed scanning and processing language
|
||||
.SH SYNOPSIS
|
||||
.B awk
|
||||
[
|
||||
.BI \-F
|
||||
.I fs
|
||||
]
|
||||
[
|
||||
.BI \-v
|
||||
.I var=value
|
||||
]
|
||||
[
|
||||
.I 'prog'
|
||||
|
|
||||
.BI \-f
|
||||
.I progfile
|
||||
]
|
||||
[
|
||||
.I file ...
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
.I Awk
|
||||
scans each input
|
||||
.I file
|
||||
for lines that match any of a set of patterns specified literally in
|
||||
.IR prog
|
||||
or in one or more files
|
||||
specified as
|
||||
.B \-f
|
||||
.IR progfile .
|
||||
With each pattern
|
||||
there can be an associated action that will be performed
|
||||
when a line of a
|
||||
.I file
|
||||
matches the pattern.
|
||||
Each line is matched against the
|
||||
pattern portion of every pattern-action statement;
|
||||
the associated action is performed for each matched pattern.
|
||||
The file name
|
||||
.B \-
|
||||
means the standard input.
|
||||
Any
|
||||
.IR file
|
||||
of the form
|
||||
.I var=value
|
||||
is treated as an assignment, not a filename,
|
||||
and is executed at the time it would have been opened if it were a filename.
|
||||
The option
|
||||
.B \-v
|
||||
followed by
|
||||
.I var=value
|
||||
is an assignment to be done before
|
||||
.I prog
|
||||
is executed;
|
||||
any number of
|
||||
.B \-v
|
||||
options may be present.
|
||||
The
|
||||
.B \-F
|
||||
.IR fs
|
||||
option defines the input field separator to be the regular expression
|
||||
.IR fs.
|
||||
.PP
|
||||
An input line is normally made up of fields separated by white space,
|
||||
or by regular expression
|
||||
.BR FS .
|
||||
The fields are denoted
|
||||
.BR $1 ,
|
||||
.BR $2 ,
|
||||
\&..., while
|
||||
.B $0
|
||||
refers to the entire line.
|
||||
If
|
||||
.BR FS
|
||||
is null, the input line is split into one field per character.
|
||||
.PP
|
||||
A pattern-action statement has the form
|
||||
.IP
|
||||
.IB pattern " { " action " }
|
||||
.PP
|
||||
A missing
|
||||
.BI { " action " }
|
||||
means print the line;
|
||||
a missing pattern always matches.
|
||||
Pattern-action statements are separated by newlines or semicolons.
|
||||
.PP
|
||||
An action is a sequence of statements.
|
||||
A statement can be one of the following:
|
||||
.PP
|
||||
.EX
|
||||
.ta \w'\f(CWdelete array[expression]'u
|
||||
.RS
|
||||
.nf
|
||||
.ft CW
|
||||
if(\fI expression \fP)\fI statement \fP\fR[ \fPelse\fI statement \fP\fR]\fP
|
||||
while(\fI expression \fP)\fI statement\fP
|
||||
for(\fI expression \fP;\fI expression \fP;\fI expression \fP)\fI statement\fP
|
||||
for(\fI var \fPin\fI array \fP)\fI statement\fP
|
||||
do\fI statement \fPwhile(\fI expression \fP)
|
||||
break
|
||||
continue
|
||||
{\fR [\fP\fI statement ... \fP\fR] \fP}
|
||||
\fIexpression\fP #\fR commonly\fP\fI var = expression\fP
|
||||
print\fR [ \fP\fIexpression-list \fP\fR] \fP\fR[ \fP>\fI expression \fP\fR]\fP
|
||||
printf\fI format \fP\fR[ \fP,\fI expression-list \fP\fR] \fP\fR[ \fP>\fI expression \fP\fR]\fP
|
||||
return\fR [ \fP\fIexpression \fP\fR]\fP
|
||||
next #\fR skip remaining patterns on this input line\fP
|
||||
nextfile #\fR skip rest of this file, open next, start at top\fP
|
||||
delete\fI array\fP[\fI expression \fP] #\fR delete an array element\fP
|
||||
delete\fI array\fP #\fR delete all elements of array\fP
|
||||
exit\fR [ \fP\fIexpression \fP\fR]\fP #\fR exit immediately; status is \fP\fIexpression\fP
|
||||
.fi
|
||||
.RE
|
||||
.EE
|
||||
.DT
|
||||
.PP
|
||||
Statements are terminated by
|
||||
semicolons, newlines or right braces.
|
||||
An empty
|
||||
.I expression-list
|
||||
stands for
|
||||
.BR $0 .
|
||||
String constants are quoted \&\f(CW"\ "\fR,
|
||||
with the usual C escapes recognized within.
|
||||
Expressions take on string or numeric values as appropriate,
|
||||
and are built using the operators
|
||||
.B + \- * / % ^
|
||||
(exponentiation), and concatenation (indicated by white space).
|
||||
The operators
|
||||
.B
|
||||
! ++ \-\- += \-= *= /= %= ^= > >= < <= == != ?:
|
||||
are also available in expressions.
|
||||
Variables may be scalars, array elements
|
||||
(denoted
|
||||
.IB x [ i ] )
|
||||
or fields.
|
||||
Variables are initialized to the null string.
|
||||
Array subscripts may be any string,
|
||||
not necessarily numeric;
|
||||
this allows for a form of associative memory.
|
||||
Multiple subscripts such as
|
||||
.B [i,j,k]
|
||||
are permitted; the constituents are concatenated,
|
||||
separated by the value of
|
||||
.BR SUBSEP .
|
||||
.PP
|
||||
The
|
||||
.B print
|
||||
statement prints its arguments on the standard output
|
||||
(or on a file if
|
||||
.BI > file
|
||||
or
|
||||
.BI >> file
|
||||
is present or on a pipe if
|
||||
.BI | cmd
|
||||
is present), separated by the current output field separator,
|
||||
and terminated by the output record separator.
|
||||
.I file
|
||||
and
|
||||
.I cmd
|
||||
may be literal names or parenthesized expressions;
|
||||
identical string values in different statements denote
|
||||
the same open file.
|
||||
The
|
||||
.B printf
|
||||
statement formats its expression list according to the format
|
||||
(see
|
||||
.IR printf (3)) .
|
||||
The built-in function
|
||||
.BI close( expr )
|
||||
closes the file or pipe
|
||||
.IR expr .
|
||||
The built-in function
|
||||
.BI fflush( expr )
|
||||
flushes any buffered output for the file or pipe
|
||||
.IR expr .
|
||||
.PP
|
||||
The mathematical functions
|
||||
.BR exp ,
|
||||
.BR log ,
|
||||
.BR sqrt ,
|
||||
.BR sin ,
|
||||
.BR cos ,
|
||||
and
|
||||
.BR atan2
|
||||
are built in.
|
||||
Other built-in functions:
|
||||
.TF length
|
||||
.TP
|
||||
.B length
|
||||
the length of its argument
|
||||
taken as a string,
|
||||
or of
|
||||
.B $0
|
||||
if no argument.
|
||||
.TP
|
||||
.B rand
|
||||
random number on (0,1)
|
||||
.TP
|
||||
.B srand
|
||||
sets seed for
|
||||
.B rand
|
||||
and returns the previous seed.
|
||||
.TP
|
||||
.B int
|
||||
truncates to an integer value
|
||||
.TP
|
||||
.BI substr( s , " m" , " n\fB)
|
||||
the
|
||||
.IR n -character
|
||||
substring of
|
||||
.I s
|
||||
that begins at position
|
||||
.IR m
|
||||
counted from 1.
|
||||
.TP
|
||||
.BI index( s , " t" )
|
||||
the position in
|
||||
.I s
|
||||
where the string
|
||||
.I t
|
||||
occurs, or 0 if it does not.
|
||||
.TP
|
||||
.BI match( s , " r" )
|
||||
the position in
|
||||
.I s
|
||||
where the regular expression
|
||||
.I r
|
||||
occurs, or 0 if it does not.
|
||||
The variables
|
||||
.B RSTART
|
||||
and
|
||||
.B RLENGTH
|
||||
are set to the position and length of the matched string.
|
||||
.TP
|
||||
.BI split( s , " a" , " fs\fB)
|
||||
splits the string
|
||||
.I s
|
||||
into array elements
|
||||
.IB a [1] ,
|
||||
.IB a [2] ,
|
||||
\&...,
|
||||
.IB a [ n ] ,
|
||||
and returns
|
||||
.IR n .
|
||||
The separation is done with the regular expression
|
||||
.I fs
|
||||
or with the field separator
|
||||
.B FS
|
||||
if
|
||||
.I fs
|
||||
is not given.
|
||||
An empty string as field separator splits the string
|
||||
into one array element per character.
|
||||
.TP
|
||||
.BI sub( r , " t" , " s\fB)
|
||||
substitutes
|
||||
.I t
|
||||
for the first occurrence of the regular expression
|
||||
.I r
|
||||
in the string
|
||||
.IR s .
|
||||
If
|
||||
.I s
|
||||
is not given,
|
||||
.B $0
|
||||
is used.
|
||||
.TP
|
||||
.B gsub
|
||||
same as
|
||||
.B sub
|
||||
except that all occurrences of the regular expression
|
||||
are replaced;
|
||||
.B sub
|
||||
and
|
||||
.B gsub
|
||||
return the number of replacements.
|
||||
.TP
|
||||
.BI sprintf( fmt , " expr" , " ...\fB )
|
||||
the string resulting from formatting
|
||||
.I expr ...
|
||||
according to the
|
||||
.IR printf (3)
|
||||
format
|
||||
.I fmt
|
||||
.TP
|
||||
.BI system( cmd )
|
||||
executes
|
||||
.I cmd
|
||||
and returns its exit status
|
||||
.TP
|
||||
.BI tolower( str )
|
||||
returns a copy of
|
||||
.I str
|
||||
with all upper-case characters translated to their
|
||||
corresponding lower-case equivalents.
|
||||
.TP
|
||||
.BI toupper( str )
|
||||
returns a copy of
|
||||
.I str
|
||||
with all lower-case characters translated to their
|
||||
corresponding upper-case equivalents.
|
||||
.PD
|
||||
.PP
|
||||
The ``function''
|
||||
.B getline
|
||||
sets
|
||||
.B $0
|
||||
to the next input record from the current input file;
|
||||
.B getline
|
||||
.BI < file
|
||||
sets
|
||||
.B $0
|
||||
to the next record from
|
||||
.IR file .
|
||||
.B getline
|
||||
.I x
|
||||
sets variable
|
||||
.I x
|
||||
instead.
|
||||
Finally,
|
||||
.IB cmd " | getline
|
||||
pipes the output of
|
||||
.I cmd
|
||||
into
|
||||
.BR getline ;
|
||||
each call of
|
||||
.B getline
|
||||
returns the next line of output from
|
||||
.IR cmd .
|
||||
In all cases,
|
||||
.B getline
|
||||
returns 1 for a successful input,
|
||||
0 for end of file, and \-1 for an error.
|
||||
.PP
|
||||
Patterns are arbitrary Boolean combinations
|
||||
(with
|
||||
.BR "! || &&" )
|
||||
of regular expressions and
|
||||
relational expressions.
|
||||
Regular expressions are as in
|
||||
.IR egrep ;
|
||||
see
|
||||
.IR grep (1).
|
||||
Isolated regular expressions
|
||||
in a pattern apply to the entire line.
|
||||
Regular expressions may also occur in
|
||||
relational expressions, using the operators
|
||||
.BR ~
|
||||
and
|
||||
.BR !~ .
|
||||
.BI / re /
|
||||
is a constant regular expression;
|
||||
any string (constant or variable) may be used
|
||||
as a regular expression, except in the position of an isolated regular expression
|
||||
in a pattern.
|
||||
.PP
|
||||
A pattern may consist of two patterns separated by a comma;
|
||||
in this case, the action is performed for all lines
|
||||
from an occurrence of the first pattern
|
||||
though an occurrence of the second.
|
||||
.PP
|
||||
A relational expression is one of the following:
|
||||
.IP
|
||||
.I expression matchop regular-expression
|
||||
.br
|
||||
.I expression relop expression
|
||||
.br
|
||||
.IB expression " in " array-name
|
||||
.br
|
||||
.BI ( expr , expr,... ") in " array-name
|
||||
.PP
|
||||
where a relop is any of the six relational operators in C,
|
||||
and a matchop is either
|
||||
.B ~
|
||||
(matches)
|
||||
or
|
||||
.B !~
|
||||
(does not match).
|
||||
A conditional is an arithmetic expression,
|
||||
a relational expression,
|
||||
or a Boolean combination
|
||||
of these.
|
||||
.PP
|
||||
The special patterns
|
||||
.B BEGIN
|
||||
and
|
||||
.B END
|
||||
may be used to capture control before the first input line is read
|
||||
and after the last.
|
||||
.B BEGIN
|
||||
and
|
||||
.B END
|
||||
do not combine with other patterns.
|
||||
.PP
|
||||
Variable names with special meanings:
|
||||
.TF FILENAME
|
||||
.TP
|
||||
.B CONVFMT
|
||||
conversion format used when converting numbers
|
||||
(default
|
||||
.BR "%.6g" )
|
||||
.TP
|
||||
.B FS
|
||||
regular expression used to separate fields; also settable
|
||||
by option
|
||||
.BI \-F fs.
|
||||
.TP
|
||||
.BR NF
|
||||
number of fields in the current record
|
||||
.TP
|
||||
.B NR
|
||||
ordinal number of the current record
|
||||
.TP
|
||||
.B FNR
|
||||
ordinal number of the current record in the current file
|
||||
.TP
|
||||
.B FILENAME
|
||||
the name of the current input file
|
||||
.TP
|
||||
.B RS
|
||||
input record separator (default newline)
|
||||
.TP
|
||||
.B OFS
|
||||
output field separator (default blank)
|
||||
.TP
|
||||
.B ORS
|
||||
output record separator (default newline)
|
||||
.TP
|
||||
.B OFMT
|
||||
output format for numbers (default
|
||||
.BR "%.6g" )
|
||||
.TP
|
||||
.B SUBSEP
|
||||
separates multiple subscripts (default 034)
|
||||
.TP
|
||||
.B ARGC
|
||||
argument count, assignable
|
||||
.TP
|
||||
.B ARGV
|
||||
argument array, assignable;
|
||||
non-null members are taken as filenames
|
||||
.TP
|
||||
.B ENVIRON
|
||||
array of environment variables; subscripts are names.
|
||||
.PD
|
||||
.PP
|
||||
Functions may be defined (at the position of a pattern-action statement) thus:
|
||||
.IP
|
||||
.B
|
||||
function foo(a, b, c) { ...; return x }
|
||||
.PP
|
||||
Parameters are passed by value if scalar and by reference if array name;
|
||||
functions may be called recursively.
|
||||
Parameters are local to the function; all other variables are global.
|
||||
Thus local variables may be created by providing excess parameters in
|
||||
the function definition.
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
.EX
|
||||
length($0) > 72
|
||||
.EE
|
||||
Print lines longer than 72 characters.
|
||||
.TP
|
||||
.EX
|
||||
{ print $2, $1 }
|
||||
.EE
|
||||
Print first two fields in opposite order.
|
||||
.PP
|
||||
.EX
|
||||
BEGIN { FS = ",[ \et]*|[ \et]+" }
|
||||
{ print $2, $1 }
|
||||
.EE
|
||||
.ns
|
||||
.IP
|
||||
Same, with input fields separated by comma and/or blanks and tabs.
|
||||
.PP
|
||||
.EX
|
||||
.nf
|
||||
{ s += $1 }
|
||||
END { print "sum is", s, " average is", s/NR }
|
||||
.fi
|
||||
.EE
|
||||
.ns
|
||||
.IP
|
||||
Add up first column, print sum and average.
|
||||
.TP
|
||||
.EX
|
||||
/start/, /stop/
|
||||
.EE
|
||||
Print all lines between start/stop pairs.
|
||||
.PP
|
||||
.EX
|
||||
.nf
|
||||
BEGIN { # Simulate echo(1)
|
||||
for (i = 1; i < ARGC; i++) printf "%s ", ARGV[i]
|
||||
printf "\en"
|
||||
exit }
|
||||
.fi
|
||||
.EE
|
||||
.SH SEE ALSO
|
||||
.IR lex (1),
|
||||
.IR sed (1)
|
||||
.br
|
||||
A. V. Aho, B. W. Kernighan, P. J. Weinberger,
|
||||
.I
|
||||
The AWK Programming Language,
|
||||
Addison-Wesley, 1988. ISBN 0-201-07981-X
|
||||
.SH BUGS
|
||||
There are no explicit conversions between numbers and strings.
|
||||
To force an expression to be treated as a number add 0 to it;
|
||||
to force it to be treated as a string concatenate
|
||||
\&\f(CW""\fP to it.
|
||||
.br
|
||||
The scope rules for variables in functions are a botch;
|
||||
the syntax is worse.
|
|
@ -1,232 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
typedef double Awkfloat;
|
||||
|
||||
/* unsigned char is more trouble than it's worth */
|
||||
|
||||
typedef unsigned char uschar;
|
||||
|
||||
#define xfree(a) { if ((a) != NULL) { free((void *) (a)); (a) = NULL; } }
|
||||
|
||||
#define NN(p) ((p) ? (p) : "(null)") /* guaranteed non-null for dprintf
|
||||
*/
|
||||
#define DEBUG
|
||||
#ifdef DEBUG
|
||||
/* uses have to be doubly parenthesized */
|
||||
# define dprintf(x) if (dbg) printf x
|
||||
#else
|
||||
# define dprintf(x)
|
||||
#endif
|
||||
|
||||
extern int compile_time; /* 1 if compiling, 0 if running */
|
||||
extern int safe; /* 0 => unsafe, 1 => safe */
|
||||
|
||||
#define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
|
||||
extern int recsize; /* size of current record, orig RECSIZE */
|
||||
|
||||
extern char **FS;
|
||||
extern char **RS;
|
||||
extern char **ORS;
|
||||
extern char **OFS;
|
||||
extern char **OFMT;
|
||||
extern Awkfloat *NR;
|
||||
extern Awkfloat *FNR;
|
||||
extern Awkfloat *NF;
|
||||
extern char **FILENAME;
|
||||
extern char **SUBSEP;
|
||||
extern Awkfloat *RSTART;
|
||||
extern Awkfloat *RLENGTH;
|
||||
|
||||
extern uschar *record; /* points to $0 */
|
||||
extern int lineno; /* line number in awk program */
|
||||
extern int errorflag; /* 1 if error has occurred */
|
||||
extern int donefld; /* 1 if record broken into fields */
|
||||
extern int donerec; /* 1 if record is valid (no fld has changed */
|
||||
|
||||
extern int dbg;
|
||||
|
||||
extern uschar *patbeg; /* beginning of pattern matched */
|
||||
extern int patlen; /* length of pattern matched. set in b.c */
|
||||
|
||||
/* Cell: all information about a variable or constant */
|
||||
|
||||
typedef struct Cell {
|
||||
uschar ctype; /* OCELL, OBOOL, OJUMP, etc. */
|
||||
uschar csub; /* CCON, CTEMP, CFLD, etc. */
|
||||
char *nval; /* name, for variables only */
|
||||
char *sval; /* string value */
|
||||
Awkfloat fval; /* value as number */
|
||||
int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
|
||||
struct Cell *cnext; /* ptr to next if chained */
|
||||
} Cell;
|
||||
|
||||
typedef struct Array { /* symbol table array */
|
||||
int nelem; /* elements in table right now */
|
||||
int size; /* size of tab */
|
||||
Cell **tab; /* hash table pointers */
|
||||
} Array;
|
||||
|
||||
#define NSYMTAB 50 /* initial size of a symbol table */
|
||||
extern Array *symtab;
|
||||
|
||||
extern Cell *nrloc; /* NR */
|
||||
extern Cell *fnrloc; /* FNR */
|
||||
extern Cell *nfloc; /* NF */
|
||||
extern Cell *rstartloc; /* RSTART */
|
||||
extern Cell *rlengthloc; /* RLENGTH */
|
||||
|
||||
/* Cell.tval values: */
|
||||
#define NUM 01 /* number value is valid */
|
||||
#define STR 02 /* string value is valid */
|
||||
#define DONTFREE 04 /* string space is not freeable */
|
||||
#define CON 010 /* this is a constant */
|
||||
#define ARR 020 /* this is an array */
|
||||
#define FCN 040 /* this is a function name */
|
||||
#define FLD 0100 /* this is a field $1, $2, ... */
|
||||
#define REC 0200 /* this is $0 */
|
||||
|
||||
|
||||
/* function types */
|
||||
#define FLENGTH 1
|
||||
#define FSQRT 2
|
||||
#define FEXP 3
|
||||
#define FLOG 4
|
||||
#define FINT 5
|
||||
#define FSYSTEM 6
|
||||
#define FRAND 7
|
||||
#define FSRAND 8
|
||||
#define FSIN 9
|
||||
#define FCOS 10
|
||||
#define FATAN 11
|
||||
#define FTOUPPER 12
|
||||
#define FTOLOWER 13
|
||||
#define FFLUSH 14
|
||||
#define FSYSTIME 15
|
||||
#define FSTRFTIME 16
|
||||
|
||||
/* Node: parse tree is made of nodes, with Cell's at bottom */
|
||||
|
||||
typedef struct Node {
|
||||
int ntype;
|
||||
struct Node *nnext;
|
||||
int lineno;
|
||||
int nobj;
|
||||
struct Node *narg[1]; /* variable: actual size set by calling malloc */
|
||||
} Node;
|
||||
|
||||
#define NIL ((Node *) 0)
|
||||
|
||||
extern Node *winner;
|
||||
extern Node *nullstat;
|
||||
extern Node *nullnode;
|
||||
|
||||
/* ctypes */
|
||||
#define OCELL 1
|
||||
#define OBOOL 2
|
||||
#define OJUMP 3
|
||||
|
||||
/* Cell subtypes: csub */
|
||||
#define CFREE 7
|
||||
#define CCOPY 6
|
||||
#define CCON 5
|
||||
#define CTEMP 4
|
||||
#define CNAME 3
|
||||
#define CVAR 2
|
||||
#define CFLD 1
|
||||
#define CUNK 0
|
||||
|
||||
/* bool subtypes */
|
||||
#define BTRUE 11
|
||||
#define BFALSE 12
|
||||
|
||||
/* jump subtypes */
|
||||
#define JEXIT 21
|
||||
#define JNEXT 22
|
||||
#define JBREAK 23
|
||||
#define JCONT 24
|
||||
#define JRET 25
|
||||
#define JNEXTFILE 26
|
||||
|
||||
/* node types */
|
||||
#define NVALUE 1
|
||||
#define NSTAT 2
|
||||
#define NEXPR 3
|
||||
|
||||
|
||||
extern int pairstack[], paircnt;
|
||||
|
||||
#define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
|
||||
#define isvalue(n) ((n)->ntype == NVALUE)
|
||||
#define isexpr(n) ((n)->ntype == NEXPR)
|
||||
#define isjump(n) ((n)->ctype == OJUMP)
|
||||
#define isexit(n) ((n)->csub == JEXIT)
|
||||
#define isbreak(n) ((n)->csub == JBREAK)
|
||||
#define iscont(n) ((n)->csub == JCONT)
|
||||
#define isnext(n) ((n)->csub == JNEXT || (n)->csub == JNEXTFILE)
|
||||
#define isret(n) ((n)->csub == JRET)
|
||||
#define isrec(n) ((n)->tval & REC)
|
||||
#define isfld(n) ((n)->tval & FLD)
|
||||
#define isstr(n) ((n)->tval & STR)
|
||||
#define isnum(n) ((n)->tval & NUM)
|
||||
#define isarr(n) ((n)->tval & ARR)
|
||||
#define isfcn(n) ((n)->tval & FCN)
|
||||
#define istrue(n) ((n)->csub == BTRUE)
|
||||
#define istemp(n) ((n)->csub == CTEMP)
|
||||
#define isargument(n) ((n)->nobj == ARG)
|
||||
/* #define freeable(p) (!((p)->tval & DONTFREE)) */
|
||||
#define freeable(p) ( ((p)->tval & (STR|DONTFREE)) == STR )
|
||||
|
||||
/* structures used by regular expression matching machinery, mostly b.c: */
|
||||
|
||||
#define NCHARS (256+3) /* 256 handles 8-bit chars; 128 does 7-bit */
|
||||
/* watch out in match(), etc. */
|
||||
typedef struct rrow {
|
||||
long ltype; /* long avoids pointer warnings on 64-bit */
|
||||
union {
|
||||
int i;
|
||||
Node *np;
|
||||
uschar *up;
|
||||
} lval; /* because Al stores a pointer in it! */
|
||||
int *lfollow;
|
||||
} rrow;
|
||||
|
||||
typedef struct fa {
|
||||
unsigned int **gototab;
|
||||
uschar *out;
|
||||
uschar *restr;
|
||||
int **posns;
|
||||
int state_count;
|
||||
int anchor;
|
||||
int use;
|
||||
int initstat;
|
||||
int curstat;
|
||||
int accept;
|
||||
struct rrow re[1]; /* variable: actual size set by calling malloc */
|
||||
} fa;
|
||||
|
||||
|
||||
#include "proto.h"
|
|
@ -1,506 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
%{
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "awk.h"
|
||||
|
||||
void checkdup(Node *list, Cell *item);
|
||||
int yywrap(void) { return(1); }
|
||||
|
||||
Node *beginloc = 0;
|
||||
Node *endloc = 0;
|
||||
int infunc = 0; /* = 1 if in arglist or body of func */
|
||||
int inloop = 0; /* = 1 if in while, for, do */
|
||||
char *curfname = 0; /* current function name */
|
||||
Node *arglist = 0; /* list of args for current function */
|
||||
%}
|
||||
|
||||
%union {
|
||||
Node *p;
|
||||
Cell *cp;
|
||||
int i;
|
||||
char *s;
|
||||
}
|
||||
|
||||
%token <i> FIRSTTOKEN /* must be first */
|
||||
%token <p> PROGRAM PASTAT PASTAT2 XBEGIN XEND
|
||||
%token <i> NL ',' '{' '(' '|' ';' '/' ')' '}' '[' ']'
|
||||
%token <i> ARRAY
|
||||
%token <i> MATCH NOTMATCH MATCHOP
|
||||
%token <i> FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS EMPTYRE
|
||||
%token <i> AND BOR APPEND EQ GE GT LE LT NE IN
|
||||
%token <i> ARG BLTIN BREAK CLOSE CONTINUE DELETE DO EXIT FOR FUNC
|
||||
%token <i> SUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NEXTFILE
|
||||
%token <i> ADD MINUS MULT DIVIDE MOD
|
||||
%token <i> ASSIGN ASGNOP ADDEQ SUBEQ MULTEQ DIVEQ MODEQ POWEQ
|
||||
%token <i> PRINT PRINTF SPRINTF
|
||||
%token <p> ELSE INTEST CONDEXPR
|
||||
%token <i> POSTINCR PREINCR POSTDECR PREDECR
|
||||
%token <cp> VAR IVAR VARNF CALL NUMBER STRING
|
||||
%token <s> REGEXPR
|
||||
|
||||
%type <p> pas pattern ppattern plist pplist patlist prarg term re
|
||||
%type <p> pa_pat pa_stat pa_stats
|
||||
%type <s> reg_expr
|
||||
%type <p> simple_stmt opt_simple_stmt stmt stmtlist
|
||||
%type <p> var varname funcname varlist
|
||||
%type <p> for if else while
|
||||
%type <i> do st
|
||||
%type <i> pst opt_pst lbrace rbrace rparen comma nl opt_nl and bor
|
||||
%type <i> subop print
|
||||
|
||||
%right ASGNOP
|
||||
%right '?'
|
||||
%right ':'
|
||||
%left BOR
|
||||
%left AND
|
||||
%left GETLINE
|
||||
%nonassoc APPEND EQ GE GT LE LT NE MATCHOP IN '|'
|
||||
%left ARG BLTIN BREAK CALL CLOSE CONTINUE DELETE DO EXIT FOR FUNC
|
||||
%left GENSUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NUMBER
|
||||
%left PRINT PRINTF RETURN SPLIT SPRINTF STRING SUB SUBSTR
|
||||
%left REGEXPR VAR VARNF IVAR WHILE '('
|
||||
%left CAT
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left NOT UMINUS
|
||||
%right POWER
|
||||
%right DECR INCR
|
||||
%left INDIRECT
|
||||
%token LASTTOKEN /* must be last */
|
||||
|
||||
%%
|
||||
|
||||
program:
|
||||
pas { if (errorflag==0)
|
||||
winner = (Node *)stat3(PROGRAM, beginloc, $1, endloc); }
|
||||
| error { yyclearin; bracecheck(); SYNTAX("bailing out"); }
|
||||
;
|
||||
|
||||
and:
|
||||
AND | and NL
|
||||
;
|
||||
|
||||
bor:
|
||||
BOR | bor NL
|
||||
;
|
||||
|
||||
comma:
|
||||
',' | comma NL
|
||||
;
|
||||
|
||||
do:
|
||||
DO | do NL
|
||||
;
|
||||
|
||||
else:
|
||||
ELSE | else NL
|
||||
;
|
||||
|
||||
for:
|
||||
FOR '(' opt_simple_stmt ';' opt_nl pattern ';' opt_nl opt_simple_stmt rparen {inloop++;} stmt
|
||||
{ --inloop; $$ = stat4(FOR, $3, notnull($6), $9, $12); }
|
||||
| FOR '(' opt_simple_stmt ';' ';' opt_nl opt_simple_stmt rparen {inloop++;} stmt
|
||||
{ --inloop; $$ = stat4(FOR, $3, NIL, $7, $10); }
|
||||
| FOR '(' varname IN varname rparen {inloop++;} stmt
|
||||
{ --inloop; $$ = stat3(IN, $3, makearr($5), $8); }
|
||||
;
|
||||
|
||||
funcname:
|
||||
VAR { setfname($1); }
|
||||
| CALL { setfname($1); }
|
||||
;
|
||||
|
||||
if:
|
||||
IF '(' pattern rparen { $$ = notnull($3); }
|
||||
;
|
||||
|
||||
lbrace:
|
||||
'{' | lbrace NL
|
||||
;
|
||||
|
||||
nl:
|
||||
NL | nl NL
|
||||
;
|
||||
|
||||
opt_nl:
|
||||
/* empty */ { $$ = 0; }
|
||||
| nl
|
||||
;
|
||||
|
||||
opt_pst:
|
||||
/* empty */ { $$ = 0; }
|
||||
| pst
|
||||
;
|
||||
|
||||
|
||||
opt_simple_stmt:
|
||||
/* empty */ { $$ = 0; }
|
||||
| simple_stmt
|
||||
;
|
||||
|
||||
pas:
|
||||
opt_pst { $$ = 0; }
|
||||
| opt_pst pa_stats opt_pst { $$ = $2; }
|
||||
;
|
||||
|
||||
pa_pat:
|
||||
pattern { $$ = notnull($1); }
|
||||
;
|
||||
|
||||
pa_stat:
|
||||
pa_pat { $$ = stat2(PASTAT, $1, stat2(PRINT, rectonode(), NIL)); }
|
||||
| pa_pat lbrace stmtlist '}' { $$ = stat2(PASTAT, $1, $3); }
|
||||
| pa_pat ',' pa_pat { $$ = pa2stat($1, $3, stat2(PRINT, rectonode(), NIL)); }
|
||||
| pa_pat ',' pa_pat lbrace stmtlist '}' { $$ = pa2stat($1, $3, $5); }
|
||||
| lbrace stmtlist '}' { $$ = stat2(PASTAT, NIL, $2); }
|
||||
| XBEGIN lbrace stmtlist '}'
|
||||
{ beginloc = linkum(beginloc, $3); $$ = 0; }
|
||||
| XEND lbrace stmtlist '}'
|
||||
{ endloc = linkum(endloc, $3); $$ = 0; }
|
||||
| FUNC funcname '(' varlist rparen {infunc++;} lbrace stmtlist '}'
|
||||
{ infunc--; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; }
|
||||
;
|
||||
|
||||
pa_stats:
|
||||
pa_stat
|
||||
| pa_stats opt_pst pa_stat { $$ = linkum($1, $3); }
|
||||
;
|
||||
|
||||
patlist:
|
||||
pattern
|
||||
| patlist comma pattern { $$ = linkum($1, $3); }
|
||||
;
|
||||
|
||||
ppattern:
|
||||
var ASGNOP ppattern { $$ = op2($2, $1, $3); }
|
||||
| ppattern '?' ppattern ':' ppattern %prec '?'
|
||||
{ $$ = op3(CONDEXPR, notnull($1), $3, $5); }
|
||||
| ppattern bor ppattern %prec BOR
|
||||
{ $$ = op2(BOR, notnull($1), notnull($3)); }
|
||||
| ppattern and ppattern %prec AND
|
||||
{ $$ = op2(AND, notnull($1), notnull($3)); }
|
||||
| ppattern MATCHOP reg_expr { $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); }
|
||||
| ppattern MATCHOP ppattern
|
||||
{ if (constnode($3))
|
||||
$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
|
||||
else
|
||||
$$ = op3($2, (Node *)1, $1, $3); }
|
||||
| ppattern IN varname { $$ = op2(INTEST, $1, makearr($3)); }
|
||||
| '(' plist ')' IN varname { $$ = op2(INTEST, $2, makearr($5)); }
|
||||
| ppattern term %prec CAT { $$ = op2(CAT, $1, $2); }
|
||||
| re
|
||||
| term
|
||||
;
|
||||
|
||||
pattern:
|
||||
var ASGNOP pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern '?' pattern ':' pattern %prec '?'
|
||||
{ $$ = op3(CONDEXPR, notnull($1), $3, $5); }
|
||||
| pattern bor pattern %prec BOR
|
||||
{ $$ = op2(BOR, notnull($1), notnull($3)); }
|
||||
| pattern and pattern %prec AND
|
||||
{ $$ = op2(AND, notnull($1), notnull($3)); }
|
||||
| pattern EQ pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern GE pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern GT pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern LE pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern LT pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern NE pattern { $$ = op2($2, $1, $3); }
|
||||
| pattern MATCHOP reg_expr { $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); }
|
||||
| pattern MATCHOP pattern
|
||||
{ if (constnode($3))
|
||||
$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
|
||||
else
|
||||
$$ = op3($2, (Node *)1, $1, $3); }
|
||||
| pattern IN varname { $$ = op2(INTEST, $1, makearr($3)); }
|
||||
| '(' plist ')' IN varname { $$ = op2(INTEST, $2, makearr($5)); }
|
||||
| pattern '|' GETLINE var {
|
||||
if (safe) SYNTAX("cmd | getline is unsafe");
|
||||
else $$ = op3(GETLINE, $4, itonp($2), $1); }
|
||||
| pattern '|' GETLINE {
|
||||
if (safe) SYNTAX("cmd | getline is unsafe");
|
||||
else $$ = op3(GETLINE, (Node*)0, itonp($2), $1); }
|
||||
| pattern term %prec CAT { $$ = op2(CAT, $1, $2); }
|
||||
| re
|
||||
| term
|
||||
;
|
||||
|
||||
plist:
|
||||
pattern comma pattern { $$ = linkum($1, $3); }
|
||||
| plist comma pattern { $$ = linkum($1, $3); }
|
||||
;
|
||||
|
||||
pplist:
|
||||
ppattern
|
||||
| pplist comma ppattern { $$ = linkum($1, $3); }
|
||||
;
|
||||
|
||||
prarg:
|
||||
/* empty */ { $$ = rectonode(); }
|
||||
| pplist
|
||||
| '(' plist ')' { $$ = $2; }
|
||||
;
|
||||
|
||||
print:
|
||||
PRINT | PRINTF
|
||||
;
|
||||
|
||||
pst:
|
||||
NL | ';' | pst NL | pst ';'
|
||||
;
|
||||
|
||||
rbrace:
|
||||
'}' | rbrace NL
|
||||
;
|
||||
|
||||
re:
|
||||
reg_expr
|
||||
{ $$ = op3(MATCH, NIL, rectonode(), (Node*)makedfa($1, 0)); }
|
||||
| NOT re { $$ = op1(NOT, notnull($2)); }
|
||||
;
|
||||
|
||||
reg_expr:
|
||||
'/' {startreg();} REGEXPR '/' { $$ = $3; }
|
||||
;
|
||||
|
||||
rparen:
|
||||
')' | rparen NL
|
||||
;
|
||||
|
||||
simple_stmt:
|
||||
print prarg '|' term {
|
||||
if (safe) SYNTAX("print | is unsafe");
|
||||
else $$ = stat3($1, $2, itonp($3), $4); }
|
||||
| print prarg APPEND term {
|
||||
if (safe) SYNTAX("print >> is unsafe");
|
||||
else $$ = stat3($1, $2, itonp($3), $4); }
|
||||
| print prarg GT term {
|
||||
if (safe) SYNTAX("print > is unsafe");
|
||||
else $$ = stat3($1, $2, itonp($3), $4); }
|
||||
| print prarg { $$ = stat3($1, $2, NIL, NIL); }
|
||||
| DELETE varname '[' patlist ']' { $$ = stat2(DELETE, makearr($2), $4); }
|
||||
| DELETE varname { $$ = stat2(DELETE, makearr($2), 0); }
|
||||
| pattern { $$ = exptostat($1); }
|
||||
| error { yyclearin; SYNTAX("illegal statement"); }
|
||||
;
|
||||
|
||||
st:
|
||||
nl
|
||||
| ';' opt_nl
|
||||
;
|
||||
|
||||
stmt:
|
||||
BREAK st { if (!inloop) SYNTAX("break illegal outside of loops");
|
||||
$$ = stat1(BREAK, NIL); }
|
||||
| CONTINUE st { if (!inloop) SYNTAX("continue illegal outside of loops");
|
||||
$$ = stat1(CONTINUE, NIL); }
|
||||
| do {inloop++;} stmt {--inloop;} WHILE '(' pattern ')' st
|
||||
{ $$ = stat2(DO, $3, notnull($7)); }
|
||||
| EXIT pattern st { $$ = stat1(EXIT, $2); }
|
||||
| EXIT st { $$ = stat1(EXIT, NIL); }
|
||||
| for
|
||||
| if stmt else stmt { $$ = stat3(IF, $1, $2, $4); }
|
||||
| if stmt { $$ = stat3(IF, $1, $2, NIL); }
|
||||
| lbrace stmtlist rbrace { $$ = $2; }
|
||||
| NEXT st { if (infunc)
|
||||
SYNTAX("next is illegal inside a function");
|
||||
$$ = stat1(NEXT, NIL); }
|
||||
| NEXTFILE st { if (infunc)
|
||||
SYNTAX("nextfile is illegal inside a function");
|
||||
$$ = stat1(NEXTFILE, NIL); }
|
||||
| RETURN pattern st { $$ = stat1(RETURN, $2); }
|
||||
| RETURN st { $$ = stat1(RETURN, NIL); }
|
||||
| simple_stmt st
|
||||
| while {inloop++;} stmt { --inloop; $$ = stat2(WHILE, $1, $3); }
|
||||
| ';' opt_nl { $$ = 0; }
|
||||
;
|
||||
|
||||
stmtlist:
|
||||
stmt
|
||||
| stmtlist stmt { $$ = linkum($1, $2); }
|
||||
;
|
||||
|
||||
subop:
|
||||
SUB | GSUB
|
||||
;
|
||||
|
||||
term:
|
||||
term '/' ASGNOP term { $$ = op2(DIVEQ, $1, $4); }
|
||||
| term '+' term { $$ = op2(ADD, $1, $3); }
|
||||
| term '-' term { $$ = op2(MINUS, $1, $3); }
|
||||
| term '*' term { $$ = op2(MULT, $1, $3); }
|
||||
| term '/' term { $$ = op2(DIVIDE, $1, $3); }
|
||||
| term '%' term { $$ = op2(MOD, $1, $3); }
|
||||
| term POWER term { $$ = op2(POWER, $1, $3); }
|
||||
| '-' term %prec UMINUS { $$ = op1(UMINUS, $2); }
|
||||
| '+' term %prec UMINUS { $$ = $2; }
|
||||
| NOT term %prec UMINUS { $$ = op1(NOT, notnull($2)); }
|
||||
| BLTIN '(' ')' { $$ = op2(BLTIN, itonp($1), rectonode()); }
|
||||
| BLTIN '(' patlist ')' { $$ = op2(BLTIN, itonp($1), $3); }
|
||||
| BLTIN { $$ = op2(BLTIN, itonp($1), rectonode()); }
|
||||
| CALL '(' ')' { $$ = op2(CALL, celltonode($1,CVAR), NIL); }
|
||||
| CALL '(' patlist ')' { $$ = op2(CALL, celltonode($1,CVAR), $3); }
|
||||
| CLOSE term { $$ = op1(CLOSE, $2); }
|
||||
| DECR var { $$ = op1(PREDECR, $2); }
|
||||
| INCR var { $$ = op1(PREINCR, $2); }
|
||||
| var DECR { $$ = op1(POSTDECR, $1); }
|
||||
| var INCR { $$ = op1(POSTINCR, $1); }
|
||||
| GENSUB '(' reg_expr comma pattern comma pattern ')'
|
||||
{ $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, rectonode()); }
|
||||
| GENSUB '(' pattern comma pattern comma pattern ')'
|
||||
{ if (constnode($3))
|
||||
$$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3), 1), $5, $7, rectonode());
|
||||
else
|
||||
$$ = op5(GENSUB, (Node *)1, $3, $5, $7, rectonode());
|
||||
}
|
||||
| GENSUB '(' reg_expr comma pattern comma pattern comma pattern ')'
|
||||
{ $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, $9); }
|
||||
| GENSUB '(' pattern comma pattern comma pattern comma pattern ')'
|
||||
{ if (constnode($3))
|
||||
$$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3),1), $5,$7,$9);
|
||||
else
|
||||
$$ = op5(GENSUB, (Node *)1, $3, $5, $7, $9);
|
||||
}
|
||||
| GETLINE var LT term { $$ = op3(GETLINE, $2, itonp($3), $4); }
|
||||
| GETLINE LT term { $$ = op3(GETLINE, NIL, itonp($2), $3); }
|
||||
| GETLINE var { $$ = op3(GETLINE, $2, NIL, NIL); }
|
||||
| GETLINE { $$ = op3(GETLINE, NIL, NIL, NIL); }
|
||||
| INDEX '(' pattern comma pattern ')'
|
||||
{ $$ = op2(INDEX, $3, $5); }
|
||||
| INDEX '(' pattern comma reg_expr ')'
|
||||
{ SYNTAX("index() doesn't permit regular expressions");
|
||||
$$ = op2(INDEX, $3, (Node*)$5); }
|
||||
| '(' pattern ')' { $$ = $2; }
|
||||
| MATCHFCN '(' pattern comma reg_expr ')'
|
||||
{ $$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa($5, 1)); }
|
||||
| MATCHFCN '(' pattern comma pattern ')'
|
||||
{ if (constnode($5))
|
||||
$$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa(strnode($5), 1));
|
||||
else
|
||||
$$ = op3(MATCHFCN, (Node *)1, $3, $5); }
|
||||
| NUMBER { $$ = celltonode($1, CCON); }
|
||||
| SPLIT '(' pattern comma varname comma pattern ')' /* string */
|
||||
{ $$ = op4(SPLIT, $3, makearr($5), $7, (Node*)STRING); }
|
||||
| SPLIT '(' pattern comma varname comma reg_expr ')' /* const /regexp/ */
|
||||
{ $$ = op4(SPLIT, $3, makearr($5), (Node*)makedfa($7, 1), (Node *)REGEXPR); }
|
||||
| SPLIT '(' pattern comma varname ')'
|
||||
{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); } /* default */
|
||||
| SPRINTF '(' patlist ')' { $$ = op1($1, $3); }
|
||||
| STRING { $$ = celltonode($1, CCON); }
|
||||
| subop '(' reg_expr comma pattern ')'
|
||||
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); }
|
||||
| subop '(' pattern comma pattern ')'
|
||||
{ if (constnode($3))
|
||||
$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, rectonode());
|
||||
else
|
||||
$$ = op4($1, (Node *)1, $3, $5, rectonode()); }
|
||||
| subop '(' reg_expr comma pattern comma var ')'
|
||||
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, $7); }
|
||||
| subop '(' pattern comma pattern comma var ')'
|
||||
{ if (constnode($3))
|
||||
$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, $7);
|
||||
else
|
||||
$$ = op4($1, (Node *)1, $3, $5, $7); }
|
||||
| SUBSTR '(' pattern comma pattern comma pattern ')'
|
||||
{ $$ = op3(SUBSTR, $3, $5, $7); }
|
||||
| SUBSTR '(' pattern comma pattern ')'
|
||||
{ $$ = op3(SUBSTR, $3, $5, NIL); }
|
||||
| var
|
||||
;
|
||||
|
||||
var:
|
||||
varname
|
||||
| varname '[' patlist ']' { $$ = op2(ARRAY, makearr($1), $3); }
|
||||
| IVAR { $$ = op1(INDIRECT, celltonode($1, CVAR)); }
|
||||
| INDIRECT term { $$ = op1(INDIRECT, $2); }
|
||||
;
|
||||
|
||||
varlist:
|
||||
/* nothing */ { arglist = $$ = 0; }
|
||||
| VAR { arglist = $$ = celltonode($1,CVAR); }
|
||||
| varlist comma VAR {
|
||||
checkdup($1, $3);
|
||||
arglist = $$ = linkum($1,celltonode($3,CVAR)); }
|
||||
;
|
||||
|
||||
varname:
|
||||
VAR { $$ = celltonode($1, CVAR); }
|
||||
| ARG { $$ = op1(ARG, itonp($1)); }
|
||||
| VARNF { $$ = op1(VARNF, (Node *) $1); }
|
||||
;
|
||||
|
||||
|
||||
while:
|
||||
WHILE '(' pattern rparen { $$ = notnull($3); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
void setfname(Cell *p)
|
||||
{
|
||||
if (isarr(p))
|
||||
SYNTAX("%s is an array, not a function", p->nval);
|
||||
else if (isfcn(p))
|
||||
SYNTAX("you can't define function %s more than once", p->nval);
|
||||
curfname = p->nval;
|
||||
}
|
||||
|
||||
int constnode(Node *p)
|
||||
{
|
||||
return isvalue(p) && ((Cell *) (p->narg[0]))->csub == CCON;
|
||||
}
|
||||
|
||||
char *strnode(Node *p)
|
||||
{
|
||||
return ((Cell *)(p->narg[0]))->sval;
|
||||
}
|
||||
|
||||
Node *notnull(Node *n)
|
||||
{
|
||||
switch (n->nobj) {
|
||||
case LE: case LT: case EQ: case NE: case GT: case GE:
|
||||
case BOR: case AND: case NOT:
|
||||
return n;
|
||||
default:
|
||||
return op2(NE, n, nullnode);
|
||||
}
|
||||
}
|
||||
|
||||
void checkdup(Node *vl, Cell *cp) /* check if name already in list */
|
||||
{
|
||||
char *s = cp->nval;
|
||||
for ( ; vl; vl = vl->nnext) {
|
||||
if (strcmp(s, ((Cell *)(vl->narg[0]))->nval) == 0) {
|
||||
SYNTAX("duplicate argument %s", s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,981 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
/* lasciate ogne speranza, voi ch'intrate. */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
#define HAT (NCHARS+2) /* matches ^ in regular expr */
|
||||
/* NCHARS is 2**n */
|
||||
#define MAXLIN 22
|
||||
|
||||
#define type(v) (v)->nobj /* badly overloaded here */
|
||||
#define info(v) (v)->ntype /* badly overloaded here */
|
||||
#define left(v) (v)->narg[0]
|
||||
#define right(v) (v)->narg[1]
|
||||
#define parent(v) (v)->nnext
|
||||
|
||||
#define LEAF case CCL: case NCCL: case CHAR: case DOT: case FINAL: case ALL:
|
||||
#define ELEAF case EMPTYRE: /* empty string in regexp */
|
||||
#define UNARY case STAR: case PLUS: case QUEST:
|
||||
|
||||
/* encoding in tree Nodes:
|
||||
leaf (CCL, NCCL, CHAR, DOT, FINAL, ALL, EMPTYRE):
|
||||
left is index, right contains value or pointer to value
|
||||
unary (STAR, PLUS, QUEST): left is child, right is null
|
||||
binary (CAT, OR): left and right are children
|
||||
parent contains pointer to parent
|
||||
*/
|
||||
|
||||
|
||||
int *setvec;
|
||||
int *tmpset;
|
||||
int maxsetvec = 0;
|
||||
|
||||
int rtok; /* next token in current re */
|
||||
int rlxval;
|
||||
static uschar *rlxstr;
|
||||
static uschar *prestr; /* current position in current re */
|
||||
static uschar *lastre; /* origin of last re */
|
||||
|
||||
static int setcnt;
|
||||
static int poscnt;
|
||||
|
||||
uschar *patbeg;
|
||||
int patlen;
|
||||
|
||||
#define NFA 128 /* cache this many dynamic fa's */
|
||||
fa *fatab[NFA];
|
||||
int nfatab = 0; /* entries in fatab */
|
||||
|
||||
static void
|
||||
resize_state(fa *fa, int state)
|
||||
{
|
||||
void *p;
|
||||
int i, new_count;
|
||||
|
||||
if (++state < fa->state_count)
|
||||
return;
|
||||
|
||||
new_count = state + 10; /* needs to be tuned */
|
||||
|
||||
p = realloc(fa->gototab, new_count * sizeof(fa->gototab[0]));
|
||||
if (p == NULL)
|
||||
goto out;
|
||||
fa->gototab = p;
|
||||
|
||||
p = realloc(fa->out, new_count * sizeof(fa->out[0]));
|
||||
if (p == NULL)
|
||||
goto out;
|
||||
fa->out = p;
|
||||
|
||||
p = realloc(fa->posns, new_count * sizeof(fa->posns[0]));
|
||||
if (p == NULL)
|
||||
goto out;
|
||||
fa->posns = p;
|
||||
|
||||
for (i = fa->state_count; i < new_count; ++i) {
|
||||
fa->gototab[i] = calloc(1, NCHARS * sizeof (**fa->gototab));
|
||||
if (fa->gototab[i] == NULL)
|
||||
goto out;
|
||||
fa->out[i] = 0;
|
||||
fa->posns[i] = NULL;
|
||||
}
|
||||
fa->state_count = new_count;
|
||||
return;
|
||||
out:
|
||||
overflo("out of memory in resize_state");
|
||||
}
|
||||
|
||||
fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */
|
||||
{
|
||||
int i, use, nuse;
|
||||
fa *pfa;
|
||||
static int now = 1;
|
||||
|
||||
if (setvec == 0) { /* first time through any RE */
|
||||
maxsetvec = MAXLIN;
|
||||
setvec = (int *) malloc(maxsetvec * sizeof(int));
|
||||
tmpset = (int *) malloc(maxsetvec * sizeof(int));
|
||||
if (setvec == 0 || tmpset == 0)
|
||||
overflo("out of space initializing makedfa");
|
||||
}
|
||||
|
||||
if (compile_time) /* a constant for sure */
|
||||
return mkdfa(s, anchor);
|
||||
for (i = 0; i < nfatab; i++) /* is it there already? */
|
||||
if (fatab[i]->anchor == anchor
|
||||
&& strcmp((const char *) fatab[i]->restr, s) == 0) {
|
||||
fatab[i]->use = now++;
|
||||
return fatab[i];
|
||||
}
|
||||
pfa = mkdfa(s, anchor);
|
||||
if (nfatab < NFA) { /* room for another */
|
||||
fatab[nfatab] = pfa;
|
||||
fatab[nfatab]->use = now++;
|
||||
nfatab++;
|
||||
return pfa;
|
||||
}
|
||||
use = fatab[0]->use; /* replace least-recently used */
|
||||
nuse = 0;
|
||||
for (i = 1; i < nfatab; i++)
|
||||
if (fatab[i]->use < use) {
|
||||
use = fatab[i]->use;
|
||||
nuse = i;
|
||||
}
|
||||
freefa(fatab[nuse]);
|
||||
fatab[nuse] = pfa;
|
||||
pfa->use = now++;
|
||||
return pfa;
|
||||
}
|
||||
|
||||
fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */
|
||||
/* anchor = 1 for anchored matches, else 0 */
|
||||
{
|
||||
Node *p, *p1;
|
||||
fa *f;
|
||||
|
||||
p = reparse(s);
|
||||
p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p);
|
||||
/* put ALL STAR in front of reg. exp. */
|
||||
p1 = op2(CAT, p1, op2(FINAL, NIL, NIL));
|
||||
/* put FINAL after reg. exp. */
|
||||
|
||||
poscnt = 0;
|
||||
penter(p1); /* enter parent pointers and leaf indices */
|
||||
if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL)
|
||||
overflo("out of space for fa");
|
||||
f->accept = poscnt-1; /* penter has computed number of positions in re */
|
||||
cfoll(f, p1); /* set up follow sets */
|
||||
freetr(p1);
|
||||
resize_state(f, 1);
|
||||
if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
|
||||
overflo("out of space in makedfa");
|
||||
if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL)
|
||||
overflo("out of space in makedfa");
|
||||
*f->posns[1] = 0;
|
||||
f->initstat = makeinit(f, anchor);
|
||||
f->anchor = anchor;
|
||||
f->restr = (uschar *) tostring(s);
|
||||
return f;
|
||||
}
|
||||
|
||||
int makeinit(fa *f, int anchor)
|
||||
{
|
||||
int i, k;
|
||||
|
||||
resize_state(f, 2);
|
||||
f->curstat = 2;
|
||||
f->out[2] = 0;
|
||||
k = *(f->re[0].lfollow);
|
||||
xfree(f->posns[2]);
|
||||
if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL)
|
||||
overflo("out of space in makeinit");
|
||||
for (i=0; i <= k; i++) {
|
||||
(f->posns[2])[i] = (f->re[0].lfollow)[i];
|
||||
}
|
||||
if ((f->posns[2])[1] == f->accept)
|
||||
f->out[2] = 1;
|
||||
for (i=0; i < NCHARS; i++)
|
||||
f->gototab[2][i] = 0;
|
||||
f->curstat = cgoto(f, 2, HAT);
|
||||
if (anchor) {
|
||||
*f->posns[2] = k-1; /* leave out position 0 */
|
||||
for (i=0; i < k; i++) {
|
||||
(f->posns[0])[i] = (f->posns[2])[i];
|
||||
}
|
||||
|
||||
f->out[0] = f->out[2];
|
||||
if (f->curstat != 2) {
|
||||
resize_state(f, f->curstat);
|
||||
--(*f->posns[f->curstat]);
|
||||
}
|
||||
}
|
||||
return f->curstat;
|
||||
}
|
||||
|
||||
void penter(Node *p) /* set up parent pointers and leaf indices */
|
||||
{
|
||||
switch (type(p)) {
|
||||
ELEAF
|
||||
LEAF
|
||||
info(p) = poscnt;
|
||||
poscnt++;
|
||||
break;
|
||||
UNARY
|
||||
penter(left(p));
|
||||
parent(left(p)) = p;
|
||||
break;
|
||||
case CAT:
|
||||
case OR:
|
||||
penter(left(p));
|
||||
penter(right(p));
|
||||
parent(left(p)) = p;
|
||||
parent(right(p)) = p;
|
||||
break;
|
||||
default: /* can't happen */
|
||||
FATAL("can't happen: unknown type %d in penter", type(p));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void freetr(Node *p) /* free parse tree */
|
||||
{
|
||||
switch (type(p)) {
|
||||
ELEAF
|
||||
LEAF
|
||||
xfree(p);
|
||||
break;
|
||||
UNARY
|
||||
freetr(left(p));
|
||||
xfree(p);
|
||||
break;
|
||||
case CAT:
|
||||
case OR:
|
||||
freetr(left(p));
|
||||
freetr(right(p));
|
||||
xfree(p);
|
||||
break;
|
||||
default: /* can't happen */
|
||||
FATAL("can't happen: unknown type %d in freetr", type(p));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* in the parsing of regular expressions, metacharacters like . have */
|
||||
/* to be seen literally; \056 is not a metacharacter. */
|
||||
|
||||
int hexstr(uschar **pp) /* find and eval hex string at pp, return new p */
|
||||
{ /* only pick up one 8-bit byte (2 chars) */
|
||||
uschar *p;
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0, p = (uschar *) *pp; i < 2 && isxdigit(*p); i++, p++) {
|
||||
if (isdigit(*p))
|
||||
n = 16 * n + *p - '0';
|
||||
else if (*p >= 'a' && *p <= 'f')
|
||||
n = 16 * n + *p - 'a' + 10;
|
||||
else if (*p >= 'A' && *p <= 'F')
|
||||
n = 16 * n + *p - 'A' + 10;
|
||||
}
|
||||
*pp = (char *) p;
|
||||
return n;
|
||||
}
|
||||
|
||||
#define isoctdigit(c) ((c) >= '0' && (c) <= '7') /* multiple use of arg */
|
||||
|
||||
int quoted(uschar **pp) /* pick up next thing after a \\ */
|
||||
/* and increment *pp */
|
||||
{
|
||||
uschar *p = *pp;
|
||||
int c;
|
||||
|
||||
if ((c = *p++) == 't')
|
||||
c = '\t';
|
||||
else if (c == 'n')
|
||||
c = '\n';
|
||||
else if (c == 'f')
|
||||
c = '\f';
|
||||
else if (c == 'r')
|
||||
c = '\r';
|
||||
else if (c == 'b')
|
||||
c = '\b';
|
||||
else if (c == '\\')
|
||||
c = '\\';
|
||||
else if (c == 'x') { /* hexadecimal goo follows */
|
||||
c = hexstr(&p); /* this adds a null if number is invalid */
|
||||
} else if (isoctdigit(c)) { /* \d \dd \ddd */
|
||||
int n = c - '0';
|
||||
if (isoctdigit(*p)) {
|
||||
n = 8 * n + *p++ - '0';
|
||||
if (isoctdigit(*p))
|
||||
n = 8 * n + *p++ - '0';
|
||||
}
|
||||
c = n;
|
||||
} /* else */
|
||||
/* c = c; */
|
||||
*pp = p;
|
||||
return c;
|
||||
}
|
||||
|
||||
char *cclenter(const char *argp) /* add a character class */
|
||||
{
|
||||
int i, c, c2;
|
||||
uschar *p = (uschar *) argp;
|
||||
uschar *op, *bp;
|
||||
static uschar *buf = 0;
|
||||
static int bufsz = 100;
|
||||
|
||||
op = p;
|
||||
if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL)
|
||||
FATAL("out of space for character class [%.10s...] 1", p);
|
||||
bp = buf;
|
||||
for (i = 0; (c = *p++) != 0; ) {
|
||||
if (c == '\\') {
|
||||
c = quoted(&p);
|
||||
} else if (c == '-' && i > 0 && bp[-1] != 0) {
|
||||
if (*p != 0) {
|
||||
c = bp[-1];
|
||||
c2 = *p++;
|
||||
if (c2 == '\\')
|
||||
c2 = quoted(&p);
|
||||
if (c > c2) { /* empty; ignore */
|
||||
bp--;
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
while (c < c2) {
|
||||
if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, "cclenter1"))
|
||||
FATAL("out of space for character class [%.10s...] 2", p);
|
||||
*bp++ = ++c;
|
||||
i++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, "cclenter2"))
|
||||
FATAL("out of space for character class [%.10s...] 3", p);
|
||||
*bp++ = c;
|
||||
i++;
|
||||
}
|
||||
*bp = 0;
|
||||
dprintf( ("cclenter: in = |%s|, out = |%s|\n", op, buf) );
|
||||
xfree(op);
|
||||
return (char *) tostring((char *) buf);
|
||||
}
|
||||
|
||||
void overflo(const char *s)
|
||||
{
|
||||
FATAL("regular expression too big: %.30s...", s);
|
||||
}
|
||||
|
||||
void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfollow[leaf] */
|
||||
{
|
||||
int i;
|
||||
int *p;
|
||||
|
||||
switch (type(v)) {
|
||||
ELEAF
|
||||
LEAF
|
||||
f->re[info(v)].ltype = type(v);
|
||||
f->re[info(v)].lval.np = right(v);
|
||||
while (f->accept >= maxsetvec) { /* guessing here! */
|
||||
maxsetvec *= 4;
|
||||
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
|
||||
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
|
||||
if (setvec == 0 || tmpset == 0)
|
||||
overflo("out of space in cfoll()");
|
||||
}
|
||||
for (i = 0; i <= f->accept; i++)
|
||||
setvec[i] = 0;
|
||||
setcnt = 0;
|
||||
follow(v); /* computes setvec and setcnt */
|
||||
if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL)
|
||||
overflo("out of space building follow set");
|
||||
f->re[info(v)].lfollow = p;
|
||||
*p = setcnt;
|
||||
for (i = f->accept; i >= 0; i--)
|
||||
if (setvec[i] == 1)
|
||||
*++p = i;
|
||||
break;
|
||||
UNARY
|
||||
cfoll(f,left(v));
|
||||
break;
|
||||
case CAT:
|
||||
case OR:
|
||||
cfoll(f,left(v));
|
||||
cfoll(f,right(v));
|
||||
break;
|
||||
default: /* can't happen */
|
||||
FATAL("can't happen: unknown type %d in cfoll", type(v));
|
||||
}
|
||||
}
|
||||
|
||||
int first(Node *p) /* collects initially active leaves of p into setvec */
|
||||
/* returns 0 if p matches empty string */
|
||||
{
|
||||
int b, lp;
|
||||
|
||||
switch (type(p)) {
|
||||
ELEAF
|
||||
LEAF
|
||||
lp = info(p); /* look for high-water mark of subscripts */
|
||||
while (setcnt >= maxsetvec || lp >= maxsetvec) { /* guessing here! */
|
||||
maxsetvec *= 4;
|
||||
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
|
||||
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
|
||||
if (setvec == 0 || tmpset == 0)
|
||||
overflo("out of space in first()");
|
||||
}
|
||||
if (type(p) == EMPTYRE) {
|
||||
setvec[lp] = 0;
|
||||
return(0);
|
||||
}
|
||||
if (setvec[lp] != 1) {
|
||||
setvec[lp] = 1;
|
||||
setcnt++;
|
||||
}
|
||||
if (type(p) == CCL && (*(char *) right(p)) == '\0')
|
||||
return(0); /* empty CCL */
|
||||
else return(1);
|
||||
case PLUS:
|
||||
if (first(left(p)) == 0) return(0);
|
||||
return(1);
|
||||
case STAR:
|
||||
case QUEST:
|
||||
first(left(p));
|
||||
return(0);
|
||||
case CAT:
|
||||
if (first(left(p)) == 0 && first(right(p)) == 0) return(0);
|
||||
return(1);
|
||||
case OR:
|
||||
b = first(right(p));
|
||||
if (first(left(p)) == 0 || b == 0) return(0);
|
||||
return(1);
|
||||
}
|
||||
FATAL("can't happen: unknown type %d in first", type(p)); /* can't happen */
|
||||
return(-1);
|
||||
}
|
||||
|
||||
void follow(Node *v) /* collects leaves that can follow v into setvec */
|
||||
{
|
||||
Node *p;
|
||||
|
||||
if (type(v) == FINAL)
|
||||
return;
|
||||
p = parent(v);
|
||||
switch (type(p)) {
|
||||
case STAR:
|
||||
case PLUS:
|
||||
first(v);
|
||||
follow(p);
|
||||
return;
|
||||
|
||||
case OR:
|
||||
case QUEST:
|
||||
follow(p);
|
||||
return;
|
||||
|
||||
case CAT:
|
||||
if (v == left(p)) { /* v is left child of p */
|
||||
if (first(right(p)) == 0) {
|
||||
follow(p);
|
||||
return;
|
||||
}
|
||||
} else /* v is right child */
|
||||
follow(p);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int member(int c, const char *sarg) /* is c in s? */
|
||||
{
|
||||
uschar *s = (uschar *) sarg;
|
||||
|
||||
while (*s)
|
||||
if (c == *s++)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int match(fa *f, const char *p0) /* shortest match ? */
|
||||
{
|
||||
int s, ns;
|
||||
uschar *p = (uschar *) p0;
|
||||
|
||||
s = f->initstat;
|
||||
assert (s < f->state_count);
|
||||
|
||||
if (f->out[s])
|
||||
return(1);
|
||||
do {
|
||||
/* assert(*p < NCHARS); */
|
||||
if ((ns = f->gototab[s][*p]) != 0)
|
||||
s = ns;
|
||||
else
|
||||
s = cgoto(f, s, *p);
|
||||
|
||||
assert (s < f->state_count);
|
||||
|
||||
if (f->out[s])
|
||||
return(1);
|
||||
} while (*p++ != 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int pmatch(fa *f, const char *p0) /* longest match, for sub */
|
||||
{
|
||||
int s, ns;
|
||||
uschar *p = (uschar *) p0;
|
||||
uschar *q;
|
||||
|
||||
s = f->initstat;
|
||||
assert(s < f->state_count);
|
||||
patbeg = p;
|
||||
patlen = -1;
|
||||
do {
|
||||
q = p;
|
||||
do {
|
||||
if (f->out[s]) /* final state */
|
||||
patlen = q-p;
|
||||
/* assert(*q < NCHARS); */
|
||||
if ((ns = f->gototab[s][*q]) != 0)
|
||||
s = ns;
|
||||
else
|
||||
s = cgoto(f, s, *q);
|
||||
|
||||
assert(s < f->state_count);
|
||||
|
||||
if (s == 1) { /* no transition */
|
||||
if (patlen >= 0) {
|
||||
patbeg = p;
|
||||
return(1);
|
||||
}
|
||||
else
|
||||
goto nextin; /* no match */
|
||||
}
|
||||
} while (*q++ != 0);
|
||||
if (f->out[s])
|
||||
patlen = q-p-1; /* don't count $ */
|
||||
if (patlen >= 0) {
|
||||
patbeg = p;
|
||||
return(1);
|
||||
}
|
||||
nextin:
|
||||
s = 2;
|
||||
} while (*p++ != 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int nematch(fa *f, const char *p0) /* non-empty match, for sub */
|
||||
{
|
||||
int s, ns;
|
||||
uschar *p = (uschar *) p0;
|
||||
uschar *q;
|
||||
|
||||
s = f->initstat;
|
||||
assert(s < f->state_count);
|
||||
|
||||
patlen = -1;
|
||||
while (*p) {
|
||||
q = p;
|
||||
do {
|
||||
if (f->out[s]) /* final state */
|
||||
patlen = q-p;
|
||||
/* assert(*q < NCHARS); */
|
||||
if ((ns = f->gototab[s][*q]) != 0)
|
||||
s = ns;
|
||||
else
|
||||
s = cgoto(f, s, *q);
|
||||
|
||||
assert(s < f->state_count);
|
||||
|
||||
if (s == 1) { /* no transition */
|
||||
if (patlen > 0) {
|
||||
patbeg = p;
|
||||
return(1);
|
||||
} else
|
||||
goto nnextin; /* no nonempty match */
|
||||
}
|
||||
} while (*q++ != 0);
|
||||
if (f->out[s])
|
||||
patlen = q-p-1; /* don't count $ */
|
||||
if (patlen > 0 ) {
|
||||
patbeg = p;
|
||||
return(1);
|
||||
}
|
||||
nnextin:
|
||||
s = 2;
|
||||
p++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
Node *reparse(const char *p) /* parses regular expression pointed to by p */
|
||||
{ /* uses relex() to scan regular expression */
|
||||
Node *np;
|
||||
|
||||
dprintf( ("reparse <%s>\n", p) );
|
||||
lastre = prestr = (uschar *) p; /* prestr points to string to be parsed */
|
||||
rtok = relex();
|
||||
/* GNU compatibility: an empty regexp matches anything */
|
||||
if (rtok == '\0') {
|
||||
/* FATAL("empty regular expression"); previous */
|
||||
return(op2(EMPTYRE, NIL, NIL));
|
||||
}
|
||||
np = regexp();
|
||||
if (rtok != '\0')
|
||||
FATAL("syntax error in regular expression %s at %s", lastre, prestr);
|
||||
return(np);
|
||||
}
|
||||
|
||||
Node *regexp(void) /* top-level parse of reg expr */
|
||||
{
|
||||
return (alt(concat(primary())));
|
||||
}
|
||||
|
||||
Node *primary(void)
|
||||
{
|
||||
Node *np;
|
||||
|
||||
switch (rtok) {
|
||||
case CHAR:
|
||||
np = op2(CHAR, NIL, itonp(rlxval));
|
||||
rtok = relex();
|
||||
return (unary(np));
|
||||
case ALL:
|
||||
rtok = relex();
|
||||
return (unary(op2(ALL, NIL, NIL)));
|
||||
case EMPTYRE:
|
||||
rtok = relex();
|
||||
return (unary(op2(ALL, NIL, NIL)));
|
||||
case DOT:
|
||||
rtok = relex();
|
||||
return (unary(op2(DOT, NIL, NIL)));
|
||||
case CCL:
|
||||
np = op2(CCL, NIL, (Node*) cclenter((char *) rlxstr));
|
||||
rtok = relex();
|
||||
return (unary(np));
|
||||
case NCCL:
|
||||
np = op2(NCCL, NIL, (Node *) cclenter((char *) rlxstr));
|
||||
rtok = relex();
|
||||
return (unary(np));
|
||||
case '^':
|
||||
rtok = relex();
|
||||
return (unary(op2(CHAR, NIL, itonp(HAT))));
|
||||
case '$':
|
||||
rtok = relex();
|
||||
return (unary(op2(CHAR, NIL, NIL)));
|
||||
case '(':
|
||||
rtok = relex();
|
||||
if (rtok == ')') { /* special pleading for () */
|
||||
rtok = relex();
|
||||
return unary(op2(CCL, NIL, (Node *) tostring("")));
|
||||
}
|
||||
np = regexp();
|
||||
if (rtok == ')') {
|
||||
rtok = relex();
|
||||
return (unary(np));
|
||||
}
|
||||
else
|
||||
FATAL("syntax error in regular expression %s at %s", lastre, prestr);
|
||||
default:
|
||||
FATAL("illegal primary in regular expression %s at %s", lastre, prestr);
|
||||
}
|
||||
return 0; /*NOTREACHED*/
|
||||
}
|
||||
|
||||
Node *concat(Node *np)
|
||||
{
|
||||
switch (rtok) {
|
||||
case CHAR: case DOT: case ALL: case EMPTYRE: case CCL: case NCCL: case '$': case '(':
|
||||
return (concat(op2(CAT, np, primary())));
|
||||
}
|
||||
return (np);
|
||||
}
|
||||
|
||||
Node *alt(Node *np)
|
||||
{
|
||||
if (rtok == OR) {
|
||||
rtok = relex();
|
||||
return (alt(op2(OR, np, concat(primary()))));
|
||||
}
|
||||
return (np);
|
||||
}
|
||||
|
||||
Node *unary(Node *np)
|
||||
{
|
||||
switch (rtok) {
|
||||
case STAR:
|
||||
rtok = relex();
|
||||
return (unary(op2(STAR, np, NIL)));
|
||||
case PLUS:
|
||||
rtok = relex();
|
||||
return (unary(op2(PLUS, np, NIL)));
|
||||
case QUEST:
|
||||
rtok = relex();
|
||||
return (unary(op2(QUEST, np, NIL)));
|
||||
default:
|
||||
return (np);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Character class definitions conformant to the POSIX locale as
|
||||
* defined in IEEE P1003.1 draft 7 of June 2001, assuming the source
|
||||
* and operating character sets are both ASCII (ISO646) or supersets
|
||||
* thereof.
|
||||
*
|
||||
* Note that to avoid overflowing the temporary buffer used in
|
||||
* relex(), the expanded character class (prior to range expansion)
|
||||
* must be less than twice the size of their full name.
|
||||
*/
|
||||
|
||||
/* Because isblank doesn't show up in any of the header files on any
|
||||
* system i use, it's defined here. if some other locale has a richer
|
||||
* definition of "blank", define HAS_ISBLANK and provide your own
|
||||
* version.
|
||||
* the parentheses here are an attempt to find a path through the maze
|
||||
* of macro definition and/or function and/or version provided. thanks
|
||||
* to nelson beebe for the suggestion; let's see if it works everywhere.
|
||||
*/
|
||||
|
||||
#ifndef HAS_ISBLANK
|
||||
|
||||
int (isblank)(int c)
|
||||
{
|
||||
return c==' ' || c=='\t';
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static const struct charclass {
|
||||
const char *cc_name;
|
||||
int cc_namelen;
|
||||
int (*cc_func)(int);
|
||||
} charclasses[] = {
|
||||
{ "alnum", 5, isalnum },
|
||||
{ "alpha", 5, isalpha },
|
||||
{ "blank", 5, isblank },
|
||||
{ "cntrl", 5, iscntrl },
|
||||
{ "digit", 5, isdigit },
|
||||
{ "graph", 5, isgraph },
|
||||
{ "lower", 5, islower },
|
||||
{ "print", 5, isprint },
|
||||
{ "punct", 5, ispunct },
|
||||
{ "space", 5, isspace },
|
||||
{ "upper", 5, isupper },
|
||||
{ "xdigit", 6, isxdigit },
|
||||
{ NULL, 0, NULL },
|
||||
};
|
||||
|
||||
|
||||
int relex(void) /* lexical analyzer for reparse */
|
||||
{
|
||||
int c, n;
|
||||
int cflag;
|
||||
static uschar *buf = 0;
|
||||
static int bufsz = 100;
|
||||
uschar *bp;
|
||||
const struct charclass *cc;
|
||||
int i;
|
||||
|
||||
switch (c = *prestr++) {
|
||||
case '|': return OR;
|
||||
case '*': return STAR;
|
||||
case '+': return PLUS;
|
||||
case '?': return QUEST;
|
||||
case '.': return DOT;
|
||||
case '\0': prestr--; return '\0';
|
||||
case '^':
|
||||
case '$':
|
||||
case '(':
|
||||
case ')':
|
||||
return c;
|
||||
case '\\':
|
||||
rlxval = quoted(&prestr);
|
||||
return CHAR;
|
||||
default:
|
||||
rlxval = c;
|
||||
return CHAR;
|
||||
case '[':
|
||||
if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL)
|
||||
FATAL("out of space in reg expr %.10s..", lastre);
|
||||
bp = buf;
|
||||
if (*prestr == '^') {
|
||||
cflag = 1;
|
||||
prestr++;
|
||||
}
|
||||
else
|
||||
cflag = 0;
|
||||
n = 2 * strlen((const char *) prestr)+1;
|
||||
if (!adjbuf(&buf, &bufsz, n, n, &bp, "relex1"))
|
||||
FATAL("out of space for reg expr %.10s...", lastre);
|
||||
for (; ; ) {
|
||||
if ((c = *prestr++) == '\\') {
|
||||
*bp++ = '\\';
|
||||
if ((c = *prestr++) == '\0')
|
||||
FATAL("nonterminated character class %.20s...", lastre);
|
||||
*bp++ = c;
|
||||
/* } else if (c == '\n') { */
|
||||
/* FATAL("newline in character class %.20s...", lastre); */
|
||||
} else if (c == '[' && *prestr == ':') {
|
||||
/* POSIX char class names, Dag-Erling Smorgrav, des@ofug.org */
|
||||
for (cc = charclasses; cc->cc_name; cc++)
|
||||
if (strncmp((const char *) prestr + 1, (const char *) cc->cc_name, cc->cc_namelen) == 0)
|
||||
break;
|
||||
if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' &&
|
||||
prestr[2 + cc->cc_namelen] == ']') {
|
||||
prestr += cc->cc_namelen + 3;
|
||||
for (i = 1; i < NCHARS; i++) {
|
||||
if (!adjbuf(&buf, &bufsz, bp-buf+1, 100, &bp, "relex2"))
|
||||
FATAL("out of space for reg expr %.10s...", lastre);
|
||||
if (cc->cc_func(i)) {
|
||||
*bp++ = i;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
*bp++ = c;
|
||||
} else if (c == '\0') {
|
||||
FATAL("nonterminated character class %.20s", lastre);
|
||||
} else if (bp == buf) { /* 1st char is special */
|
||||
*bp++ = c;
|
||||
} else if (c == ']') {
|
||||
*bp++ = 0;
|
||||
rlxstr = (uschar *) tostring((char *) buf);
|
||||
if (cflag == 0)
|
||||
return CCL;
|
||||
else
|
||||
return NCCL;
|
||||
} else
|
||||
*bp++ = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int cgoto(fa *f, int s, int c)
|
||||
{
|
||||
int i, j, k;
|
||||
int *p, *q;
|
||||
|
||||
assert(c == HAT || c < NCHARS);
|
||||
while (f->accept >= maxsetvec) { /* guessing here! */
|
||||
maxsetvec *= 4;
|
||||
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
|
||||
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
|
||||
if (setvec == 0 || tmpset == 0)
|
||||
overflo("out of space in cgoto()");
|
||||
}
|
||||
for (i = 0; i <= f->accept; i++)
|
||||
setvec[i] = 0;
|
||||
setcnt = 0;
|
||||
resize_state(f, s);
|
||||
/* compute positions of gototab[s,c] into setvec */
|
||||
p = f->posns[s];
|
||||
for (i = 1; i <= *p; i++) {
|
||||
if ((k = f->re[p[i]].ltype) != FINAL) {
|
||||
if ((k == CHAR && c == ptoi(f->re[p[i]].lval.np))
|
||||
|| (k == DOT && c != 0 && c != HAT)
|
||||
|| (k == ALL && c != 0)
|
||||
|| (k == EMPTYRE && c != 0)
|
||||
|| (k == CCL && member(c, (char *) f->re[p[i]].lval.up))
|
||||
|| (k == NCCL && !member(c, (char *) f->re[p[i]].lval.up) && c != 0 && c != HAT)) {
|
||||
q = f->re[p[i]].lfollow;
|
||||
for (j = 1; j <= *q; j++) {
|
||||
if (q[j] >= maxsetvec) {
|
||||
maxsetvec *= 4;
|
||||
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
|
||||
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
|
||||
if (setvec == 0 || tmpset == 0)
|
||||
overflo("cgoto overflow");
|
||||
}
|
||||
if (setvec[q[j]] == 0) {
|
||||
setcnt++;
|
||||
setvec[q[j]] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* determine if setvec is a previous state */
|
||||
tmpset[0] = setcnt;
|
||||
j = 1;
|
||||
for (i = f->accept; i >= 0; i--)
|
||||
if (setvec[i]) {
|
||||
tmpset[j++] = i;
|
||||
}
|
||||
|
||||
resize_state(f, f->curstat > s ? f->curstat : s);
|
||||
/* tmpset == previous state? */
|
||||
for (i = 1; i <= f->curstat; i++) {
|
||||
p = f->posns[i];
|
||||
if ((k = tmpset[0]) != p[0])
|
||||
goto different;
|
||||
for (j = 1; j <= k; j++)
|
||||
if (tmpset[j] != p[j])
|
||||
goto different;
|
||||
/* setvec is state i */
|
||||
if (c != HAT)
|
||||
f->gototab[s][c] = i;
|
||||
return i;
|
||||
different:;
|
||||
}
|
||||
|
||||
/* add tmpset to current set of states */
|
||||
++(f->curstat);
|
||||
resize_state(f, f->curstat);
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
f->gototab[f->curstat][i] = 0;
|
||||
xfree(f->posns[f->curstat]);
|
||||
if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL)
|
||||
overflo("out of space in cgoto");
|
||||
|
||||
f->posns[f->curstat] = p;
|
||||
if (c != HAT)
|
||||
f->gototab[s][c] = f->curstat;
|
||||
for (i = 0; i <= setcnt; i++)
|
||||
p[i] = tmpset[i];
|
||||
if (setvec[f->accept])
|
||||
f->out[f->curstat] = 1;
|
||||
else
|
||||
f->out[f->curstat] = 0;
|
||||
return f->curstat;
|
||||
}
|
||||
|
||||
|
||||
void freefa(fa *f) /* free a finite automaton */
|
||||
{
|
||||
int i;
|
||||
|
||||
if (f == NULL)
|
||||
return;
|
||||
for (i = 0; i < f->state_count; i++) {
|
||||
xfree(f->gototab[i])
|
||||
xfree(f->posns[i]);
|
||||
}
|
||||
for (i = 0; i <= f->accept; i++) {
|
||||
xfree(f->re[i].lfollow);
|
||||
if (f->re[i].ltype == CCL || f->re[i].ltype == NCCL)
|
||||
xfree((f->re[i].lval.np));
|
||||
}
|
||||
xfree(f->restr);
|
||||
xfree(f->out);
|
||||
xfree(f->posns);
|
||||
xfree(f->gototab);
|
||||
xfree(f);
|
||||
}
|
|
@ -1,596 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
extern int infunc;
|
||||
|
||||
int lineno = 1;
|
||||
int bracecnt = 0;
|
||||
int brackcnt = 0;
|
||||
int parencnt = 0;
|
||||
|
||||
typedef struct Keyword {
|
||||
const char *word;
|
||||
int sub;
|
||||
int type;
|
||||
} Keyword;
|
||||
|
||||
int peek(void);
|
||||
int gettok(char **, int *);
|
||||
int binsearch(const char *, const Keyword *, int);
|
||||
|
||||
const Keyword keywords[] ={ /* keep sorted: binary searched */
|
||||
{ "BEGIN", XBEGIN, XBEGIN },
|
||||
{ "END", XEND, XEND },
|
||||
{ "NF", VARNF, VARNF },
|
||||
{ "atan2", FATAN, BLTIN },
|
||||
{ "break", BREAK, BREAK },
|
||||
{ "close", CLOSE, CLOSE },
|
||||
{ "continue", CONTINUE, CONTINUE },
|
||||
{ "cos", FCOS, BLTIN },
|
||||
{ "delete", DELETE, DELETE },
|
||||
{ "do", DO, DO },
|
||||
{ "else", ELSE, ELSE },
|
||||
{ "exit", EXIT, EXIT },
|
||||
{ "exp", FEXP, BLTIN },
|
||||
{ "fflush", FFLUSH, BLTIN },
|
||||
{ "for", FOR, FOR },
|
||||
{ "func", FUNC, FUNC },
|
||||
{ "function", FUNC, FUNC },
|
||||
{ "gensub", GENSUB, GENSUB },
|
||||
{ "getline", GETLINE, GETLINE },
|
||||
{ "gsub", GSUB, GSUB },
|
||||
{ "if", IF, IF },
|
||||
{ "in", IN, IN },
|
||||
{ "index", INDEX, INDEX },
|
||||
{ "int", FINT, BLTIN },
|
||||
{ "length", FLENGTH, BLTIN },
|
||||
{ "log", FLOG, BLTIN },
|
||||
{ "match", MATCHFCN, MATCHFCN },
|
||||
{ "next", NEXT, NEXT },
|
||||
{ "nextfile", NEXTFILE, NEXTFILE },
|
||||
{ "print", PRINT, PRINT },
|
||||
{ "printf", PRINTF, PRINTF },
|
||||
{ "rand", FRAND, BLTIN },
|
||||
{ "return", RETURN, RETURN },
|
||||
{ "sin", FSIN, BLTIN },
|
||||
{ "split", SPLIT, SPLIT },
|
||||
{ "sprintf", SPRINTF, SPRINTF },
|
||||
{ "sqrt", FSQRT, BLTIN },
|
||||
{ "srand", FSRAND, BLTIN },
|
||||
{ "strftime", FSTRFTIME, BLTIN },
|
||||
{ "sub", SUB, SUB },
|
||||
{ "substr", SUBSTR, SUBSTR },
|
||||
{ "system", FSYSTEM, BLTIN },
|
||||
{ "systime", FSYSTIME, BLTIN },
|
||||
{ "tolower", FTOLOWER, BLTIN },
|
||||
{ "toupper", FTOUPPER, BLTIN },
|
||||
{ "while", WHILE, WHILE },
|
||||
};
|
||||
|
||||
#define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); }
|
||||
|
||||
int peek(void)
|
||||
{
|
||||
int c = input();
|
||||
unput(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
int gettok(char **pbuf, int *psz) /* get next input token */
|
||||
{
|
||||
int c, retc;
|
||||
uschar *buf = (uschar *) *pbuf;
|
||||
int sz = *psz;
|
||||
uschar *bp = buf;
|
||||
|
||||
c = input();
|
||||
if (c == 0)
|
||||
return 0;
|
||||
buf[0] = c;
|
||||
buf[1] = 0;
|
||||
if (!isalnum(c) && c != '.' && c != '_')
|
||||
return c;
|
||||
|
||||
*bp++ = c;
|
||||
if (isalpha(c) || c == '_') { /* it's a varname */
|
||||
for ( ; (c = input()) != 0; ) {
|
||||
if (bp-buf >= sz)
|
||||
if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
|
||||
FATAL( "out of space for name %.10s...", buf );
|
||||
if (isalnum(c) || c == '_')
|
||||
*bp++ = c;
|
||||
else {
|
||||
*bp = 0;
|
||||
unput(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*bp = 0;
|
||||
retc = 'a'; /* alphanumeric */
|
||||
} else { /* maybe it's a number, but could be . */
|
||||
char *rem;
|
||||
/* read input until can't be a number */
|
||||
for ( ; (c = input()) != 0; ) {
|
||||
if (bp-buf >= sz)
|
||||
if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
|
||||
FATAL( "out of space for number %.10s...", buf );
|
||||
if (isdigit(c) || c == 'e' || c == 'E'
|
||||
|| c == '.' || c == '+' || c == '-')
|
||||
*bp++ = c;
|
||||
else {
|
||||
unput(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*bp = 0;
|
||||
strtod(buf, &rem); /* parse the number */
|
||||
if (rem == (char *)buf) { /* it wasn't a valid number at all */
|
||||
buf[1] = 0; /* return one character as token */
|
||||
retc = buf[0]; /* character is its own type */
|
||||
unputstr(rem+1); /* put rest back for later */
|
||||
} else { /* some prefix was a number */
|
||||
unputstr(rem); /* put rest back for later */
|
||||
rem[0] = 0; /* truncate buf after number part */
|
||||
retc = '0'; /* type is number */
|
||||
}
|
||||
}
|
||||
*pbuf = buf;
|
||||
*psz = sz;
|
||||
return retc;
|
||||
}
|
||||
|
||||
int word(char *);
|
||||
int string(void);
|
||||
int regexpr(void);
|
||||
int sc = 0; /* 1 => return a } right now */
|
||||
int reg = 0; /* 1 => return a REGEXPR now */
|
||||
|
||||
int yylex(void)
|
||||
{
|
||||
int c;
|
||||
static char *buf = 0;
|
||||
static int bufsize = 5; /* BUG: setting this small causes core dump! */
|
||||
|
||||
if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL)
|
||||
FATAL( "out of space in yylex" );
|
||||
if (sc) {
|
||||
sc = 0;
|
||||
RET('}');
|
||||
}
|
||||
if (reg) {
|
||||
reg = 0;
|
||||
return regexpr();
|
||||
}
|
||||
for (;;) {
|
||||
c = gettok(&buf, &bufsize);
|
||||
if (c == 0)
|
||||
return 0;
|
||||
if (isalpha(c) || c == '_')
|
||||
return word(buf);
|
||||
if (isdigit(c)) {
|
||||
yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
|
||||
/* should this also have STR set? */
|
||||
RET(NUMBER);
|
||||
}
|
||||
|
||||
yylval.i = c;
|
||||
switch (c) {
|
||||
case '\n': /* {EOL} */
|
||||
RET(NL);
|
||||
case '\r': /* assume \n is coming */
|
||||
case ' ': /* {WS}+ */
|
||||
case '\t':
|
||||
break;
|
||||
case '#': /* #.* strip comments */
|
||||
while ((c = input()) != '\n' && c != 0)
|
||||
;
|
||||
unput(c);
|
||||
break;
|
||||
case ';':
|
||||
RET(';');
|
||||
case '\\':
|
||||
if (peek() == '\n') {
|
||||
input();
|
||||
} else if (peek() == '\r') {
|
||||
input(); input(); /* \n */
|
||||
lineno++;
|
||||
} else {
|
||||
RET(c);
|
||||
}
|
||||
break;
|
||||
case '&':
|
||||
if (peek() == '&') {
|
||||
input(); RET(AND);
|
||||
} else
|
||||
RET('&');
|
||||
case '|':
|
||||
if (peek() == '|') {
|
||||
input(); RET(BOR);
|
||||
} else
|
||||
RET('|');
|
||||
case '!':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = NE; RET(NE);
|
||||
} else if (peek() == '~') {
|
||||
input(); yylval.i = NOTMATCH; RET(MATCHOP);
|
||||
} else
|
||||
RET(NOT);
|
||||
case '~':
|
||||
yylval.i = MATCH;
|
||||
RET(MATCHOP);
|
||||
case '<':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = LE; RET(LE);
|
||||
} else {
|
||||
yylval.i = LT; RET(LT);
|
||||
}
|
||||
case '=':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = EQ; RET(EQ);
|
||||
} else {
|
||||
yylval.i = ASSIGN; RET(ASGNOP);
|
||||
}
|
||||
case '>':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = GE; RET(GE);
|
||||
} else if (peek() == '>') {
|
||||
input(); yylval.i = APPEND; RET(APPEND);
|
||||
} else {
|
||||
yylval.i = GT; RET(GT);
|
||||
}
|
||||
case '+':
|
||||
if (peek() == '+') {
|
||||
input(); yylval.i = INCR; RET(INCR);
|
||||
} else if (peek() == '=') {
|
||||
input(); yylval.i = ADDEQ; RET(ASGNOP);
|
||||
} else
|
||||
RET('+');
|
||||
case '-':
|
||||
if (peek() == '-') {
|
||||
input(); yylval.i = DECR; RET(DECR);
|
||||
} else if (peek() == '=') {
|
||||
input(); yylval.i = SUBEQ; RET(ASGNOP);
|
||||
} else
|
||||
RET('-');
|
||||
case '*':
|
||||
if (peek() == '=') { /* *= */
|
||||
input(); yylval.i = MULTEQ; RET(ASGNOP);
|
||||
} else if (peek() == '*') { /* ** or **= */
|
||||
input(); /* eat 2nd * */
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = POWEQ; RET(ASGNOP);
|
||||
} else {
|
||||
RET(POWER);
|
||||
}
|
||||
} else
|
||||
RET('*');
|
||||
case '/':
|
||||
RET('/');
|
||||
case '%':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = MODEQ; RET(ASGNOP);
|
||||
} else
|
||||
RET('%');
|
||||
case '^':
|
||||
if (peek() == '=') {
|
||||
input(); yylval.i = POWEQ; RET(ASGNOP);
|
||||
} else
|
||||
RET(POWER);
|
||||
|
||||
case '$':
|
||||
/* BUG: awkward, if not wrong */
|
||||
c = gettok(&buf, &bufsize);
|
||||
if (isalpha(c)) {
|
||||
if (strcmp(buf, "NF") == 0) { /* very special */
|
||||
unputstr("(NF)");
|
||||
RET(INDIRECT);
|
||||
}
|
||||
c = peek();
|
||||
if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) {
|
||||
unputstr(buf);
|
||||
RET(INDIRECT);
|
||||
}
|
||||
yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab);
|
||||
RET(IVAR);
|
||||
} else if (c == 0) { /* */
|
||||
SYNTAX( "unexpected end of input after $" );
|
||||
RET(';');
|
||||
} else {
|
||||
unputstr(buf);
|
||||
RET(INDIRECT);
|
||||
}
|
||||
|
||||
case '}':
|
||||
if (--bracecnt < 0)
|
||||
SYNTAX( "extra }" );
|
||||
sc = 1;
|
||||
RET(';');
|
||||
case ']':
|
||||
if (--brackcnt < 0)
|
||||
SYNTAX( "extra ]" );
|
||||
RET(']');
|
||||
case ')':
|
||||
if (--parencnt < 0)
|
||||
SYNTAX( "extra )" );
|
||||
RET(')');
|
||||
case '{':
|
||||
bracecnt++;
|
||||
RET('{');
|
||||
case '[':
|
||||
brackcnt++;
|
||||
RET('[');
|
||||
case '(':
|
||||
parencnt++;
|
||||
RET('(');
|
||||
|
||||
case '"':
|
||||
return string(); /* BUG: should be like tran.c ? */
|
||||
|
||||
default:
|
||||
RET(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int string(void)
|
||||
{
|
||||
int c, n;
|
||||
uschar *s, *bp;
|
||||
static uschar *buf = 0;
|
||||
static int bufsz = 500;
|
||||
|
||||
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
|
||||
FATAL("out of space for strings");
|
||||
for (bp = buf; (c = input()) != '"'; ) {
|
||||
if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string"))
|
||||
FATAL("out of space for string %.10s...", buf);
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
case 0:
|
||||
SYNTAX( "non-terminated string %.10s...", buf );
|
||||
lineno++;
|
||||
if (c == 0) /* hopeless */
|
||||
FATAL( "giving up" );
|
||||
break;
|
||||
case '\\':
|
||||
c = input();
|
||||
switch (c) {
|
||||
case '\n': break;
|
||||
case '"': *bp++ = '"'; break;
|
||||
case 'n': *bp++ = '\n'; break;
|
||||
case 't': *bp++ = '\t'; break;
|
||||
case 'f': *bp++ = '\f'; break;
|
||||
case 'r': *bp++ = '\r'; break;
|
||||
case 'b': *bp++ = '\b'; break;
|
||||
case 'v': *bp++ = '\v'; break;
|
||||
case 'a': *bp++ = '\007'; break;
|
||||
case '\\': *bp++ = '\\'; break;
|
||||
|
||||
case '0': case '1': case '2': /* octal: \d \dd \ddd */
|
||||
case '3': case '4': case '5': case '6': case '7':
|
||||
n = c - '0';
|
||||
if ((c = peek()) >= '0' && c < '8') {
|
||||
n = 8 * n + input() - '0';
|
||||
if ((c = peek()) >= '0' && c < '8')
|
||||
n = 8 * n + input() - '0';
|
||||
}
|
||||
*bp++ = n;
|
||||
break;
|
||||
|
||||
case 'x': /* hex \x0-9a-fA-F + */
|
||||
{ char xbuf[100], *px;
|
||||
for (px = xbuf; (c = input()) != 0 && px-xbuf < 100-2; ) {
|
||||
if (isdigit(c)
|
||||
|| (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F'))
|
||||
*px++ = c;
|
||||
else
|
||||
break;
|
||||
}
|
||||
*px = 0;
|
||||
unput(c);
|
||||
sscanf(xbuf, "%x", &n);
|
||||
*bp++ = n;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
WARNING("warning: escape sequence `\\%c' "
|
||||
"treated as plain `%c'", c, c);
|
||||
*bp++ = c;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*bp++ = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*bp = 0;
|
||||
s = tostring(buf);
|
||||
*bp++ = ' '; *bp++ = 0;
|
||||
yylval.cp = setsymtab(buf, s, 0.0, CON|STR|DONTFREE, symtab);
|
||||
RET(STRING);
|
||||
}
|
||||
|
||||
|
||||
int binsearch(const char *w, const Keyword *kp, int n)
|
||||
{
|
||||
int cond, low, mid, high;
|
||||
|
||||
low = 0;
|
||||
high = n - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
if ((cond = strcmp(w, kp[mid].word)) < 0)
|
||||
high = mid - 1;
|
||||
else if (cond > 0)
|
||||
low = mid + 1;
|
||||
else
|
||||
return mid;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int word(char *w)
|
||||
{
|
||||
const Keyword *kp;
|
||||
int c, n;
|
||||
|
||||
n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
|
||||
/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
|
||||
kp = keywords + n;
|
||||
if (n != -1) { /* found in table */
|
||||
yylval.i = kp->sub;
|
||||
switch (kp->type) { /* special handling */
|
||||
case BLTIN:
|
||||
if (kp->sub == FSYSTEM && safe)
|
||||
SYNTAX( "system is unsafe" );
|
||||
RET(kp->type);
|
||||
case FUNC:
|
||||
if (infunc)
|
||||
SYNTAX( "illegal nested function" );
|
||||
RET(kp->type);
|
||||
case RETURN:
|
||||
if (!infunc)
|
||||
SYNTAX( "return not in function" );
|
||||
RET(kp->type);
|
||||
case VARNF:
|
||||
yylval.cp = setsymtab("NF", "", 0.0, NUM, symtab);
|
||||
RET(VARNF);
|
||||
default:
|
||||
RET(kp->type);
|
||||
}
|
||||
}
|
||||
c = peek(); /* look for '(' */
|
||||
if (c != '(' && infunc && (n=isarg(w)) >= 0) {
|
||||
yylval.i = n;
|
||||
RET(ARG);
|
||||
} else {
|
||||
yylval.cp = setsymtab(w, "", 0.0, STR|NUM|DONTFREE, symtab);
|
||||
if (c == '(') {
|
||||
RET(CALL);
|
||||
} else {
|
||||
RET(VAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void startreg(void) /* next call to yylex will return a regular expression */
|
||||
{
|
||||
reg = 1;
|
||||
}
|
||||
|
||||
int regexpr(void)
|
||||
{
|
||||
int c;
|
||||
static uschar *buf = 0;
|
||||
static int bufsz = 500;
|
||||
uschar *bp;
|
||||
|
||||
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
|
||||
FATAL("out of space for rex expr");
|
||||
bp = buf;
|
||||
for ( ; (c = input()) != '/' && c != 0; ) {
|
||||
if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr"))
|
||||
FATAL("out of space for reg expr %.10s...", buf);
|
||||
if (c == '\n') {
|
||||
SYNTAX( "newline in regular expression %.10s...", buf );
|
||||
unput('\n');
|
||||
break;
|
||||
} else if (c == '\\') {
|
||||
*bp++ = '\\';
|
||||
*bp++ = input();
|
||||
} else {
|
||||
*bp++ = c;
|
||||
}
|
||||
}
|
||||
*bp = 0;
|
||||
if (c == 0)
|
||||
SYNTAX("non-terminated regular expression %.10s...", buf);
|
||||
yylval.s = tostring(buf);
|
||||
unput('/');
|
||||
RET(REGEXPR);
|
||||
}
|
||||
|
||||
/* low-level lexical stuff, sort of inherited from lex */
|
||||
|
||||
char ebuf[300];
|
||||
char *ep = ebuf;
|
||||
char yysbuf[100]; /* pushback buffer */
|
||||
char *yysptr = yysbuf;
|
||||
FILE *yyin = 0;
|
||||
|
||||
int input(void) /* get next lexical input character */
|
||||
{
|
||||
int c;
|
||||
extern char *lexprog;
|
||||
|
||||
if (yysptr > yysbuf)
|
||||
c = (uschar)*--yysptr;
|
||||
else if (lexprog != NULL) { /* awk '...' */
|
||||
if ((c = (uschar)*lexprog) != 0)
|
||||
lexprog++;
|
||||
} else /* awk -f ... */
|
||||
c = pgetc();
|
||||
if (c == '\n')
|
||||
lineno++;
|
||||
else if (c == EOF)
|
||||
c = 0;
|
||||
if (ep >= ebuf + sizeof ebuf)
|
||||
ep = ebuf;
|
||||
return *ep++ = c;
|
||||
}
|
||||
|
||||
void unput(int c) /* put lexical character back on input */
|
||||
{
|
||||
if (c == '\n')
|
||||
lineno--;
|
||||
if (yysptr >= yysbuf + sizeof(yysbuf))
|
||||
FATAL("pushed back too much: %.20s...", yysbuf);
|
||||
*yysptr++ = c;
|
||||
if (--ep < ebuf)
|
||||
ep = ebuf + sizeof(ebuf) - 1;
|
||||
}
|
||||
|
||||
void unputstr(const char *s) /* put a string back on input */
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = strlen(s)-1; i >= 0; i--)
|
||||
unput(s[i]);
|
||||
}
|
|
@ -1,763 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
FILE *infile = NULL;
|
||||
char *file = "";
|
||||
uschar *record;
|
||||
int recsize = RECSIZE;
|
||||
char *fields;
|
||||
int fieldssize = RECSIZE;
|
||||
|
||||
Cell **fldtab; /* pointers to Cells */
|
||||
|
||||
static char static_inputFS[16] = " ";
|
||||
static size_t len_inputFS = sizeof(static_inputFS) - 1;
|
||||
static char *inputFS = static_inputFS;
|
||||
|
||||
#define MAXFLD 2
|
||||
int nfields = MAXFLD; /* last allocated slot for $i */
|
||||
|
||||
int donefld; /* 1 = implies rec broken into fields */
|
||||
int donerec; /* 1 = record is valid (no flds have changed) */
|
||||
|
||||
int lastfld = 0; /* last used field */
|
||||
int argno = 1; /* current input argument number */
|
||||
extern Awkfloat *ARGC;
|
||||
|
||||
static Cell dollar0 = { OCELL, CFLD, NULL, "", 0.0, REC|STR|DONTFREE };
|
||||
static Cell dollar1 = { OCELL, CFLD, NULL, "", 0.0, FLD|STR|DONTFREE };
|
||||
|
||||
void recinit(unsigned int n)
|
||||
{
|
||||
if ( (record = (char *) malloc(n)) == NULL
|
||||
|| (fields = (char *) malloc(n)) == NULL
|
||||
|| (fldtab = (Cell **) malloc((nfields+1) * sizeof(Cell *))) == NULL
|
||||
|| (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL )
|
||||
FATAL("out of space for $0 and fields");
|
||||
*fldtab[0] = dollar0;
|
||||
fldtab[0]->sval = record;
|
||||
fldtab[0]->nval = tostring("0");
|
||||
makefields(1, nfields);
|
||||
}
|
||||
|
||||
void makefields(int n1, int n2) /* create $n1..$n2 inclusive */
|
||||
{
|
||||
char temp[50];
|
||||
int i;
|
||||
|
||||
for (i = n1; i <= n2; i++) {
|
||||
fldtab[i] = (Cell *) malloc(sizeof (struct Cell));
|
||||
if (fldtab[i] == NULL)
|
||||
FATAL("out of space in makefields %d", i);
|
||||
*fldtab[i] = dollar1;
|
||||
snprintf(temp, sizeof(temp), "%d", i);
|
||||
fldtab[i]->nval = tostring(temp);
|
||||
}
|
||||
}
|
||||
|
||||
void initgetrec(void)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
for (i = 1; i < *ARGC; i++) {
|
||||
if (!isclvar(p = getargv(i))) { /* find 1st real filename */
|
||||
setsval(lookup("FILENAME", symtab), getargv(i));
|
||||
return;
|
||||
}
|
||||
setclvar(p); /* a commandline assignment before filename */
|
||||
argno++;
|
||||
}
|
||||
infile = stdin; /* no filenames, so use stdin */
|
||||
}
|
||||
|
||||
static int firsttime = 1;
|
||||
|
||||
int getrec(uschar **pbuf, int *pbufsize, int isrecord) /* get next input record */
|
||||
{ /* note: cares whether buf == record */
|
||||
int c;
|
||||
uschar *buf = *pbuf;
|
||||
uschar saveb0;
|
||||
int bufsize = *pbufsize, savebufsize = bufsize;
|
||||
|
||||
if (firsttime) {
|
||||
firsttime = 0;
|
||||
initgetrec();
|
||||
}
|
||||
dprintf( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n",
|
||||
*RS, *FS, *ARGC, *FILENAME) );
|
||||
if (isrecord) {
|
||||
donefld = 0;
|
||||
donerec = 1;
|
||||
}
|
||||
saveb0 = buf[0];
|
||||
buf[0] = 0;
|
||||
while (argno < *ARGC || infile == stdin) {
|
||||
dprintf( ("argno=%d, file=|%s|\n", argno, file) );
|
||||
if (infile == NULL) { /* have to open a new file */
|
||||
file = getargv(argno);
|
||||
if (*file == '\0') { /* it's been zapped */
|
||||
argno++;
|
||||
continue;
|
||||
}
|
||||
if (isclvar(file)) { /* a var=value arg */
|
||||
setclvar(file);
|
||||
argno++;
|
||||
continue;
|
||||
}
|
||||
*FILENAME = file;
|
||||
dprintf( ("opening file %s\n", file) );
|
||||
if (*file == '-' && *(file+1) == '\0')
|
||||
infile = stdin;
|
||||
else if ((infile = fopen(file, "r")) == NULL)
|
||||
FATAL("can't open file %s", file);
|
||||
setfval(fnrloc, 0.0);
|
||||
}
|
||||
c = readrec(&buf, &bufsize, infile);
|
||||
if (c != 0 || buf[0] != '\0') { /* normal record */
|
||||
if (isrecord) {
|
||||
if (freeable(fldtab[0]))
|
||||
xfree(fldtab[0]->sval);
|
||||
fldtab[0]->sval = buf; /* buf == record */
|
||||
fldtab[0]->tval = REC | STR | DONTFREE;
|
||||
if (is_number(fldtab[0]->sval)) {
|
||||
fldtab[0]->fval = atof(fldtab[0]->sval);
|
||||
fldtab[0]->tval |= NUM;
|
||||
}
|
||||
}
|
||||
setfval(nrloc, nrloc->fval+1);
|
||||
setfval(fnrloc, fnrloc->fval+1);
|
||||
*pbuf = buf;
|
||||
*pbufsize = bufsize;
|
||||
return 1;
|
||||
}
|
||||
/* EOF arrived on this file; set up next */
|
||||
if (infile != stdin)
|
||||
fclose(infile);
|
||||
infile = NULL;
|
||||
argno++;
|
||||
}
|
||||
buf[0] = saveb0;
|
||||
*pbuf = buf;
|
||||
*pbufsize = savebufsize;
|
||||
return 0; /* true end of file */
|
||||
}
|
||||
|
||||
void nextfile(void)
|
||||
{
|
||||
if (infile != NULL && infile != stdin)
|
||||
fclose(infile);
|
||||
infile = NULL;
|
||||
argno++;
|
||||
}
|
||||
|
||||
int readrec(uschar **pbuf, int *pbufsize, FILE *inf) /* read one record into buf */
|
||||
{
|
||||
int sep, c;
|
||||
uschar *rr, *buf = *pbuf;
|
||||
int bufsize = *pbufsize;
|
||||
size_t len;
|
||||
|
||||
if ((len = strlen(*FS)) <= len_inputFS) {
|
||||
strcpy(inputFS, *FS); /* for subsequent field splitting */
|
||||
} else {
|
||||
if (inputFS != static_inputFS)
|
||||
free(inputFS);
|
||||
inputFS = malloc(len + 1);
|
||||
if (inputFS == NULL)
|
||||
FATAL("field separator %.10s... is too long", *FS);
|
||||
len_inputFS = len;
|
||||
memcpy(inputFS, *FS, len + 1);
|
||||
}
|
||||
if ((sep = **RS) == 0) {
|
||||
sep = '\n';
|
||||
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */
|
||||
;
|
||||
if (c != EOF)
|
||||
ungetc(c, inf);
|
||||
} else if ((*RS)[1]) {
|
||||
fa *pfa = makedfa(*RS, 1);
|
||||
int tempstat = pfa->initstat;
|
||||
char *brr = buf;
|
||||
char *rrr = NULL;
|
||||
int x;
|
||||
for (rr = buf; ; ) {
|
||||
while ((c = getc(inf)) != EOF) {
|
||||
if (rr-buf+3 > bufsize)
|
||||
if (!adjbuf(&buf, &bufsize, 3+rr-buf,
|
||||
recsize, &rr, "readrec 2"))
|
||||
FATAL("input record `%.30s...'"
|
||||
" too long", buf);
|
||||
*rr++ = c;
|
||||
*rr = '\0';
|
||||
if (!(x = nematch(pfa, brr))) {
|
||||
pfa->initstat = tempstat;
|
||||
if (rrr) {
|
||||
rr = rrr;
|
||||
ungetc(c, inf);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
pfa->initstat = 2;
|
||||
brr = rrr = rr = patbeg;
|
||||
}
|
||||
}
|
||||
if (rrr || c == EOF)
|
||||
break;
|
||||
if ((c = getc(inf)) == '\n' || c == EOF)
|
||||
/* 2 in a row */
|
||||
break;
|
||||
*rr++ = '\n';
|
||||
*rr++ = c;
|
||||
}
|
||||
} else {
|
||||
for (rr = buf; ; ) {
|
||||
for (; (c=getc(inf)) != sep && c != EOF; ) {
|
||||
if (rr-buf+1 > bufsize)
|
||||
if (!adjbuf(&buf, &bufsize, 1+rr-buf,
|
||||
recsize, &rr, "readrec 1"))
|
||||
FATAL("input record `%.30s...'"
|
||||
" too long", buf);
|
||||
*rr++ = c;
|
||||
}
|
||||
if (**RS == sep || c == EOF)
|
||||
break;
|
||||
if ((c = getc(inf)) == '\n' || c == EOF)
|
||||
/* 2 in a row */
|
||||
break;
|
||||
if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr,
|
||||
"readrec 2"))
|
||||
FATAL("input record `%.30s...' too long", buf);
|
||||
*rr++ = '\n';
|
||||
*rr++ = c;
|
||||
}
|
||||
}
|
||||
if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3"))
|
||||
FATAL("input record `%.30s...' too long", buf);
|
||||
*rr = 0;
|
||||
dprintf( ("readrec saw <%s>, returns %d\n", buf, c == EOF && rr == buf ? 0 : 1) );
|
||||
*pbuf = buf;
|
||||
*pbufsize = bufsize;
|
||||
return c == EOF && rr == buf ? 0 : 1;
|
||||
}
|
||||
|
||||
char *getargv(int n) /* get ARGV[n] */
|
||||
{
|
||||
Cell *x;
|
||||
char *s, temp[50];
|
||||
extern Array *ARGVtab;
|
||||
|
||||
snprintf(temp, sizeof(temp), "%d", n);
|
||||
x = setsymtab(temp, "", 0.0, STR, ARGVtab);
|
||||
s = getsval(x);
|
||||
dprintf( ("getargv(%d) returns |%s|\n", n, s) );
|
||||
return s;
|
||||
}
|
||||
|
||||
void setclvar(char *s) /* set var=value from s */
|
||||
{
|
||||
char *p;
|
||||
Cell *q;
|
||||
|
||||
for (p=s; *p != '='; p++)
|
||||
;
|
||||
*p++ = 0;
|
||||
p = qstring(p, '\0');
|
||||
q = setsymtab(s, p, 0.0, STR, symtab);
|
||||
setsval(q, p);
|
||||
if (is_number(q->sval)) {
|
||||
q->fval = atof(q->sval);
|
||||
q->tval |= NUM;
|
||||
}
|
||||
dprintf( ("command line set %s to |%s|\n", s, p) );
|
||||
}
|
||||
|
||||
|
||||
void fldbld(void) /* create fields from current record */
|
||||
{
|
||||
/* this relies on having fields[] the same length as $0 */
|
||||
/* the fields are all stored in this one array with \0's */
|
||||
char *r, *fr, sep;
|
||||
Cell *p;
|
||||
int i, j, n;
|
||||
|
||||
if (donefld)
|
||||
return;
|
||||
if (!isstr(fldtab[0]))
|
||||
getsval(fldtab[0]);
|
||||
r = fldtab[0]->sval;
|
||||
n = strlen(r);
|
||||
if (n > fieldssize) {
|
||||
xfree(fields);
|
||||
if ((fields = (char *) malloc(n+1)) == NULL)
|
||||
FATAL("out of space for fields in fldbld %d", n);
|
||||
fieldssize = n;
|
||||
}
|
||||
fr = fields;
|
||||
i = 0; /* number of fields accumulated here */
|
||||
if (inputFS[0] && inputFS[1]) { /* it's a regular expression */
|
||||
i = refldbld(r, inputFS);
|
||||
} else if ((sep = *inputFS) == ' ') { /* default whitespace */
|
||||
for (i = 0; ; ) {
|
||||
while (*r == ' ' || *r == '\t' || *r == '\n')
|
||||
r++;
|
||||
if (*r == 0)
|
||||
break;
|
||||
i++;
|
||||
if (i > nfields)
|
||||
growfldtab(i);
|
||||
if (freeable(fldtab[i]))
|
||||
xfree(fldtab[i]->sval);
|
||||
fldtab[i]->sval = fr;
|
||||
fldtab[i]->tval = FLD | STR | DONTFREE;
|
||||
do
|
||||
*fr++ = *r++;
|
||||
while (*r != ' ' && *r != '\t' && *r != '\n' && *r != '\0');
|
||||
*fr++ = 0;
|
||||
}
|
||||
*fr = 0;
|
||||
} else if ((sep = *inputFS) == 0) { /* new: FS="" => 1 char/field */
|
||||
for (i = 0; *r != 0; r++) {
|
||||
char buf[2];
|
||||
i++;
|
||||
if (i > nfields)
|
||||
growfldtab(i);
|
||||
if (freeable(fldtab[i]))
|
||||
xfree(fldtab[i]->sval);
|
||||
buf[0] = *r;
|
||||
buf[1] = 0;
|
||||
fldtab[i]->sval = tostring(buf);
|
||||
fldtab[i]->tval = FLD | STR;
|
||||
}
|
||||
*fr = 0;
|
||||
} else if (*r != 0) { /* if 0, it's a null field */
|
||||
/* subtlecase : if length(FS) == 1 && length(RS > 0)
|
||||
* \n is NOT a field separator (cf awk book 61,84).
|
||||
* this variable is tested in the inner while loop.
|
||||
*/
|
||||
int rtest = '\n'; /* normal case */
|
||||
if (strlen(*RS) > 0)
|
||||
rtest = '\0';
|
||||
for (;;) {
|
||||
i++;
|
||||
if (i > nfields)
|
||||
growfldtab(i);
|
||||
if (freeable(fldtab[i]))
|
||||
xfree(fldtab[i]->sval);
|
||||
fldtab[i]->sval = fr;
|
||||
fldtab[i]->tval = FLD | STR | DONTFREE;
|
||||
while (*r != sep && *r != rtest && *r != '\0') /* \n is always a separator */
|
||||
*fr++ = *r++;
|
||||
*fr++ = 0;
|
||||
if (*r++ == 0)
|
||||
break;
|
||||
}
|
||||
*fr = 0;
|
||||
}
|
||||
if (i > nfields)
|
||||
FATAL("record `%.30s...' has too many fields; can't happen", r);
|
||||
cleanfld(i+1, lastfld); /* clean out junk from previous record */
|
||||
lastfld = i;
|
||||
donefld = 1;
|
||||
for (j = 1; j <= lastfld; j++) {
|
||||
p = fldtab[j];
|
||||
if(is_number(p->sval)) {
|
||||
p->fval = atof(p->sval);
|
||||
p->tval |= NUM;
|
||||
}
|
||||
}
|
||||
setfval(nfloc, (Awkfloat) lastfld);
|
||||
if (dbg) {
|
||||
for (j = 0; j <= lastfld; j++) {
|
||||
p = fldtab[j];
|
||||
printf("field %d (%s): |%s|\n", j, p->nval, p->sval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cleanfld(int n1, int n2) /* clean out fields n1 .. n2 inclusive */
|
||||
{ /* nvals remain intact */
|
||||
Cell *p;
|
||||
int i;
|
||||
|
||||
for (i = n1; i <= n2; i++) {
|
||||
p = fldtab[i];
|
||||
if (freeable(p))
|
||||
xfree(p->sval);
|
||||
p->sval = "";
|
||||
p->tval = FLD | STR | DONTFREE;
|
||||
}
|
||||
}
|
||||
|
||||
void newfld(int n) /* add field n after end of existing lastfld */
|
||||
{
|
||||
if (n > nfields)
|
||||
growfldtab(n);
|
||||
cleanfld(lastfld+1, n);
|
||||
lastfld = n;
|
||||
setfval(nfloc, (Awkfloat) n);
|
||||
}
|
||||
|
||||
Cell *fieldadr(int n) /* get nth field */
|
||||
{
|
||||
if (n < 0)
|
||||
FATAL("trying to access out of range field %d", n);
|
||||
if (n > nfields) /* fields after NF are empty */
|
||||
growfldtab(n); /* but does not increase NF */
|
||||
return(fldtab[n]);
|
||||
}
|
||||
|
||||
void growfldtab(int n) /* make new fields up to at least $n */
|
||||
{
|
||||
int nf = 2 * nfields;
|
||||
size_t s;
|
||||
|
||||
if (n > nf)
|
||||
nf = n;
|
||||
s = (nf+1) * (sizeof (struct Cell *)); /* freebsd: how much do we need? */
|
||||
if (s / sizeof(struct Cell *) - 1 == nf) /* didn't overflow */
|
||||
fldtab = (Cell **) realloc(fldtab, s);
|
||||
else /* overflow sizeof int */
|
||||
xfree(fldtab); /* make it null */
|
||||
if (fldtab == NULL)
|
||||
FATAL("out of space creating %d fields", nf);
|
||||
makefields(nfields+1, nf);
|
||||
nfields = nf;
|
||||
}
|
||||
|
||||
int refldbld(const char *rec, const char *fs) /* build fields from reg expr in FS */
|
||||
{
|
||||
/* this relies on having fields[] the same length as $0 */
|
||||
/* the fields are all stored in this one array with \0's */
|
||||
char *fr;
|
||||
int i, tempstat, n;
|
||||
fa *pfa;
|
||||
|
||||
n = strlen(rec);
|
||||
if (n > fieldssize) {
|
||||
xfree(fields);
|
||||
if ((fields = (char *) malloc(n+1)) == NULL)
|
||||
FATAL("out of space for fields in refldbld %d", n);
|
||||
fieldssize = n;
|
||||
}
|
||||
fr = fields;
|
||||
*fr = '\0';
|
||||
if (*rec == '\0')
|
||||
return 0;
|
||||
pfa = makedfa(fs, 1);
|
||||
dprintf( ("into refldbld, rec = <%s>, pat = <%s>\n", rec, fs) );
|
||||
tempstat = pfa->initstat;
|
||||
for (i = 1; ; i++) {
|
||||
if (i > nfields)
|
||||
growfldtab(i);
|
||||
if (freeable(fldtab[i]))
|
||||
xfree(fldtab[i]->sval);
|
||||
fldtab[i]->tval = FLD | STR | DONTFREE;
|
||||
fldtab[i]->sval = fr;
|
||||
dprintf( ("refldbld: i=%d\n", i) );
|
||||
if (nematch(pfa, rec)) {
|
||||
pfa->initstat = 2; /* horrible coupling to b.c */
|
||||
dprintf( ("match %s (%d chars)\n", patbeg, patlen) );
|
||||
strncpy(fr, rec, ((char*)patbeg)-rec);
|
||||
fr += ((char*)patbeg) - rec + 1;
|
||||
*(fr-1) = '\0';
|
||||
rec = patbeg + patlen;
|
||||
} else {
|
||||
dprintf( ("no match %s\n", rec) );
|
||||
strcpy(fr, rec);
|
||||
pfa->initstat = tempstat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void recbld(void) /* create $0 from $1..$NF if necessary */
|
||||
{
|
||||
int i;
|
||||
uschar *r;
|
||||
char *p;
|
||||
|
||||
if (donerec == 1)
|
||||
return;
|
||||
r = record;
|
||||
for (i = 1; i <= *NF; i++) {
|
||||
p = getsval(fldtab[i]);
|
||||
if (!adjbuf(&record, &recsize, 1+strlen(p)+r-record, recsize, &r, "recbld 1"))
|
||||
FATAL("created $0 `%.30s...' too long", record);
|
||||
while ((*r = *p++) != 0)
|
||||
r++;
|
||||
if (i < *NF) {
|
||||
if (!adjbuf(&record, &recsize, 2+strlen(*OFS)+r-record, recsize, &r, "recbld 2"))
|
||||
FATAL("created $0 `%.30s...' too long", record);
|
||||
for (p = *OFS; (*r = *p++) != 0; )
|
||||
r++;
|
||||
}
|
||||
}
|
||||
if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3"))
|
||||
FATAL("built giant record `%.30s...'", record);
|
||||
*r = '\0';
|
||||
dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
|
||||
|
||||
if (freeable(fldtab[0]))
|
||||
xfree(fldtab[0]->sval);
|
||||
fldtab[0]->tval = REC | STR | DONTFREE;
|
||||
fldtab[0]->sval = record;
|
||||
|
||||
dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
|
||||
dprintf( ("recbld = |%s|\n", record) );
|
||||
donerec = 1;
|
||||
}
|
||||
|
||||
int errorflag = 0;
|
||||
|
||||
void yyerror(const char *s)
|
||||
{
|
||||
SYNTAX("%s", s);
|
||||
}
|
||||
|
||||
void SYNTAX(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname, *curfname;
|
||||
static int been_here = 0;
|
||||
va_list varg;
|
||||
|
||||
if (been_here++ > 2)
|
||||
return;
|
||||
fprintf(stderr, "%s: ", cmdname);
|
||||
va_start(varg, fmt);
|
||||
vfprintf(stderr, fmt, varg);
|
||||
va_end(varg);
|
||||
fprintf(stderr, " at source line %d", lineno);
|
||||
if (curfname != NULL)
|
||||
fprintf(stderr, " in function %s", curfname);
|
||||
if (compile_time == 1 && cursource() != NULL)
|
||||
fprintf(stderr, " source file %s", cursource());
|
||||
fprintf(stderr, "\n");
|
||||
errorflag = 2;
|
||||
eprint();
|
||||
}
|
||||
|
||||
extern int bracecnt, brackcnt, parencnt;
|
||||
|
||||
void bracecheck(void)
|
||||
{
|
||||
int c;
|
||||
static int beenhere = 0;
|
||||
|
||||
if (beenhere++)
|
||||
return;
|
||||
while ((c = input()) != EOF && c != '\0')
|
||||
bclass(c);
|
||||
bcheck2(bracecnt, '{', '}');
|
||||
bcheck2(brackcnt, '[', ']');
|
||||
bcheck2(parencnt, '(', ')');
|
||||
}
|
||||
|
||||
void bcheck2(int n, int c1, int c2)
|
||||
{
|
||||
if (n == 1)
|
||||
fprintf(stderr, "\tmissing %c\n", c2);
|
||||
else if (n > 1)
|
||||
fprintf(stderr, "\t%d missing %c's\n", n, c2);
|
||||
else if (n == -1)
|
||||
fprintf(stderr, "\textra %c\n", c2);
|
||||
else if (n < -1)
|
||||
fprintf(stderr, "\t%d extra %c's\n", -n, c2);
|
||||
}
|
||||
|
||||
void FATAL(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname;
|
||||
va_list varg;
|
||||
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: ", cmdname);
|
||||
va_start(varg, fmt);
|
||||
vfprintf(stderr, fmt, varg);
|
||||
va_end(varg);
|
||||
error();
|
||||
if (dbg > 1) /* core dump if serious debugging on */
|
||||
abort();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
void WARNING(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname;
|
||||
va_list varg;
|
||||
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: ", cmdname);
|
||||
va_start(varg, fmt);
|
||||
vfprintf(stderr, fmt, varg);
|
||||
va_end(varg);
|
||||
error();
|
||||
}
|
||||
|
||||
void error()
|
||||
{
|
||||
extern Node *curnode;
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
if (compile_time != 2 && NR && *NR > 0) {
|
||||
fprintf(stderr, " input record number %d", (int) (*FNR));
|
||||
if (strcmp(*FILENAME, "-") != 0)
|
||||
fprintf(stderr, ", file %s", *FILENAME);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (compile_time != 2 && curnode)
|
||||
fprintf(stderr, " source line number %d", curnode->lineno);
|
||||
else if (compile_time != 2 && lineno)
|
||||
fprintf(stderr, " source line number %d", lineno);
|
||||
if (compile_time == 1 && cursource() != NULL)
|
||||
fprintf(stderr, " source file %s", cursource());
|
||||
fprintf(stderr, "\n");
|
||||
eprint();
|
||||
}
|
||||
|
||||
void eprint(void) /* try to print context around error */
|
||||
{
|
||||
char *p, *q;
|
||||
static int been_here = 0;
|
||||
extern char ebuf[], *ep;
|
||||
|
||||
if (compile_time == 2 || compile_time == 0 || been_here++ > 0)
|
||||
return;
|
||||
p = ep - 1;
|
||||
if (p > ebuf && *p == '\n')
|
||||
p--;
|
||||
for ( ; p > ebuf && *p != '\n' && *p != '\0'; p--)
|
||||
;
|
||||
while (*p == '\n')
|
||||
p++;
|
||||
fprintf(stderr, " context is\n\t");
|
||||
for (q=ep-1; q>=p && *q!=' ' && *q!='\t' && *q!='\n'; q--)
|
||||
;
|
||||
for ( ; p < q; p++)
|
||||
if (*p)
|
||||
putc(*p, stderr);
|
||||
fprintf(stderr, " >>> ");
|
||||
for ( ; p < ep; p++)
|
||||
if (*p)
|
||||
putc(*p, stderr);
|
||||
fprintf(stderr, " <<< ");
|
||||
#if 0
|
||||
/*
|
||||
* The following code was used to print the rest of the line of
|
||||
* error context. It naively counts brackets, parens and braces in
|
||||
* order to minimize the parsing effect of dropping the rest of the
|
||||
* line but it does not work in all the cases. It is too much work
|
||||
* to save the current program input point and restore it in all the
|
||||
* cases just for the benefit of error printing so for now this
|
||||
* code is disabled. In particular this code is confused if the
|
||||
* [ { ( ) } ] is inside a quoted string or a pattern.
|
||||
*/
|
||||
if (*ep) {
|
||||
int c;
|
||||
while ((c = input()) != '\n' && c != '\0' && c != EOF) {
|
||||
putc(c, stderr);
|
||||
bclass(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
putc('\n', stderr);
|
||||
ep = ebuf;
|
||||
}
|
||||
|
||||
void bclass(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case '{': bracecnt++; break;
|
||||
case '}': bracecnt--; break;
|
||||
case '[': brackcnt++; break;
|
||||
case ']': brackcnt--; break;
|
||||
case '(': parencnt++; break;
|
||||
case ')': parencnt--; break;
|
||||
}
|
||||
}
|
||||
|
||||
double errcheck(double x, const char *s)
|
||||
{
|
||||
|
||||
if (errno == EDOM) {
|
||||
errno = 0;
|
||||
WARNING("%s argument out of domain", s);
|
||||
x = 1;
|
||||
} else if (errno == ERANGE) {
|
||||
errno = 0;
|
||||
WARNING("%s result out of range", s);
|
||||
x = 1;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int isclvar(const char *s) /* is s of form var=something ? */
|
||||
{
|
||||
const char *os = s;
|
||||
|
||||
if (!isalpha((uschar) *s) && *s != '_')
|
||||
return 0;
|
||||
for ( ; *s; s++)
|
||||
if (!(isalnum((uschar) *s) || *s == '_'))
|
||||
break;
|
||||
return *s == '=' && s > os && *(s+1) != '=';
|
||||
}
|
||||
|
||||
/* strtod is supposed to be a proper test of what's a valid number */
|
||||
/* appears to be broken in gcc on linux: thinks 0x123 is a valid FP number */
|
||||
/* wrong: violates 4.10.1.4 of ansi C standard */
|
||||
|
||||
#include <math.h>
|
||||
int is_number(const char *s)
|
||||
{
|
||||
double r;
|
||||
char *ep;
|
||||
errno = 0;
|
||||
r = strtod(s, &ep);
|
||||
if (ep == s || errno == ERANGE)
|
||||
return 0;
|
||||
if (ep - s >= 3 && strncasecmp(ep - 3, "nan", 3) == 0)
|
||||
return 0;
|
||||
while (*ep == ' ' || *ep == '\t' || *ep == '\n')
|
||||
ep++;
|
||||
if (*ep == '\0')
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
|
@ -1,243 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
const char *version = "version 20070501";
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
extern char **environ;
|
||||
extern int nfields;
|
||||
|
||||
int dbg = 0;
|
||||
char *cmdname; /* gets argv[0] for error messages */
|
||||
extern FILE *yyin; /* lex input file */
|
||||
char *lexprog; /* points to program argument if it exists */
|
||||
extern int errorflag; /* non-zero if any syntax errors; set by yyerror */
|
||||
int compile_time = 2; /* for error printing: */
|
||||
/* 2 = cmdline, 1 = compile, 0 = running */
|
||||
|
||||
#define MAX_PFILE 20 /* max number of -f's */
|
||||
|
||||
char *pfile[MAX_PFILE]; /* program filenames from -f's */
|
||||
int npfile = 0; /* number of filenames */
|
||||
int curpfile = 0; /* current filename */
|
||||
|
||||
int safe = 0; /* 1 => "safe" mode */
|
||||
|
||||
static char *
|
||||
setfs(char *p)
|
||||
{
|
||||
#ifdef notdef
|
||||
/* wart: t=>\t */
|
||||
if (p[0] == 't' && p[1] == 0)
|
||||
return "\t";
|
||||
else
|
||||
#endif
|
||||
if (p[0] != 0)
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void fpecatch(int n
|
||||
#ifdef SA_SIGINFO
|
||||
, siginfo_t *si, void *uc
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef SA_SIGINFO
|
||||
static const char *emsg[] = {
|
||||
"Unknown error",
|
||||
"Integer divide by zero",
|
||||
"Integer overflow",
|
||||
"Floating point divide by zero",
|
||||
"Floating point overflow",
|
||||
"Floating point underflow",
|
||||
"Floating point inexact result",
|
||||
"Invalid Floating point operation",
|
||||
"Subscript out of range",
|
||||
};
|
||||
#endif
|
||||
FATAL("floating point exception"
|
||||
#ifdef SA_SIGINFO
|
||||
": %s\n", emsg[si->si_code >= 1 && si->si_code <= 8 ?
|
||||
si->si_code : 0]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *fs = NULL;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
|
||||
cmdname = argv[0];
|
||||
if (argc == 1) {
|
||||
fprintf(stderr,
|
||||
"usage: %s [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]\n",
|
||||
cmdname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef SA_SIGINFO
|
||||
{
|
||||
struct sigaction sa;
|
||||
sa.sa_sigaction = fpecatch;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
(void)sigaction(SIGFPE, &sa, NULL);
|
||||
}
|
||||
#else
|
||||
(void)signal(SIGFPE, fpecatch);
|
||||
#endif
|
||||
yyin = NULL;
|
||||
symtab = makesymtab(NSYMTAB/NSYMTAB);
|
||||
while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
|
||||
if (strcmp(argv[1],"-version") == 0 || strcmp(argv[1],"--version") == 0) {
|
||||
printf("awk %s\n", version);
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
if (strncmp(argv[1], "--", 2) == 0) { /* explicit end of args */
|
||||
argc--;
|
||||
argv++;
|
||||
break;
|
||||
}
|
||||
switch (argv[1][1]) {
|
||||
case 's':
|
||||
if (strcmp(argv[1], "-safe") == 0)
|
||||
safe = 1;
|
||||
break;
|
||||
case 'f': /* next argument is program filename */
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc <= 1)
|
||||
FATAL("no program filename");
|
||||
if (npfile >= MAX_PFILE - 1)
|
||||
FATAL("too many -f options");
|
||||
pfile[npfile++] = argv[1];
|
||||
break;
|
||||
case 'F': /* set field separator */
|
||||
if (argv[1][2] != 0) { /* arg is -Fsomething */
|
||||
fs = setfs(argv[1] + 2);
|
||||
} else { /* arg is -F something */
|
||||
argc--; argv++;
|
||||
if (argc > 1)
|
||||
fs = setfs(argv[1]);
|
||||
}
|
||||
if (fs == NULL || *fs == '\0')
|
||||
WARNING("field separator FS is empty");
|
||||
break;
|
||||
case 'v': /* -v a=1 to be done NOW. one -v for each */
|
||||
if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1]))
|
||||
setclvar(argv[1]);
|
||||
break;
|
||||
case 'd':
|
||||
dbg = atoi(&argv[1][2]);
|
||||
if (dbg == 0)
|
||||
dbg = 1;
|
||||
printf("awk %s\n", version);
|
||||
break;
|
||||
default:
|
||||
WARNING("unknown option %s ignored", argv[1]);
|
||||
break;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
/* argv[1] is now the first argument */
|
||||
if (npfile == 0) { /* no -f; first argument is program */
|
||||
if (argc <= 1) {
|
||||
if (dbg)
|
||||
exit(0);
|
||||
FATAL("no program given");
|
||||
}
|
||||
dprintf( ("program = |%s|\n", argv[1]) );
|
||||
lexprog = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
recinit(recsize);
|
||||
syminit();
|
||||
compile_time = 1;
|
||||
argv[0] = cmdname; /* put prog name at front of arglist */
|
||||
dprintf( ("argc=%d, argv[0]=%s\n", argc, argv[0]) );
|
||||
arginit(argc, argv);
|
||||
if (!safe)
|
||||
envinit(environ);
|
||||
yyparse();
|
||||
setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
|
||||
if (fs)
|
||||
*FS = qstring(fs, '\0');
|
||||
dprintf( ("errorflag=%d\n", errorflag) );
|
||||
if (errorflag == 0) {
|
||||
compile_time = 0;
|
||||
run(winner);
|
||||
} else
|
||||
bracecheck();
|
||||
return(errorflag);
|
||||
}
|
||||
|
||||
int pgetc(void) /* get 1 character from awk program */
|
||||
{
|
||||
int c;
|
||||
|
||||
for (;;) {
|
||||
if (yyin == NULL) {
|
||||
if (curpfile >= npfile)
|
||||
return EOF;
|
||||
if (strcmp(pfile[curpfile], "-") == 0)
|
||||
yyin = stdin;
|
||||
else if ((yyin = fopen(pfile[curpfile], "r")) == NULL)
|
||||
FATAL("can't open file %s", pfile[curpfile]);
|
||||
lineno = 1;
|
||||
}
|
||||
if ((c = getc(yyin)) != EOF)
|
||||
return c;
|
||||
if (yyin != stdin)
|
||||
fclose(yyin);
|
||||
yyin = NULL;
|
||||
curpfile++;
|
||||
}
|
||||
}
|
||||
|
||||
char *cursource(void) /* current source file name */
|
||||
{
|
||||
if (npfile > 0)
|
||||
return pfile[curpfile];
|
||||
else
|
||||
return NULL;
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
# /****************************************************************
|
||||
# Copyright (C) Lucent Technologies 1997
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby
|
||||
# granted, provided that the above copyright notice appear in all
|
||||
# copies and that both that the copyright notice and this
|
||||
# permission notice and warranty disclaimer appear in supporting
|
||||
# documentation, and that the name Lucent Technologies or any of
|
||||
# its entities not be used in advertising or publicity pertaining
|
||||
# to distribution of the software without specific, written prior
|
||||
# permission.
|
||||
#
|
||||
# LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
# IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
# THIS SOFTWARE.
|
||||
# ****************************************************************/
|
||||
|
||||
CFLAGS = -g
|
||||
CFLAGS = -O2
|
||||
CFLAGS =
|
||||
|
||||
CC = gcc -Wall -g -Wwrite-strings
|
||||
CC = gcc -fprofile-arcs -ftest-coverage # then gcov f1.c; cat f1.c.gcov
|
||||
CC = gcc -Wall -g
|
||||
CC = /opt/SUNWspro/bin/cc
|
||||
CC = /opt/pure/purify/purify cc
|
||||
CC = cc
|
||||
CC = gcc -O4
|
||||
CC = gcc -Wall -g
|
||||
|
||||
|
||||
YACC = bison -y
|
||||
YACC = yacc
|
||||
YFLAGS = -d
|
||||
|
||||
OFILES = b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o
|
||||
|
||||
SOURCE = awk.h ytab.c ytab.h proto.h awkgram.y lex.c b.c main.c \
|
||||
maketab.c parse.c lib.c run.c tran.c proctab.c missing95.c
|
||||
|
||||
LISTING = awk.h proto.h awkgram.y lex.c b.c main.c maketab.c parse.c \
|
||||
lib.c run.c tran.c missing95.c
|
||||
|
||||
SHIP = README FIXES $(SOURCE) ytab[ch].bak makefile makefile.win \
|
||||
vcvars32.bat buildwin.bat awk.1
|
||||
|
||||
a.out: ytab.o $(OFILES)
|
||||
$(CC) $(CFLAGS) ytab.o $(OFILES) $(ALLOC) -lm
|
||||
|
||||
$(OFILES): awk.h ytab.h proto.h
|
||||
|
||||
ytab.o: awk.h proto.h awkgram.y
|
||||
$(YACC) $(YFLAGS) awkgram.y
|
||||
mv y.tab.c ytab.c
|
||||
mv y.tab.h ytab.h
|
||||
$(CC) $(CFLAGS) -c ytab.c
|
||||
|
||||
proctab.c: maketab
|
||||
./maketab >proctab.c
|
||||
|
||||
maketab: ytab.h maketab.c
|
||||
$(CC) $(CFLAGS) maketab.c -o maketab
|
||||
|
||||
bundle:
|
||||
@cp ytab.h ytabh.bak
|
||||
@cp ytab.c ytabc.bak
|
||||
@bundle $(SHIP)
|
||||
|
||||
tar:
|
||||
@cp ytab.h ytabh.bak
|
||||
@cp ytab.c ytabc.bak
|
||||
@bundle $(SHIP) >awk.shar
|
||||
@tar cf awk.tar $(SHIP)
|
||||
gzip awk.tar
|
||||
ls -l awk.tar.gz
|
||||
@zip awk.zip $(SHIP)
|
||||
ls -l awk.zip
|
||||
|
||||
names:
|
||||
@echo $(LISTING)
|
||||
|
||||
clean:
|
||||
rm -f a.out *.o *.obj maketab maketab.exe ytab.[ch] *.bb *.bbg *.da *.gcov *.gcno *.gcda # proctab.c
|
|
@ -1,176 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
/*
|
||||
* this program makes the table to link function names
|
||||
* and type indices that is used by execute() in run.c.
|
||||
* it finds the indices in ytab.h, produced by yacc.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
struct xx
|
||||
{ int token;
|
||||
const char *name;
|
||||
const char *pname;
|
||||
} proc[] = {
|
||||
{ PROGRAM, "program", NULL },
|
||||
{ BOR, "boolop", " || " },
|
||||
{ AND, "boolop", " && " },
|
||||
{ NOT, "boolop", " !" },
|
||||
{ NE, "relop", " != " },
|
||||
{ EQ, "relop", " == " },
|
||||
{ LE, "relop", " <= " },
|
||||
{ LT, "relop", " < " },
|
||||
{ GE, "relop", " >= " },
|
||||
{ GT, "relop", " > " },
|
||||
{ ARRAY, "array", NULL },
|
||||
{ INDIRECT, "indirect", "$(" },
|
||||
{ SUBSTR, "substr", "substr" },
|
||||
{ SUB, "sub", "sub" },
|
||||
{ GSUB, "gsub", "gsub" },
|
||||
{ INDEX, "sindex", "sindex" },
|
||||
{ SPRINTF, "awksprintf", "sprintf " },
|
||||
{ ADD, "arith", " + " },
|
||||
{ MINUS, "arith", " - " },
|
||||
{ MULT, "arith", " * " },
|
||||
{ DIVIDE, "arith", " / " },
|
||||
{ MOD, "arith", " % " },
|
||||
{ UMINUS, "arith", " -" },
|
||||
{ POWER, "arith", " **" },
|
||||
{ PREINCR, "incrdecr", "++" },
|
||||
{ POSTINCR, "incrdecr", "++" },
|
||||
{ PREDECR, "incrdecr", "--" },
|
||||
{ POSTDECR, "incrdecr", "--" },
|
||||
{ CAT, "cat", " " },
|
||||
{ PASTAT, "pastat", NULL },
|
||||
{ PASTAT2, "dopa2", NULL },
|
||||
{ MATCH, "matchop", " ~ " },
|
||||
{ NOTMATCH, "matchop", " !~ " },
|
||||
{ MATCHFCN, "matchop", "matchop" },
|
||||
{ INTEST, "intest", "intest" },
|
||||
{ PRINTF, "awkprintf", "printf" },
|
||||
{ PRINT, "printstat", "print" },
|
||||
{ CLOSE, "closefile", "closefile" },
|
||||
{ DELETE, "awkdelete", "awkdelete" },
|
||||
{ SPLIT, "split", "split" },
|
||||
{ ASSIGN, "assign", " = " },
|
||||
{ ADDEQ, "assign", " += " },
|
||||
{ SUBEQ, "assign", " -= " },
|
||||
{ MULTEQ, "assign", " *= " },
|
||||
{ DIVEQ, "assign", " /= " },
|
||||
{ MODEQ, "assign", " %= " },
|
||||
{ POWEQ, "assign", " ^= " },
|
||||
{ CONDEXPR, "condexpr", " ?: " },
|
||||
{ IF, "ifstat", "if(" },
|
||||
{ WHILE, "whilestat", "while(" },
|
||||
{ FOR, "forstat", "for(" },
|
||||
{ DO, "dostat", "do" },
|
||||
{ IN, "instat", "instat" },
|
||||
{ NEXT, "jump", "next" },
|
||||
{ NEXTFILE, "jump", "nextfile" },
|
||||
{ EXIT, "jump", "exit" },
|
||||
{ BREAK, "jump", "break" },
|
||||
{ CONTINUE, "jump", "continue" },
|
||||
{ RETURN, "jump", "ret" },
|
||||
{ BLTIN, "bltin", "bltin" },
|
||||
{ CALL, "call", "call" },
|
||||
{ ARG, "arg", "arg" },
|
||||
{ VARNF, "getnf", "NF" },
|
||||
{ GETLINE, "get_line", "getline" },
|
||||
{ GENSUB, "gensub", "gensub" },
|
||||
{ 0, "", "" },
|
||||
};
|
||||
|
||||
#define SIZE (LASTTOKEN - FIRSTTOKEN + 1)
|
||||
const char *table[SIZE];
|
||||
char *names[SIZE];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const struct xx *p;
|
||||
int i, n, tok;
|
||||
char c;
|
||||
FILE *fp;
|
||||
char buf[200], name[200], def[200];
|
||||
|
||||
printf("#include <stdio.h>\n");
|
||||
printf("#include \"awk.h\"\n");
|
||||
printf("#include \"awkgram.h\"\n\n");
|
||||
for (i = SIZE; --i >= 0; )
|
||||
names[i] = "";
|
||||
|
||||
if ((fp = fopen("awkgram.h", "r")) == NULL) {
|
||||
fprintf(stderr, "maketab can't open awkgram.h!\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("static const char * const printname[%d] = {\n", SIZE);
|
||||
i = 0;
|
||||
while (fgets(buf, sizeof buf, fp) != NULL) {
|
||||
n = sscanf(buf, "%1c %199s %199s %d", &c, def, name, &tok);
|
||||
if (c != '#' || (n != 4 && strcmp(def,"define") != 0)) /* not a valid #define */
|
||||
continue;
|
||||
if (tok < FIRSTTOKEN || tok > LASTTOKEN) {
|
||||
/* fprintf(stderr, "maketab funny token %d %s ignored\n", tok, buf); */
|
||||
continue;
|
||||
}
|
||||
names[tok-FIRSTTOKEN] = strdup(name);
|
||||
if (names[tok-FIRSTTOKEN] == NULL) {
|
||||
fprintf(stderr, "maketab out of space copying %s", name);
|
||||
continue;
|
||||
}
|
||||
printf("\t\"%s\",\t/* %d */\n", name, tok);
|
||||
i++;
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
for (p=proc; p->token!=0; p++)
|
||||
table[p->token-FIRSTTOKEN] = p->name;
|
||||
printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE);
|
||||
for (i=0; i<SIZE; i++)
|
||||
if (table[i]==0)
|
||||
printf("\tnullproc,\t/* %s */\n", names[i]);
|
||||
else
|
||||
printf("\t%s,\t/* %s */\n", table[i], names[i]);
|
||||
printf("};\n\n");
|
||||
|
||||
printf("const char *tokname(int n)\n"); /* print a tokname() function */
|
||||
printf("{\n");
|
||||
printf(" static char buf[100];\n\n");
|
||||
printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n");
|
||||
printf(" snprintf(buf, sizeof(buf), \"token %%d\", n);\n");
|
||||
printf(" return buf;\n");
|
||||
printf(" }\n");
|
||||
printf(" return printname[n-FIRSTTOKEN];\n");
|
||||
printf("}\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,303 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
Node *nodealloc(int n)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = (Node *) malloc(sizeof(Node) + (n-1)*sizeof(Node *));
|
||||
if (x == NULL)
|
||||
FATAL("out of space in nodealloc");
|
||||
x->nnext = NULL;
|
||||
x->lineno = lineno;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *exptostat(Node *a)
|
||||
{
|
||||
a->ntype = NSTAT;
|
||||
return(a);
|
||||
}
|
||||
|
||||
Node *node1(int a, Node *b)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = nodealloc(1);
|
||||
x->nobj = a;
|
||||
x->narg[0]=b;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *node2(int a, Node *b, Node *c)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = nodealloc(2);
|
||||
x->nobj = a;
|
||||
x->narg[0] = b;
|
||||
x->narg[1] = c;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *node3(int a, Node *b, Node *c, Node *d)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = nodealloc(3);
|
||||
x->nobj = a;
|
||||
x->narg[0] = b;
|
||||
x->narg[1] = c;
|
||||
x->narg[2] = d;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *node4(int a, Node *b, Node *c, Node *d, Node *e)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = nodealloc(4);
|
||||
x->nobj = a;
|
||||
x->narg[0] = b;
|
||||
x->narg[1] = c;
|
||||
x->narg[2] = d;
|
||||
x->narg[3] = e;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *node5(int a, Node *b, Node *c, Node *d, Node *e, Node *f)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = nodealloc(5);
|
||||
x->nobj = a;
|
||||
x->narg[0] = b;
|
||||
x->narg[1] = c;
|
||||
x->narg[2] = d;
|
||||
x->narg[3] = e;
|
||||
x->narg[4] = f;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *stat1(int a, Node *b)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node1(a,b);
|
||||
x->ntype = NSTAT;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *stat2(int a, Node *b, Node *c)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node2(a,b,c);
|
||||
x->ntype = NSTAT;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *stat3(int a, Node *b, Node *c, Node *d)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node3(a,b,c,d);
|
||||
x->ntype = NSTAT;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *stat4(int a, Node *b, Node *c, Node *d, Node *e)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node4(a,b,c,d,e);
|
||||
x->ntype = NSTAT;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *op1(int a, Node *b)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node1(a,b);
|
||||
x->ntype = NEXPR;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *op2(int a, Node *b, Node *c)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node2(a,b,c);
|
||||
x->ntype = NEXPR;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *op3(int a, Node *b, Node *c, Node *d)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node3(a,b,c,d);
|
||||
x->ntype = NEXPR;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *op4(int a, Node *b, Node *c, Node *d, Node *e)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node4(a,b,c,d,e);
|
||||
x->ntype = NEXPR;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *op5(int a, Node *b, Node *c, Node *d, Node *e, Node *f)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node5(a,b,c,d,e, f);
|
||||
x->ntype = NEXPR;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *celltonode(Cell *a, int b)
|
||||
{
|
||||
Node *x;
|
||||
|
||||
a->ctype = OCELL;
|
||||
a->csub = b;
|
||||
x = node1(0, (Node *) a);
|
||||
x->ntype = NVALUE;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *rectonode(void) /* make $0 into a Node */
|
||||
{
|
||||
extern Cell *literal0;
|
||||
return op1(INDIRECT, celltonode(literal0, CUNK));
|
||||
}
|
||||
|
||||
Node *makearr(Node *p)
|
||||
{
|
||||
Cell *cp;
|
||||
|
||||
if (isvalue(p)) {
|
||||
cp = (Cell *) (p->narg[0]);
|
||||
if (isfcn(cp))
|
||||
SYNTAX( "%s is a function, not an array", cp->nval );
|
||||
else if (!isarr(cp)) {
|
||||
xfree(cp->sval);
|
||||
cp->sval = (char *) makesymtab(NSYMTAB);
|
||||
cp->tval = ARR;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#define PA2NUM 50 /* max number of pat,pat patterns allowed */
|
||||
int paircnt; /* number of them in use */
|
||||
int pairstack[PA2NUM]; /* state of each pat,pat */
|
||||
|
||||
Node *pa2stat(Node *a, Node *b, Node *c) /* pat, pat {...} */
|
||||
{
|
||||
Node *x;
|
||||
|
||||
x = node4(PASTAT2, a, b, c, itonp(paircnt));
|
||||
if (paircnt++ >= PA2NUM)
|
||||
SYNTAX( "limited to %d pat,pat statements", PA2NUM );
|
||||
x->ntype = NSTAT;
|
||||
return(x);
|
||||
}
|
||||
|
||||
Node *linkum(Node *a, Node *b)
|
||||
{
|
||||
Node *c;
|
||||
|
||||
if (errorflag) /* don't link things that are wrong */
|
||||
return a;
|
||||
if (a == NULL)
|
||||
return(b);
|
||||
else if (b == NULL)
|
||||
return(a);
|
||||
for (c = a; c->nnext != NULL; c = c->nnext)
|
||||
;
|
||||
c->nnext = b;
|
||||
return(a);
|
||||
}
|
||||
|
||||
void defn(Cell *v, Node *vl, Node *st) /* turn on FCN bit in definition, */
|
||||
{ /* body of function, arglist */
|
||||
Node *p;
|
||||
int n;
|
||||
|
||||
if (isarr(v)) {
|
||||
SYNTAX( "`%s' is an array name and a function name", v->nval );
|
||||
return;
|
||||
}
|
||||
if (isarg(v->nval) != -1) {
|
||||
SYNTAX( "`%s' is both function name and argument name", v->nval );
|
||||
return;
|
||||
}
|
||||
|
||||
v->tval = FCN;
|
||||
v->sval = (char *) st;
|
||||
n = 0; /* count arguments */
|
||||
for (p = vl; p; p = p->nnext)
|
||||
n++;
|
||||
v->fval = n;
|
||||
dprintf( ("defining func %s (%d args)\n", v->nval, n) );
|
||||
}
|
||||
|
||||
int isarg(const char *s) /* is s in argument list for current function? */
|
||||
{ /* return -1 if not, otherwise arg # */
|
||||
extern Node *arglist;
|
||||
Node *p = arglist;
|
||||
int n;
|
||||
|
||||
for (n = 0; p != 0; p = p->nnext, n++)
|
||||
if (strcmp(((Cell *)(p->narg[0]))->nval, s) == 0)
|
||||
return n;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ptoi(void *p) /* convert pointer to integer */
|
||||
{
|
||||
return (int) (long) p; /* swearing that p fits, of course */
|
||||
}
|
||||
|
||||
Node *itonp(int i) /* and vice versa */
|
||||
{
|
||||
return (Node *) (long) i;
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
static const char * const printname[94] = {
|
||||
"FIRSTTOKEN", /* 257 */
|
||||
"PROGRAM", /* 258 */
|
||||
"PASTAT", /* 259 */
|
||||
"PASTAT2", /* 260 */
|
||||
"XBEGIN", /* 261 */
|
||||
"XEND", /* 262 */
|
||||
"NL", /* 263 */
|
||||
"ARRAY", /* 264 */
|
||||
"MATCH", /* 265 */
|
||||
"NOTMATCH", /* 266 */
|
||||
"MATCHOP", /* 267 */
|
||||
"FINAL", /* 268 */
|
||||
"DOT", /* 269 */
|
||||
"ALL", /* 270 */
|
||||
"CCL", /* 271 */
|
||||
"NCCL", /* 272 */
|
||||
"CHAR", /* 273 */
|
||||
"OR", /* 274 */
|
||||
"STAR", /* 275 */
|
||||
"QUEST", /* 276 */
|
||||
"PLUS", /* 277 */
|
||||
"EMPTYRE", /* 278 */
|
||||
"AND", /* 279 */
|
||||
"BOR", /* 280 */
|
||||
"APPEND", /* 281 */
|
||||
"EQ", /* 282 */
|
||||
"GE", /* 283 */
|
||||
"GT", /* 284 */
|
||||
"LE", /* 285 */
|
||||
"LT", /* 286 */
|
||||
"NE", /* 287 */
|
||||
"IN", /* 288 */
|
||||
"ARG", /* 289 */
|
||||
"BLTIN", /* 290 */
|
||||
"BREAK", /* 291 */
|
||||
"CLOSE", /* 292 */
|
||||
"CONTINUE", /* 293 */
|
||||
"DELETE", /* 294 */
|
||||
"DO", /* 295 */
|
||||
"EXIT", /* 296 */
|
||||
"FOR", /* 297 */
|
||||
"FUNC", /* 298 */
|
||||
"SUB", /* 299 */
|
||||
"GSUB", /* 300 */
|
||||
"IF", /* 301 */
|
||||
"INDEX", /* 302 */
|
||||
"LSUBSTR", /* 303 */
|
||||
"MATCHFCN", /* 304 */
|
||||
"NEXT", /* 305 */
|
||||
"NEXTFILE", /* 306 */
|
||||
"ADD", /* 307 */
|
||||
"MINUS", /* 308 */
|
||||
"MULT", /* 309 */
|
||||
"DIVIDE", /* 310 */
|
||||
"MOD", /* 311 */
|
||||
"ASSIGN", /* 312 */
|
||||
"ASGNOP", /* 313 */
|
||||
"ADDEQ", /* 314 */
|
||||
"SUBEQ", /* 315 */
|
||||
"MULTEQ", /* 316 */
|
||||
"DIVEQ", /* 317 */
|
||||
"MODEQ", /* 318 */
|
||||
"POWEQ", /* 319 */
|
||||
"PRINT", /* 320 */
|
||||
"PRINTF", /* 321 */
|
||||
"SPRINTF", /* 322 */
|
||||
"ELSE", /* 323 */
|
||||
"INTEST", /* 324 */
|
||||
"CONDEXPR", /* 325 */
|
||||
"POSTINCR", /* 326 */
|
||||
"PREINCR", /* 327 */
|
||||
"POSTDECR", /* 328 */
|
||||
"PREDECR", /* 329 */
|
||||
"VAR", /* 330 */
|
||||
"IVAR", /* 331 */
|
||||
"VARNF", /* 332 */
|
||||
"CALL", /* 333 */
|
||||
"NUMBER", /* 334 */
|
||||
"STRING", /* 335 */
|
||||
"REGEXPR", /* 336 */
|
||||
"GETLINE", /* 337 */
|
||||
"GENSUB", /* 338 */
|
||||
"RETURN", /* 339 */
|
||||
"SPLIT", /* 340 */
|
||||
"SUBSTR", /* 341 */
|
||||
"WHILE", /* 342 */
|
||||
"CAT", /* 343 */
|
||||
"NOT", /* 344 */
|
||||
"UMINUS", /* 345 */
|
||||
"POWER", /* 346 */
|
||||
"DECR", /* 347 */
|
||||
"INCR", /* 348 */
|
||||
"INDIRECT", /* 349 */
|
||||
"LASTTOKEN", /* 350 */
|
||||
};
|
||||
|
||||
|
||||
Cell *(*proctab[94])(Node **, int) = {
|
||||
nullproc, /* FIRSTTOKEN */
|
||||
program, /* PROGRAM */
|
||||
pastat, /* PASTAT */
|
||||
dopa2, /* PASTAT2 */
|
||||
nullproc, /* XBEGIN */
|
||||
nullproc, /* XEND */
|
||||
nullproc, /* NL */
|
||||
array, /* ARRAY */
|
||||
matchop, /* MATCH */
|
||||
matchop, /* NOTMATCH */
|
||||
nullproc, /* MATCHOP */
|
||||
nullproc, /* FINAL */
|
||||
nullproc, /* DOT */
|
||||
nullproc, /* ALL */
|
||||
nullproc, /* CCL */
|
||||
nullproc, /* NCCL */
|
||||
nullproc, /* CHAR */
|
||||
nullproc, /* OR */
|
||||
nullproc, /* STAR */
|
||||
nullproc, /* QUEST */
|
||||
nullproc, /* PLUS */
|
||||
nullproc, /* EMPTYRE */
|
||||
boolop, /* AND */
|
||||
boolop, /* BOR */
|
||||
nullproc, /* APPEND */
|
||||
relop, /* EQ */
|
||||
relop, /* GE */
|
||||
relop, /* GT */
|
||||
relop, /* LE */
|
||||
relop, /* LT */
|
||||
relop, /* NE */
|
||||
instat, /* IN */
|
||||
arg, /* ARG */
|
||||
bltin, /* BLTIN */
|
||||
jump, /* BREAK */
|
||||
closefile, /* CLOSE */
|
||||
jump, /* CONTINUE */
|
||||
awkdelete, /* DELETE */
|
||||
dostat, /* DO */
|
||||
jump, /* EXIT */
|
||||
forstat, /* FOR */
|
||||
nullproc, /* FUNC */
|
||||
sub, /* SUB */
|
||||
gsub, /* GSUB */
|
||||
ifstat, /* IF */
|
||||
sindex, /* INDEX */
|
||||
nullproc, /* LSUBSTR */
|
||||
matchop, /* MATCHFCN */
|
||||
jump, /* NEXT */
|
||||
jump, /* NEXTFILE */
|
||||
arith, /* ADD */
|
||||
arith, /* MINUS */
|
||||
arith, /* MULT */
|
||||
arith, /* DIVIDE */
|
||||
arith, /* MOD */
|
||||
assign, /* ASSIGN */
|
||||
nullproc, /* ASGNOP */
|
||||
assign, /* ADDEQ */
|
||||
assign, /* SUBEQ */
|
||||
assign, /* MULTEQ */
|
||||
assign, /* DIVEQ */
|
||||
assign, /* MODEQ */
|
||||
assign, /* POWEQ */
|
||||
printstat, /* PRINT */
|
||||
awkprintf, /* PRINTF */
|
||||
awksprintf, /* SPRINTF */
|
||||
nullproc, /* ELSE */
|
||||
intest, /* INTEST */
|
||||
condexpr, /* CONDEXPR */
|
||||
incrdecr, /* POSTINCR */
|
||||
incrdecr, /* PREINCR */
|
||||
incrdecr, /* POSTDECR */
|
||||
incrdecr, /* PREDECR */
|
||||
nullproc, /* VAR */
|
||||
nullproc, /* IVAR */
|
||||
getnf, /* VARNF */
|
||||
call, /* CALL */
|
||||
nullproc, /* NUMBER */
|
||||
nullproc, /* STRING */
|
||||
nullproc, /* REGEXPR */
|
||||
get_line, /* GETLINE */
|
||||
gensub, /* GENSUB */
|
||||
jump, /* RETURN */
|
||||
split, /* SPLIT */
|
||||
substr, /* SUBSTR */
|
||||
whilestat, /* WHILE */
|
||||
cat, /* CAT */
|
||||
boolop, /* NOT */
|
||||
arith, /* UMINUS */
|
||||
arith, /* POWER */
|
||||
nullproc, /* DECR */
|
||||
nullproc, /* INCR */
|
||||
indirect, /* INDIRECT */
|
||||
nullproc, /* LASTTOKEN */
|
||||
};
|
||||
|
||||
const char *tokname(int n)
|
||||
{
|
||||
static char buf[100];
|
||||
|
||||
if (n < FIRSTTOKEN || n > LASTTOKEN) {
|
||||
snprintf(buf, sizeof(buf), "token %d", n);
|
||||
return buf;
|
||||
}
|
||||
return printname[n-FIRSTTOKEN];
|
||||
}
|
|
@ -1,198 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
extern int yywrap(void);
|
||||
extern void setfname(Cell *);
|
||||
extern int constnode(Node *);
|
||||
extern char *strnode(Node *);
|
||||
extern Node *notnull(Node *);
|
||||
extern int yyparse(void);
|
||||
|
||||
extern int yylex(void);
|
||||
extern void startreg(void);
|
||||
extern int input(void);
|
||||
extern void unput(int);
|
||||
extern void unputstr(const char *);
|
||||
extern int yylook(void);
|
||||
extern int yyback(int *, int);
|
||||
extern int yyinput(void);
|
||||
|
||||
extern fa *makedfa(const char *, int);
|
||||
extern fa *mkdfa(const char *, int);
|
||||
extern int makeinit(fa *, int);
|
||||
extern void penter(Node *);
|
||||
extern void freetr(Node *);
|
||||
extern int hexstr(uschar **);
|
||||
extern int quoted(uschar **);
|
||||
extern char *cclenter(const char *);
|
||||
extern void overflo(const char *);
|
||||
extern void cfoll(fa *, Node *);
|
||||
extern int first(Node *);
|
||||
extern void follow(Node *);
|
||||
extern int member(int, const char *);
|
||||
extern int match(fa *, const char *);
|
||||
extern int pmatch(fa *, const char *);
|
||||
extern int nematch(fa *, const char *);
|
||||
extern Node *reparse(const char *);
|
||||
extern Node *regexp(void);
|
||||
extern Node *primary(void);
|
||||
extern Node *concat(Node *);
|
||||
extern Node *alt(Node *);
|
||||
extern Node *unary(Node *);
|
||||
extern int relex(void);
|
||||
extern int cgoto(fa *, int, int);
|
||||
extern void freefa(fa *);
|
||||
|
||||
extern int pgetc(void);
|
||||
extern char *cursource(void);
|
||||
|
||||
extern Node *nodealloc(int);
|
||||
extern Node *exptostat(Node *);
|
||||
extern Node *node1(int, Node *);
|
||||
extern Node *node2(int, Node *, Node *);
|
||||
extern Node *node3(int, Node *, Node *, Node *);
|
||||
extern Node *node4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *node5(int, Node *, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat3(int, Node *, Node *, Node *);
|
||||
extern Node *op2(int, Node *, Node *);
|
||||
extern Node *op1(int, Node *);
|
||||
extern Node *stat1(int, Node *);
|
||||
extern Node *op3(int, Node *, Node *, Node *);
|
||||
extern Node *op4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *op5(int, Node *, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat2(int, Node *, Node *);
|
||||
extern Node *stat4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *celltonode(Cell *, int);
|
||||
extern Node *rectonode(void);
|
||||
extern Node *makearr(Node *);
|
||||
extern Node *pa2stat(Node *, Node *, Node *);
|
||||
extern Node *linkum(Node *, Node *);
|
||||
extern void defn(Cell *, Node *, Node *);
|
||||
extern int isarg(const char *);
|
||||
extern const char *tokname(int);
|
||||
extern Cell *(*proctab[])(Node **, int);
|
||||
extern int ptoi(void *);
|
||||
extern Node *itonp(int);
|
||||
|
||||
extern void syminit(void);
|
||||
extern void arginit(int, char **);
|
||||
extern void envinit(char **);
|
||||
extern Array *makesymtab(int);
|
||||
extern void freesymtab(Cell *);
|
||||
extern void freeelem(Cell *, const char *);
|
||||
extern Cell *setsymtab(const char *, const char *, double, unsigned int, Array *);
|
||||
extern int hash(const char *, int);
|
||||
extern void rehash(Array *);
|
||||
extern Cell *lookup(const char *, Array *);
|
||||
extern double setfval(Cell *, double);
|
||||
extern void funnyvar(Cell *, const char *);
|
||||
extern char *setsval(Cell *, const char *);
|
||||
extern double getfval(Cell *);
|
||||
extern char *getsval(Cell *);
|
||||
extern char *getpssval(Cell *); /* for print */
|
||||
extern char *tostring(const char *);
|
||||
extern char *tostringN(const char *, size_t n);
|
||||
extern char *qstring(const char *, int);
|
||||
|
||||
extern void recinit(unsigned int);
|
||||
extern void initgetrec(void);
|
||||
extern void makefields(int, int);
|
||||
extern void growfldtab(int n);
|
||||
extern int getrec(uschar **, int *, int);
|
||||
extern void nextfile(void);
|
||||
extern int readrec(uschar **buf, int *bufsize, FILE *inf);
|
||||
extern char *getargv(int);
|
||||
extern void setclvar(char *);
|
||||
extern void fldbld(void);
|
||||
extern void cleanfld(int, int);
|
||||
extern void newfld(int);
|
||||
extern int refldbld(const char *, const char *);
|
||||
extern void recbld(void);
|
||||
extern Cell *fieldadr(int);
|
||||
extern void yyerror(const char *);
|
||||
extern void bracecheck(void);
|
||||
extern void bcheck2(int, int, int);
|
||||
extern void SYNTAX(const char *, ...);
|
||||
extern void FATAL(const char *, ...);
|
||||
extern void WARNING(const char *, ...);
|
||||
extern void error(void);
|
||||
extern void eprint(void);
|
||||
extern void bclass(int);
|
||||
extern double errcheck(double, const char *);
|
||||
extern int isclvar(const char *);
|
||||
extern int is_number(const char *);
|
||||
|
||||
extern int adjbuf(uschar **pb, int *sz, int min, int q, uschar **pbp, const char *what);
|
||||
extern void run(Node *);
|
||||
extern Cell *execute(Node *);
|
||||
extern Cell *program(Node **, int);
|
||||
extern Cell *call(Node **, int);
|
||||
extern Cell *copycell(Cell *);
|
||||
extern Cell *arg(Node **, int);
|
||||
extern Cell *jump(Node **, int);
|
||||
extern Cell *get_line(Node **, int);
|
||||
extern Cell *getnf(Node **, int);
|
||||
extern Cell *array(Node **, int);
|
||||
extern Cell *awkdelete(Node **, int);
|
||||
extern Cell *intest(Node **, int);
|
||||
extern Cell *matchop(Node **, int);
|
||||
extern Cell *boolop(Node **, int);
|
||||
extern Cell *relop(Node **, int);
|
||||
extern void tfree(Cell *);
|
||||
extern Cell *gettemp(void);
|
||||
extern Cell *field(Node **, int);
|
||||
extern Cell *indirect(Node **, int);
|
||||
extern Cell *substr(Node **, int);
|
||||
extern Cell *sindex(Node **, int);
|
||||
extern int format(char **, int *, const char *, Node *);
|
||||
extern Cell *awksprintf(Node **, int);
|
||||
extern Cell *awkprintf(Node **, int);
|
||||
extern Cell *arith(Node **, int);
|
||||
extern double ipow(double, int);
|
||||
extern Cell *incrdecr(Node **, int);
|
||||
extern Cell *assign(Node **, int);
|
||||
extern Cell *cat(Node **, int);
|
||||
extern Cell *pastat(Node **, int);
|
||||
extern Cell *dopa2(Node **, int);
|
||||
extern Cell *split(Node **, int);
|
||||
extern Cell *condexpr(Node **, int);
|
||||
extern Cell *ifstat(Node **, int);
|
||||
extern Cell *whilestat(Node **, int);
|
||||
extern Cell *dostat(Node **, int);
|
||||
extern Cell *forstat(Node **, int);
|
||||
extern Cell *instat(Node **, int);
|
||||
extern Cell *bltin(Node **, int);
|
||||
extern Cell *printstat(Node **, int);
|
||||
extern Cell *nullproc(Node **, int);
|
||||
extern FILE *redirect(int, Node *);
|
||||
extern FILE *openfile(int, const char *);
|
||||
extern const char *filename(FILE *);
|
||||
extern Cell *closefile(Node **, int);
|
||||
extern void closeall(void);
|
||||
extern Cell *sub(Node **, int);
|
||||
extern Cell *gsub(Node **, int);
|
||||
extern Cell *gensub(Node **, int);
|
||||
|
||||
extern FILE *popen(const char *, const char *);
|
||||
extern int pclose(FILE *);
|
File diff suppressed because it is too large
Load Diff
|
@ -1,473 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.h"
|
||||
|
||||
#define FULLTAB 2 /* rehash when table gets this x full */
|
||||
#define GROWTAB 4 /* grow table by this factor */
|
||||
|
||||
Array *symtab; /* main symbol table */
|
||||
|
||||
char **FS; /* initial field sep */
|
||||
char **RS; /* initial record sep */
|
||||
char **OFS; /* output field sep */
|
||||
char **ORS; /* output record sep */
|
||||
char **OFMT; /* output format for numbers */
|
||||
char **CONVFMT; /* format for conversions in getsval */
|
||||
Awkfloat *NF; /* number of fields in current record */
|
||||
Awkfloat *NR; /* number of current record */
|
||||
Awkfloat *FNR; /* number of current record in current file */
|
||||
char **FILENAME; /* current filename argument */
|
||||
Awkfloat *ARGC; /* number of arguments from command line */
|
||||
char **SUBSEP; /* subscript separator for a[i,j,k]; default \034 */
|
||||
Awkfloat *RSTART; /* start of re matched with ~; origin 1 (!) */
|
||||
Awkfloat *RLENGTH; /* length of same */
|
||||
|
||||
Cell *fsloc; /* FS */
|
||||
Cell *nrloc; /* NR */
|
||||
Cell *nfloc; /* NF */
|
||||
Cell *fnrloc; /* FNR */
|
||||
Array *ARGVtab; /* symbol table containing ARGV[...] */
|
||||
Array *ENVtab; /* symbol table containing ENVIRON[...] */
|
||||
Cell *rstartloc; /* RSTART */
|
||||
Cell *rlengthloc; /* RLENGTH */
|
||||
Cell *symtabloc; /* SYMTAB */
|
||||
|
||||
Cell *nullloc; /* a guaranteed empty cell */
|
||||
Node *nullnode; /* zero&null, converted into a node for comparisons */
|
||||
Cell *literal0;
|
||||
|
||||
extern Cell **fldtab;
|
||||
|
||||
void syminit(void) /* initialize symbol table with builtin vars */
|
||||
{
|
||||
literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab);
|
||||
/* this is used for if(x)... tests: */
|
||||
nullloc = setsymtab("$zero&null", "", 0.0, NUM|STR|CON|DONTFREE, symtab);
|
||||
nullnode = celltonode(nullloc, CCON);
|
||||
|
||||
fsloc = setsymtab("FS", " ", 0.0, STR|DONTFREE, symtab);
|
||||
FS = &fsloc->sval;
|
||||
RS = &setsymtab("RS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
OFS = &setsymtab("OFS", " ", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
ORS = &setsymtab("ORS", "\n", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
OFMT = &setsymtab("OFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
CONVFMT = &setsymtab("CONVFMT", "%.6g", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
FILENAME = &setsymtab("FILENAME", "", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
nfloc = setsymtab("NF", "", 0.0, NUM, symtab);
|
||||
NF = &nfloc->fval;
|
||||
nrloc = setsymtab("NR", "", 0.0, NUM, symtab);
|
||||
NR = &nrloc->fval;
|
||||
fnrloc = setsymtab("FNR", "", 0.0, NUM, symtab);
|
||||
FNR = &fnrloc->fval;
|
||||
SUBSEP = &setsymtab("SUBSEP", "\034", 0.0, STR|DONTFREE, symtab)->sval;
|
||||
rstartloc = setsymtab("RSTART", "", 0.0, NUM, symtab);
|
||||
RSTART = &rstartloc->fval;
|
||||
rlengthloc = setsymtab("RLENGTH", "", 0.0, NUM, symtab);
|
||||
RLENGTH = &rlengthloc->fval;
|
||||
symtabloc = setsymtab("SYMTAB", "", 0.0, ARR, symtab);
|
||||
symtabloc->sval = (char *) symtab;
|
||||
}
|
||||
|
||||
void arginit(int ac, char **av) /* set up ARGV and ARGC */
|
||||
{
|
||||
Cell *cp;
|
||||
int i;
|
||||
char temp[50];
|
||||
|
||||
ARGC = &setsymtab("ARGC", "", (Awkfloat) ac, NUM, symtab)->fval;
|
||||
cp = setsymtab("ARGV", "", 0.0, ARR, symtab);
|
||||
ARGVtab = makesymtab(NSYMTAB); /* could be (int) ARGC as well */
|
||||
cp->sval = (char *) ARGVtab;
|
||||
for (i = 0; i < ac; i++) {
|
||||
snprintf(temp, sizeof(temp), "%d", i);
|
||||
if (is_number(*av))
|
||||
setsymtab(temp, *av, atof(*av), STR|NUM, ARGVtab);
|
||||
else
|
||||
setsymtab(temp, *av, 0.0, STR, ARGVtab);
|
||||
av++;
|
||||
}
|
||||
}
|
||||
|
||||
void envinit(char **envp) /* set up ENVIRON variable */
|
||||
{
|
||||
Cell *cp;
|
||||
char *p;
|
||||
|
||||
cp = setsymtab("ENVIRON", "", 0.0, ARR, symtab);
|
||||
ENVtab = makesymtab(NSYMTAB);
|
||||
cp->sval = (char *) ENVtab;
|
||||
for ( ; *envp; envp++) {
|
||||
if ((p = strchr(*envp, '=')) == NULL)
|
||||
continue;
|
||||
if( p == *envp ) /* no left hand side name in env string */
|
||||
continue;
|
||||
*p++ = 0; /* split into two strings at = */
|
||||
if (is_number(p))
|
||||
setsymtab(*envp, p, atof(p), STR|NUM, ENVtab);
|
||||
else
|
||||
setsymtab(*envp, p, 0.0, STR, ENVtab);
|
||||
p[-1] = '='; /* restore in case env is passed down to a shell */
|
||||
}
|
||||
}
|
||||
|
||||
Array *makesymtab(int n) /* make a new symbol table */
|
||||
{
|
||||
Array *ap;
|
||||
Cell **tp;
|
||||
|
||||
ap = (Array *) malloc(sizeof(Array));
|
||||
tp = (Cell **) calloc(n, sizeof(Cell *));
|
||||
if (ap == NULL || tp == NULL)
|
||||
FATAL("out of space in makesymtab");
|
||||
ap->nelem = 0;
|
||||
ap->size = n;
|
||||
ap->tab = tp;
|
||||
return(ap);
|
||||
}
|
||||
|
||||
void freesymtab(Cell *ap) /* free a symbol table */
|
||||
{
|
||||
Cell *cp, *temp;
|
||||
Array *tp;
|
||||
int i;
|
||||
|
||||
if (!isarr(ap))
|
||||
return;
|
||||
tp = (Array *) ap->sval;
|
||||
if (tp == NULL)
|
||||
return;
|
||||
for (i = 0; i < tp->size; i++) {
|
||||
for (cp = tp->tab[i]; cp != NULL; cp = temp) {
|
||||
xfree(cp->nval);
|
||||
if (freeable(cp))
|
||||
xfree(cp->sval);
|
||||
temp = cp->cnext; /* avoids freeing then using */
|
||||
free(cp);
|
||||
tp->nelem--;
|
||||
}
|
||||
tp->tab[i] = 0;
|
||||
}
|
||||
if (tp->nelem != 0)
|
||||
WARNING("can't happen: inconsistent element count freeing %s", ap->nval);
|
||||
free(tp->tab);
|
||||
free(tp);
|
||||
}
|
||||
|
||||
void freeelem(Cell *ap, const char *s) /* free elem s from ap (i.e., ap["s"] */
|
||||
{
|
||||
Array *tp;
|
||||
Cell *p, *prev = NULL;
|
||||
int h;
|
||||
|
||||
tp = (Array *) ap->sval;
|
||||
h = hash(s, tp->size);
|
||||
for (p = tp->tab[h]; p != NULL; prev = p, p = p->cnext)
|
||||
if (strcmp(s, p->nval) == 0) {
|
||||
if (prev == NULL) /* 1st one */
|
||||
tp->tab[h] = p->cnext;
|
||||
else /* middle somewhere */
|
||||
prev->cnext = p->cnext;
|
||||
if (freeable(p))
|
||||
xfree(p->sval);
|
||||
free(p->nval);
|
||||
free(p);
|
||||
tp->nelem--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
|
||||
{
|
||||
int h;
|
||||
Cell *p;
|
||||
|
||||
if (n == NULL)
|
||||
n = "";
|
||||
|
||||
if ((p = lookup(n, tp)) != NULL) {
|
||||
dprintf( ("setsymtab found %p: n=%s s=\"%s\" f=%g t=%o\n",
|
||||
p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
|
||||
return(p);
|
||||
}
|
||||
p = (Cell *) malloc(sizeof(Cell));
|
||||
if (p == NULL)
|
||||
FATAL("out of space for symbol table at %s", n);
|
||||
p->nval = tostring(n);
|
||||
p->sval = s ? tostring(s) : tostring("");
|
||||
p->fval = f;
|
||||
p->tval = t;
|
||||
p->csub = CUNK;
|
||||
p->ctype = OCELL;
|
||||
tp->nelem++;
|
||||
if (tp->nelem > FULLTAB * tp->size)
|
||||
rehash(tp);
|
||||
h = hash(n, tp->size);
|
||||
p->cnext = tp->tab[h];
|
||||
tp->tab[h] = p;
|
||||
dprintf( ("setsymtab set %p: n=%s s=\"%s\" f=%g t=%o\n",
|
||||
p, p->nval, p->sval, p->fval, p->tval) );
|
||||
return(p);
|
||||
}
|
||||
|
||||
int hash(const char *s, int n) /* form hash value for string s */
|
||||
{
|
||||
unsigned hashval;
|
||||
|
||||
for (hashval = 0; *s != '\0'; s++)
|
||||
hashval = (*s + 31 * hashval);
|
||||
return hashval % n;
|
||||
}
|
||||
|
||||
void rehash(Array *tp) /* rehash items in small table into big one */
|
||||
{
|
||||
int i, nh, nsz;
|
||||
Cell *cp, *op, **np;
|
||||
|
||||
nsz = GROWTAB * tp->size;
|
||||
np = (Cell **) calloc(nsz, sizeof(Cell *));
|
||||
if (np == NULL) /* can't do it, but can keep running. */
|
||||
return; /* someone else will run out later. */
|
||||
for (i = 0; i < tp->size; i++) {
|
||||
for (cp = tp->tab[i]; cp; cp = op) {
|
||||
op = cp->cnext;
|
||||
nh = hash(cp->nval, nsz);
|
||||
cp->cnext = np[nh];
|
||||
np[nh] = cp;
|
||||
}
|
||||
}
|
||||
free(tp->tab);
|
||||
tp->tab = np;
|
||||
tp->size = nsz;
|
||||
}
|
||||
|
||||
Cell *lookup(const char *s, Array *tp) /* look for s in tp */
|
||||
{
|
||||
Cell *p;
|
||||
int h;
|
||||
|
||||
h = hash(s, tp->size);
|
||||
for (p = tp->tab[h]; p != NULL; p = p->cnext)
|
||||
if (strcmp(s, p->nval) == 0)
|
||||
return(p); /* found it */
|
||||
return(NULL); /* not found */
|
||||
}
|
||||
|
||||
Awkfloat setfval(Cell *vp, Awkfloat f) /* set float val of a Cell */
|
||||
{
|
||||
int fldno;
|
||||
|
||||
f += 0.0; /* normalise negative zero to positive zero */
|
||||
if ((vp->tval & (NUM | STR)) == 0)
|
||||
funnyvar(vp, "assign to");
|
||||
if (isfld(vp)) {
|
||||
donerec = 0; /* mark $0 invalid */
|
||||
fldno = atoi(vp->nval);
|
||||
if (fldno > *NF)
|
||||
newfld(fldno);
|
||||
dprintf( ("setting field %d to %g\n", fldno, f) );
|
||||
} else if (isrec(vp)) {
|
||||
donefld = 0; /* mark $1... invalid */
|
||||
donerec = 1;
|
||||
}
|
||||
if (freeable(vp))
|
||||
xfree(vp->sval); /* free any previous string */
|
||||
vp->tval &= ~STR; /* mark string invalid */
|
||||
vp->tval |= NUM; /* mark number ok */
|
||||
dprintf( ("setfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), f, vp->tval) );
|
||||
return vp->fval = f;
|
||||
}
|
||||
|
||||
void funnyvar(Cell *vp, const char *rw)
|
||||
{
|
||||
if (isarr(vp))
|
||||
FATAL("can't %s %s; it's an array name.", rw, vp->nval);
|
||||
if (vp->tval & FCN)
|
||||
FATAL("can't %s %s; it's a function.", rw, vp->nval);
|
||||
WARNING("funny variable %p: n=%s s=\"%s\" f=%g t=%o",
|
||||
vp, vp->nval, vp->sval, vp->fval, vp->tval);
|
||||
}
|
||||
|
||||
char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
|
||||
{
|
||||
char *t;
|
||||
int fldno;
|
||||
|
||||
dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
|
||||
vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
|
||||
if ((vp->tval & (NUM | STR)) == 0)
|
||||
funnyvar(vp, "assign to");
|
||||
if (isfld(vp)) {
|
||||
donerec = 0; /* mark $0 invalid */
|
||||
fldno = atoi(vp->nval);
|
||||
if (fldno > *NF)
|
||||
newfld(fldno);
|
||||
dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
|
||||
} else if (isrec(vp)) {
|
||||
donefld = 0; /* mark $1... invalid */
|
||||
donerec = 1;
|
||||
}
|
||||
t = tostring(s); /* in case it's self-assign */
|
||||
vp->tval &= ~NUM;
|
||||
vp->tval |= STR;
|
||||
if (freeable(vp))
|
||||
xfree(vp->sval);
|
||||
vp->tval &= ~DONTFREE;
|
||||
dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
|
||||
vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
|
||||
return(vp->sval = t);
|
||||
}
|
||||
|
||||
Awkfloat getfval(Cell *vp) /* get float val of a Cell */
|
||||
{
|
||||
if ((vp->tval & (NUM | STR)) == 0)
|
||||
funnyvar(vp, "read value of");
|
||||
if (isfld(vp) && donefld == 0)
|
||||
fldbld();
|
||||
else if (isrec(vp) && donerec == 0)
|
||||
recbld();
|
||||
if (!isnum(vp)) { /* not a number */
|
||||
vp->fval = atof(vp->sval); /* best guess */
|
||||
if (is_number(vp->sval) && !(vp->tval&CON))
|
||||
vp->tval |= NUM; /* make NUM only sparingly */
|
||||
}
|
||||
dprintf( ("getfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), vp->fval, vp->tval) );
|
||||
return(vp->fval);
|
||||
}
|
||||
|
||||
static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
|
||||
{
|
||||
char s[100];
|
||||
double dtemp;
|
||||
|
||||
if ((vp->tval & (NUM | STR)) == 0)
|
||||
funnyvar(vp, "read value of");
|
||||
if (isfld(vp) && donefld == 0)
|
||||
fldbld();
|
||||
else if (isrec(vp) && donerec == 0)
|
||||
recbld();
|
||||
if (isstr(vp) == 0) {
|
||||
if (freeable(vp))
|
||||
xfree(vp->sval);
|
||||
if (modf(vp->fval, &dtemp) == 0) /* it's integral */
|
||||
snprintf(s, sizeof(s), "%.30g", vp->fval);
|
||||
else
|
||||
snprintf(s, sizeof(s), *fmt, vp->fval);
|
||||
vp->sval = tostring(s);
|
||||
vp->tval &= ~DONTFREE;
|
||||
vp->tval |= STR;
|
||||
}
|
||||
dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n", vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
|
||||
return(vp->sval);
|
||||
}
|
||||
|
||||
char *getsval(Cell *vp) /* get string val of a Cell */
|
||||
{
|
||||
return get_str_val(vp, CONVFMT);
|
||||
}
|
||||
|
||||
char *getpssval(Cell *vp) /* get string val of a Cell for print */
|
||||
{
|
||||
return get_str_val(vp, OFMT);
|
||||
}
|
||||
|
||||
|
||||
char *tostring(const char *s) /* make a copy of string s */
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strdup(s);
|
||||
if (p == NULL)
|
||||
FATAL("out of space in tostring on %s", s);
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *tostringN(const char *s, size_t n) /* make a copy of string s */
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = malloc(n);
|
||||
if (p == NULL)
|
||||
FATAL("out of space in tostring on %s", s);
|
||||
strcpy(p, s);
|
||||
return(p);
|
||||
}
|
||||
|
||||
char *qstring(const char *is, int delim) /* collect string up to next delim */
|
||||
{
|
||||
const char *os = is;
|
||||
int c, n;
|
||||
uschar *s = (uschar *) is;
|
||||
uschar *buf, *bp;
|
||||
|
||||
if ((buf = (uschar *) malloc(strlen(is)+3)) == NULL)
|
||||
FATAL( "out of space in qstring(%s)", s);
|
||||
for (bp = buf; (c = *s) != delim; s++) {
|
||||
if (c == '\n')
|
||||
SYNTAX( "newline in string %.20s...", os );
|
||||
else if (c != '\\')
|
||||
*bp++ = c;
|
||||
else { /* \something */
|
||||
c = *++s;
|
||||
if (c == 0) { /* \ at end */
|
||||
*bp++ = '\\';
|
||||
break; /* for loop */
|
||||
}
|
||||
switch (c) {
|
||||
case '\\': *bp++ = '\\'; break;
|
||||
case 'n': *bp++ = '\n'; break;
|
||||
case 't': *bp++ = '\t'; break;
|
||||
case 'b': *bp++ = '\b'; break;
|
||||
case 'f': *bp++ = '\f'; break;
|
||||
case 'r': *bp++ = '\r'; break;
|
||||
default:
|
||||
if (!isdigit(c)) {
|
||||
*bp++ = c;
|
||||
break;
|
||||
}
|
||||
n = c - '0';
|
||||
if (isdigit(s[1])) {
|
||||
n = 8 * n + *++s - '0';
|
||||
if (isdigit(s[1]))
|
||||
n = 8 * n + *++s - '0';
|
||||
}
|
||||
*bp++ = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*bp++ = 0;
|
||||
return (char *) buf;
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
This file is automatically generated from html/copyright.html
|
||||
|
||||
Copyright Notice
|
||||
|
||||
jpg "Clone me," says Dolly sheepishly
|
||||
|
||||
Last update: 20:31 UTC Saturday, January 06, 2007
|
||||
_________________________________________________________________
|
||||
|
||||
The following copyright notice applies to all files collectively
|
||||
called the Network Time Protocol Version 4 Distribution. Unless
|
||||
specifically declared otherwise in an individual file, this notice
|
||||
applies as if the text was explicitly included in the file.
|
||||
***********************************************************************
|
||||
* *
|
||||
* Copyright (c) David L. Mills 1992-2009 *
|
||||
* *
|
||||
* Permission to use, copy, modify, and distribute this software and *
|
||||
* its documentation for any purpose with or without fee is hereby *
|
||||
* granted, provided that the above copyright notice appears in all *
|
||||
* copies and that both the copyright notice and this permission *
|
||||
* notice appear in supporting documentation, and that the name *
|
||||
* University of Delaware not be used in advertising or publicity *
|
||||
* pertaining to distribution of the software without specific, *
|
||||
* written prior permission. The University of Delaware makes no *
|
||||
* representations about the suitability this software for any *
|
||||
* purpose. It is provided "as is" without express or implied *
|
||||
* warranty. *
|
||||
* *
|
||||
***********************************************************************
|
||||
|
||||
The following individuals contributed in part to the Network Time
|
||||
Protocol Distribution Version 4 and are acknowledged as authors of
|
||||
this work.
|
||||
1. [1]Mark Andrews <mark_andrews@isc.org> Leitch atomic clock
|
||||
controller
|
||||
2. [2]Bernd Altmeier <altmeier@atlsoft.de> hopf Elektronik serial
|
||||
line and PCI-bus devices
|
||||
3. [3]Viraj Bais <vbais@mailman1.intel.com> and [4]Clayton Kirkwood
|
||||
<kirkwood@striderfm.intel.com> port to WindowsNT 3.5
|
||||
4. [5]Michael Barone <michael,barone@lmco.com> GPSVME fixes
|
||||
5. [6]Jean-Francois Boudreault
|
||||
<Jean-Francois.Boudreault@viagenie.qc.ca>IPv6 support
|
||||
6. [7]Karl Berry <karl@owl.HQ.ileaf.com> syslog to file option
|
||||
7. [8]Greg Brackley <greg.brackley@bigfoot.com> Major rework of WINNT
|
||||
port. Clean up recvbuf and iosignal code into separate modules.
|
||||
8. [9]Marc Brett <Marc.Brett@westgeo.com> Magnavox GPS clock driver
|
||||
9. [10]Piete Brooks <Piete.Brooks@cl.cam.ac.uk> MSF clock driver,
|
||||
Trimble PARSE support
|
||||
10. [11]Reg Clemens <reg@dwf.com> Oncore driver (Current maintainer)
|
||||
11. [12]Steve Clift <clift@ml.csiro.au> OMEGA clock driver
|
||||
12. [13]Casey Crellin <casey@csc.co.za> vxWorks (Tornado) port and
|
||||
help with target configuration
|
||||
13. [14]Sven Dietrich <sven_dietrich@trimble.com> Palisade reference
|
||||
clock driver, NT adj. residuals, integrated Greg's Winnt port.
|
||||
14. [15]John A. Dundas III <dundas@salt.jpl.nasa.gov> Apple A/UX port
|
||||
15. [16]Torsten Duwe <duwe@immd4.informatik.uni-erlangen.de> Linux
|
||||
port
|
||||
16. [17]Dennis Ferguson <dennis@mrbill.canet.ca> foundation code for
|
||||
NTP Version 2 as specified in RFC-1119
|
||||
17. [18]John Hay <jhay@@icomtek.csir.co.za> IPv6 support and testing
|
||||
18. [19]Glenn Hollinger <glenn@herald.usask.ca> GOES clock driver
|
||||
19. [20]Mike Iglesias <iglesias@uci.edu> DEC Alpha port
|
||||
20. [21]Jim Jagielski <jim@jagubox.gsfc.nasa.gov> A/UX port
|
||||
21. [22]Jeff Johnson <jbj@chatham.usdesign.com> massive prototyping
|
||||
overhaul
|
||||
22. [23]Hans Lambermont <Hans.Lambermont@nl.origin-it.com> or
|
||||
[24]<H.Lambermont@chello.nl> ntpsweep
|
||||
23. [25]Poul-Henning Kamp <phk@FreeBSD.ORG> Oncore driver (Original
|
||||
author)
|
||||
24. [26]Frank Kardel [27]<kardel (at) ntp (dot) org> PARSE <GENERIC>
|
||||
driver (>14 reference clocks), STREAMS modules for PARSE, support
|
||||
scripts, syslog cleanup, dynamic interface handling
|
||||
25. [28]William L. Jones <jones@hermes.chpc.utexas.edu> RS/6000 AIX
|
||||
modifications, HPUX modifications
|
||||
26. [29]Dave Katz <dkatz@cisco.com> RS/6000 AIX port
|
||||
27. [30]Craig Leres <leres@ee.lbl.gov> 4.4BSD port, ppsclock, Magnavox
|
||||
GPS clock driver
|
||||
28. [31]George Lindholm <lindholm@ucs.ubc.ca> SunOS 5.1 port
|
||||
29. [32]Louis A. Mamakos <louie@ni.umd.edu> MD5-based authentication
|
||||
30. [33]Lars H. Mathiesen <thorinn@diku.dk> adaptation of foundation
|
||||
code for Version 3 as specified in RFC-1305
|
||||
31. [34]Danny Mayer <mayer@ntp.org>Network I/O, Windows Port, Code
|
||||
Maintenance
|
||||
32. [35]David L. Mills <mills@udel.edu> Version 4 foundation: clock
|
||||
discipline, authentication, precision kernel; clock drivers:
|
||||
Spectracom, Austron, Arbiter, Heath, ATOM, ACTS, KSI/Odetics;
|
||||
audio clock drivers: CHU, WWV/H, IRIG
|
||||
33. [36]Wolfgang Moeller <moeller@gwdgv1.dnet.gwdg.de> VMS port
|
||||
34. [37]Jeffrey Mogul <mogul@pa.dec.com> ntptrace utility
|
||||
35. [38]Tom Moore <tmoore@fievel.daytonoh.ncr.com> i386 svr4 port
|
||||
36. [39]Kamal A Mostafa <kamal@whence.com> SCO OpenServer port
|
||||
37. [40]Derek Mulcahy <derek@toybox.demon.co.uk> and [41]Damon
|
||||
Hart-Davis <d@hd.org> ARCRON MSF clock driver
|
||||
38. [42]Rainer Pruy <Rainer.Pruy@informatik.uni-erlangen.de>
|
||||
monitoring/trap scripts, statistics file handling
|
||||
39. [43]Dirce Richards <dirce@zk3.dec.com> Digital UNIX V4.0 port
|
||||
40. [44]Wilfredo Sánchez <wsanchez@apple.com> added support for
|
||||
NetInfo
|
||||
41. [45]Nick Sayer <mrapple@quack.kfu.com> SunOS streams modules
|
||||
42. [46]Jack Sasportas <jack@innovativeinternet.com> Saved a Lot of
|
||||
space on the stuff in the html/pic/ subdirectory
|
||||
43. [47]Ray Schnitzler <schnitz@unipress.com> Unixware1 port
|
||||
44. [48]Michael Shields <shields@tembel.org> USNO clock driver
|
||||
45. [49]Jeff Steinman <jss@pebbles.jpl.nasa.gov> Datum PTS clock
|
||||
driver
|
||||
46. [50]Harlan Stenn <harlan@pfcs.com> GNU automake/autoconfigure
|
||||
makeover, various other bits (see the ChangeLog)
|
||||
47. [51]Kenneth Stone <ken@sdd.hp.com> HP-UX port
|
||||
48. [52]Ajit Thyagarajan <ajit@ee.udel.edu>IP multicast/anycast
|
||||
support
|
||||
49. [53]Tomoaki TSURUOKA <tsuruoka@nc.fukuoka-u.ac.jp>TRAK clock
|
||||
driver
|
||||
50. [54]Paul A Vixie <vixie@vix.com> TrueTime GPS driver, generic
|
||||
TrueTime clock driver
|
||||
51. [55]Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de> corrected and
|
||||
validated HTML documents according to the HTML DTD
|
||||
_________________________________________________________________
|
||||
|
||||
References
|
||||
|
||||
1. mailto:%20mark_andrews@isc.org
|
||||
2. mailto:%20altmeier@atlsoft.de
|
||||
3. mailto:%20vbais@mailman1.intel.co
|
||||
4. mailto:%20kirkwood@striderfm.intel.com
|
||||
5. mailto:%20michael.barone@lmco.com
|
||||
6. mailto:%20Jean-Francois.Boudreault@viagenie.qc.ca
|
||||
7. mailto:%20karl@owl.HQ.ileaf.com
|
||||
8. mailto:%20greg.brackley@bigfoot.com
|
||||
9. mailto:%20Marc.Brett@westgeo.com
|
||||
10. mailto:%20Piete.Brooks@cl.cam.ac.uk
|
||||
11. mailto:%20reg@dwf.com
|
||||
12. mailto:%20clift@ml.csiro.au
|
||||
13. mailto:casey@csc.co.za
|
||||
14. mailto:%20Sven_Dietrich@trimble.COM
|
||||
15. mailto:%20dundas@salt.jpl.nasa.gov
|
||||
16. mailto:%20duwe@immd4.informatik.uni-erlangen.de
|
||||
17. mailto:%20dennis@mrbill.canet.ca
|
||||
18. mailto:%20jhay@icomtek.csir.co.za
|
||||
19. mailto:%20glenn@herald.usask.ca
|
||||
20. mailto:%20iglesias@uci.edu
|
||||
21. mailto:%20jagubox.gsfc.nasa.gov
|
||||
22. mailto:%20jbj@chatham.usdesign.com
|
||||
23. mailto:Hans.Lambermont@nl.origin-it.com
|
||||
24. mailto:H.Lambermont@chello.nl
|
||||
25. mailto:%20phk@FreeBSD.ORG
|
||||
26. http://www4.informatik.uni-erlangen.de/%7ekardel
|
||||
27. mailto:%20kardel(at)ntp(dot)org
|
||||
28. mailto:%20jones@hermes.chpc.utexas.edu
|
||||
29. mailto:%20dkatz@cisco.com
|
||||
30. mailto:%20leres@ee.lbl.gov
|
||||
31. mailto:%20lindholm@ucs.ubc.ca
|
||||
32. mailto:%20louie@ni.umd.edu
|
||||
33. mailto:%20thorinn@diku.dk
|
||||
34. mailto:%20mayer@ntp.org
|
||||
35. mailto:%20mills@udel.edu
|
||||
36. mailto:%20moeller@gwdgv1.dnet.gwdg.de
|
||||
37. mailto:%20mogul@pa.dec.com
|
||||
38. mailto:%20tmoore@fievel.daytonoh.ncr.com
|
||||
39. mailto:%20kamal@whence.com
|
||||
40. mailto:%20derek@toybox.demon.co.uk
|
||||
41. mailto:%20d@hd.org
|
||||
42. mailto:%20Rainer.Pruy@informatik.uni-erlangen.de
|
||||
43. mailto:%20dirce@zk3.dec.com
|
||||
44. mailto:%20wsanchez@apple.com
|
||||
45. mailto:%20mrapple@quack.kfu.com
|
||||
46. mailto:%20jack@innovativeinternet.com
|
||||
47. mailto:%20schnitz@unipress.com
|
||||
48. mailto:%20shields@tembel.org
|
||||
49. mailto:%20pebbles.jpl.nasa.gov
|
||||
50. mailto:%20harlan@pfcs.com
|
||||
51. mailto:%20ken@sdd.hp.com
|
||||
52. mailto:%20ajit@ee.udel.edu
|
||||
53. mailto:%20tsuruoka@nc.fukuoka-u.ac.jp
|
||||
54. mailto:%20vixie@vix.com
|
||||
55. mailto:%20Ulrich.Windl@rz.uni-regensburg.de
|
|
@ -1,484 +0,0 @@
|
|||
---
|
||||
(4.2.4p8) 2009/12/08 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Sec 1331] DoS with mode 7 packets - CVE-2009-3563.
|
||||
|
||||
---
|
||||
(4.2.4p7) 2009/05/18 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Sec 1151] Remote exploit if autokey is enabled - CVE-2009-1252.
|
||||
* [Bug 1187] Update the copyright date.
|
||||
* [Bug 1191] ntpd fails on Win2000 - "Address already in use" after fix
|
||||
for [Sec 1149].
|
||||
|
||||
---
|
||||
(4.2.4p7-RC7) 2009/05/12 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* ntp.isc.org -> ntp.org cleanup.
|
||||
* [Bug 1178] Use prior FORCE_DNSRETRY behavior as needed at runtime,
|
||||
add configure --enable-ignore-dns-errors to be even more stubborn
|
||||
|
||||
---
|
||||
(4.2.4p7-RC6) 2009/05/08 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 784] Make --enable-linuxcaps the default when available
|
||||
* [Bug 1179] error messages for -u/--user and -i lacking droproot
|
||||
* Updated JJY reference clock driver from Takao Abe
|
||||
* [Bug 1071] Log a message and exit before trying to use FD_SET with a
|
||||
descriptor larger than FD_SETSIZE, which will corrupt memory
|
||||
* On corruption of the iface list head in add_interface, log and exit
|
||||
|
||||
---
|
||||
(4.2.4p7-RC5) 2009/05/02 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 1172] 4.2.4p7-RC{3,4} fail to build on linux.
|
||||
* flock-build script unportable 'set -m' use removed
|
||||
|
||||
---
|
||||
(4.2.4p7-RC4) 2009/04/29 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 1167] use gcc -Winit-self only if it is understood
|
||||
|
||||
---
|
||||
(4.2.4p7-RC3) 2009/04/22 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 787] Bug fixes for 64-bit time_t on Windows
|
||||
* [Bug 813] Conditional naming of Event
|
||||
* [Bug 1147] System errors should be logged to msyslog()
|
||||
* [Bug 1155] Fix compile problem on Windows with VS2005
|
||||
* [Bug 1156] lock_thread_to_processor() should be declared in header
|
||||
* [Bug 1157] quiet OpenSSL warnings, clean up configure.ac
|
||||
* [Bug 1158] support for aix6.1
|
||||
* [Bug 1160] MacOS X is like BSD regarding F_SETOWN
|
||||
|
||||
---
|
||||
(4.2.4p7-RC2) 2009/04/09 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Sec 1144] limited buffer overflow in ntpq. CVE-2009-0159
|
||||
* [Sec 1149] use SO_EXCLUSIVEADDRUSE on Windows
|
||||
|
||||
---
|
||||
(4.2.4p7-RC1) 2009/03/30 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 1131] UDP sockets should not use SIGPOLL on Solaris.
|
||||
* build system email address cleanup
|
||||
* [Bug 774] parsesolaris.c does not compile under the new Solaris
|
||||
* [Bug 873] Windows serial refclock proper TTY line discipline emulation
|
||||
* [Bug 1014] Enable building with VC9 (in Visual Studio 2008,
|
||||
Visual C++ 2008, or SDK)
|
||||
* [Bug 1117] Deferred interface binding under Windows works only correctly
|
||||
if FORCE_DNSRETRY is defined
|
||||
* [BUG 1124] Lock QueryPerformanceCounter() client threads to same CPU
|
||||
* DPRINTF macro made safer, always evaluates to a statement and will not
|
||||
misassociate an else which follows the macro.
|
||||
|
||||
---
|
||||
(4.2.4p6) 2009/01/08 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 1113] Fixed build errors with recent versions of openSSL.
|
||||
* [Sec 1111] Fix incorrect check of EVP_VerifyFinal()'s return value.
|
||||
* Update the copyright year.
|
||||
|
||||
---
|
||||
(4.2.4p5) 2008/08/17 Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [BUG 1051] Month off by one in leap second message written to clockstats
|
||||
file fixed.
|
||||
* [Bug 450] Windows only: Under original Windows NT we must not discard the
|
||||
wildcard socket to workaround a bug in NT's getsockname().
|
||||
* [Bug 1038] Built-in getpass() function also prompts for password if
|
||||
not built with DEBUG.
|
||||
* [Bug 841] Obsolete the "dynamic" keyword and make deferred binding
|
||||
to local interfaces the default.
|
||||
Emit a warning if that keyword is used for configuration.
|
||||
* [Bug 959] Refclock on Windows not properly releasing recvbuffs.
|
||||
* [Bug 993] Fix memory leak when fetching system messages.
|
||||
* [Bug 987] Wake up the resolver thread/process when a new interface has
|
||||
become available.
|
||||
* Correctly apply negative-sawtooth for oncore 12 channel receiver.
|
||||
* Startup code for original LinuxPPS removed. LinuxPPS now conforms to
|
||||
the PPSAPI.
|
||||
* [Bug 1000] allow implicit receive buffer allocation for Windows.
|
||||
fixes startup for windows systems with many interfaces.
|
||||
reduces dropped packets on network bursts.
|
||||
additionally fix timer() starvation during high load.
|
||||
* [Bug 990] drop minimum time restriction for interface update interval.
|
||||
* [Bug 977] Fix mismatching #ifdefs for builds without IPv6.
|
||||
* Update the copyright year.
|
||||
* Build system cleanup (make autogen-generated files writable).
|
||||
* [Bug 957] Windows only: Let command line parameters from the Windows SCM GUI
|
||||
override the standard parameters from the ImagePath registry key.
|
||||
* Fixes for ntpdate:
|
||||
* [Bug 532] nptdate timeout is too long if several servers are supplied.
|
||||
* [Bug 698] timeBeginPeriod is called without timeEndPeriod in some NTP tools.
|
||||
* [Bug 857] ntpdate debug mode adjusts system clock when it shouldn't.
|
||||
* [Bug 908] ntpdate crashes sometimes.
|
||||
* [Bug 982] ntpdate(and ntptimeset) buffer overrun if HAVE_POLL_H isn't set
|
||||
(dup of 908).
|
||||
* [Bug 997] ntpdate buffer too small and unsafe.
|
||||
* ntpdate.c: Under Windows check whether NTP port in use under same conditions
|
||||
as under other OSs.
|
||||
* ntpdate.c: Fixed some typos and indents (tabs/spaces).
|
||||
|
||||
---
|
||||
(4.2.4p4) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 902] Fix problems with the -6 flag.
|
||||
* Updated include/copyright.def (owner and year).
|
||||
* [Bug 878] Avoid ntpdc use of refid value as unterminated string.
|
||||
* [Bug 881] Corrected display of pll offset on 64bit systems.
|
||||
* [Bug 886] Corrected sign handling on 64bit in ntpdc loopinfo command.
|
||||
* [Bug 889] avoid malloc() interrupted by SIGIO risk
|
||||
* ntpd/refclock_parse.c: cleanup shutdown while the file descriptor is still open.
|
||||
* [Bug 885] use emalloc() to get a message at the end of the memory
|
||||
unsigned types cannot be less than 0
|
||||
default_ai_family is a short
|
||||
lose trailing , from enum list
|
||||
clarify ntp_restrict.c for easier automated analysis
|
||||
* [Bug 884] don't access recv buffers after having them passed to the free list.
|
||||
* [Bug 882] allow loopback interfaces to share addresses with other interfaces.
|
||||
|
||||
---
|
||||
(4.2.4p3) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 863] unable to stop ntpd on Windows as the handle reference for events
|
||||
changed
|
||||
|
||||
---
|
||||
(4.2.4p2) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 854] Broadcast address was not correctly set for interface addresses
|
||||
* [Bug 829] reduce syslog noise, while there fix Enabled/Disable logging
|
||||
to reflect the actual configuration.
|
||||
* [Bug 795] Moved declaration of variable to top of function.
|
||||
* [Bug 789] Fix multicast client crypto authentication and make sure arriving
|
||||
multicast packets do not disturb the autokey dance.
|
||||
* [Bug 785] improve handling of multicast interfaces
|
||||
(multicast routers still need to run a multicast routing
|
||||
software/daemon)
|
||||
* [Bug 527] Don't write from source address length to wrong location
|
||||
* Upgraded autogen and libopts.
|
||||
* [Bug 811] ntpd should not read a .ntprc file.
|
||||
|
||||
---
|
||||
(4.2.4p1) (skipped)
|
||||
|
||||
---
|
||||
(4.2.4p0) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 793] Update Hans Lambermont's email address in ntpsweep.
|
||||
* [Bug 776] Remove unimplemented "rate" flag from ntpdate.
|
||||
* [Bug 586] Avoid lookups if AI_NUMERICHOST is set.
|
||||
* [Bug 770] Fix numeric parameters to ntp-keygen (Alain Guibert).
|
||||
* [Bug 768] Fix io_setbclient() error message.
|
||||
* [Bug 765] Use net_bind_service capability on linux.
|
||||
* [Bug 760] The background resolver must be aware of the 'dynamic' keyword.
|
||||
* [Bug 753] make union timestamp anonymous (Philip Prindeville).
|
||||
* confopt.html: move description for "dynamic" keyword into the right section.
|
||||
* pick the right type for the recv*() length argument.
|
||||
|
||||
---
|
||||
(4.2.4) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* monopt.html fixes from Dave Mills.
|
||||
* [Bug 452] Do not report kernel PLL/FLL flips.
|
||||
* [Bug 746] Expert mouseCLOCK USB v2.0 support added.'
|
||||
* driver8.html updates.
|
||||
* [Bug 747] Drop <NOBR> tags from ntpdc.html.
|
||||
* sntp now uses the returned precision to control decimal places.
|
||||
* sntp -u will use an unprivileged port for its queries.
|
||||
* [Bug 741] "burst" doesn't work with !unfit peers.
|
||||
* [Bug 735] Fix a make/gmake VPATH issue on Solaris.
|
||||
* [Bug 739] ntpd -x should not take an argument.
|
||||
* [Bug 737] Some systems need help providing struct iovec.
|
||||
* [Bug 717] Fix libopts compile problem.
|
||||
* [Bug 728] parse documentation fixes.
|
||||
* [Bug 734] setsockopt(..., IP_MULTICAST_IF, ...) fails on 64-bit platforms.
|
||||
* [Bug 732] C-DEX JST2000 patch from Hideo Kuramatsu.
|
||||
* [Bug 721] check for __ss_family and __ss_len separately.
|
||||
* [Bug 666] ntpq opeers displays jitter rather than dispersion.
|
||||
* [Bug 718] Use the recommended type for the saddrlen arg to getsockname().
|
||||
* [Bug 715] Fix a multicast issue under Linux.
|
||||
* [Bug 690] Fix a Windows DNS lookup buffer overflow.
|
||||
* [Bug 670] Resolved a Windows issue with the dynamic interface rescan code.
|
||||
* K&R C support is being deprecated.
|
||||
* [Bug 714] ntpq -p should conflict with -i, not -c.
|
||||
* WWV refclock improvements from Dave Mills.
|
||||
* [Bug 708] Use thread affinity only for the clock interpolation thread.
|
||||
* [Bug 706] ntpd can be running several times in parallel.
|
||||
* [Bug 704] Documentation typos.
|
||||
* [Bug 701] coverity: NULL dereference in ntp_peer.c
|
||||
* [Bug 695] libopts does not protect against macro collisions.
|
||||
* [Bug 693] __adjtimex is independent of ntp_{adj,get}time.
|
||||
* [Bug 692] sys_limitrejected was not being incremented.
|
||||
* [Bug 691] restrictions() assumption not always valid.
|
||||
* [Bug 689] Deprecate HEATH GC-1001 II; the driver never worked.
|
||||
* [Bug 688] Fix documentation typos.
|
||||
* [Bug 686] Handle leap seconds better under Windows.
|
||||
* [Bug 685] Use the Windows multimedia timer.
|
||||
* [Bug 684] Only allow debug options if debugging is enabled.
|
||||
* [Bug 683] Use the right version string.
|
||||
* [Bug 680] Fix the generated version string on Windows.
|
||||
* [Bug 678] Use the correct size for control messages.
|
||||
* [Bug 677] Do not check uint_t in configure.ac.
|
||||
* [Bug 676] Use the right value for msg_namelen.
|
||||
* [Bug 675] Make sure ntpd builds without debugging.
|
||||
* [Bug 672] Fix cross-platform structure padding/size differences.
|
||||
* [Bug 660] New TIMESTAMP code fails tp build on Solaris Express.
|
||||
* [Bug 659] libopts does not build under Windows.
|
||||
* [Bug 658] HP-UX with cc needs -Wp,-H8166 in CFLAGS.
|
||||
* [Bug 656] ntpdate doesn't work with multicast address.
|
||||
* [Bug 638] STREAMS_TLI is deprecated - remove it.
|
||||
* [Bug 635] Fix tOptions definition.
|
||||
* [Bug 628] Fallback to ntp discipline not working for large offsets.
|
||||
* [Bug 622] Dynamic interface tracking for ntpd.
|
||||
* [Bug 603] Don't link with libelf if it's not needed.
|
||||
* [Bug 523] ntpd service under Windows does't shut down properly.
|
||||
* [Bug 500] sntp should always be built.
|
||||
* [Bug 479] Fix the -P option.
|
||||
* [Bug 421] Support the bc637PCI-U card.
|
||||
* [Bug 342] Deprecate broken TRAK refclock driver.
|
||||
* [Bug 340] Deprecate broken MSF EES refclock driver.
|
||||
* [Bug 153] Don't do DNS lookups on address masks.
|
||||
* [Bug 143] Fix interrupted system call on HP-UX.
|
||||
* [Bug 42] Distribution tarballs should be signed.
|
||||
* Support separate PPS devices for PARSE refclocks.
|
||||
* [Bug 637, 51?] Dynamic interface scanning can now be done.
|
||||
* Options processing now uses GNU AutoGen.
|
||||
|
||||
---
|
||||
(4.2.2p4) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* [Bug 710] compat getnameinfo() has off-by-one error
|
||||
* [Bug 690] Buffer overflow in Windows when doing DNS Lookups
|
||||
|
||||
---
|
||||
(4.2.2p3) Released by Harlan Stenn <stenn@ntp.org>
|
||||
|
||||
* Make the ChangeLog file cleaner and easier to read
|
||||
* [Bug 601] ntpq's decodeint uses an extra level of indirection
|
||||
* [Bug 657] Different OSes need different sized args for IP_MULTICAST_LOOP
|
||||
* release engineering/build changes
|
||||
* Documentation fixes
|
||||
* Get sntp working under AIX-5
|
||||
|
||||
---
|
||||
(4.2.2p2) (broken)
|
||||
|
||||
* Get sntp working under AIX-5
|
||||
|
||||
---
|
||||
(4.2.2p1)
|
||||
|
||||
* [Bug 661] Use environment variable to specify the base path to openssl.
|
||||
* Resolve an ambiguity in the copyright notice
|
||||
* Added some new documentation files
|
||||
* URL cleanup in the documentation
|
||||
* [Bug 657]: IP_MULTICAST_LOOP uses a u_char value/size
|
||||
* quiet gcc4 complaints
|
||||
* more Coverity fixes
|
||||
* [Bug 614] manage file descriptors better
|
||||
* [Bug 632] update kernel PPS offsets when PPS offset is re-configured
|
||||
* [Bug 637] Ignore UP in*addr_any interfaces
|
||||
* [Bug 633] Avoid writing files in srcdir
|
||||
* release engineering/build changes
|
||||
|
||||
---
|
||||
(4.2.2)
|
||||
|
||||
* SNTP
|
||||
* Many bugfixes
|
||||
* Implements the current "goal state" of NTPv4
|
||||
* Autokey improvements
|
||||
* Much better IPv6 support
|
||||
* [Bug 360] ntpd loses handles with LAN connection disabled.
|
||||
* [Bug 239] Fix intermittent autokey failure with multicast clients.
|
||||
* Rewrite of the multicast code
|
||||
* New version numbering scheme
|
||||
|
||||
---
|
||||
(4.2.0)
|
||||
|
||||
* More stuff than I have time to document
|
||||
* IPv6 support
|
||||
* Bugfixes
|
||||
* call-gap filtering
|
||||
* wwv and chu refclock improvements
|
||||
* OpenSSL integration
|
||||
|
||||
---
|
||||
(4.1.2)
|
||||
|
||||
* clock state machine bugfix
|
||||
* Lose the source port check on incoming packets
|
||||
* (x)ntpdc compatibility patch
|
||||
* Virtual IP improvements
|
||||
* ntp_loopfilter fixes and improvements
|
||||
* ntpdc improvements
|
||||
* GOES refclock fix
|
||||
* JJY driver
|
||||
* Jupiter refclock fixes
|
||||
* Neoclock4X refclock fixes
|
||||
* AIX 5 port
|
||||
* bsdi port fixes
|
||||
* Cray unicos port upgrade
|
||||
* HP MPE/iX port
|
||||
* Win/NT port upgrade
|
||||
* Dynix PTX port fixes
|
||||
* Document conversion from CVS to BK
|
||||
* readline support for ntpq
|
||||
|
||||
---
|
||||
(4.1.0)
|
||||
|
||||
* CERT problem fixed (99k23)
|
||||
|
||||
* Huff-n-Puff filter
|
||||
* Preparation for OpenSSL support
|
||||
* Resolver changes/improvements are not backward compatible with mode 7
|
||||
requests (which are implementation-specific anyway)
|
||||
* leap second stuff
|
||||
* manycast should work now
|
||||
* ntp-genkeys does new good things.
|
||||
* scripts/ntp-close
|
||||
* PPS cleanup and improvements
|
||||
* readline support for ntpdc
|
||||
* Crypto/authentication rewrite
|
||||
* WINNT builds with MD5 by default
|
||||
* WINNT no longer requires Perl for building with Visual C++ 6.0
|
||||
* algorithmic improvements, bugfixes
|
||||
* Solaris dosynctodr info update
|
||||
* html/pic/* is *lots* smaller
|
||||
* New/updated drivers: Forum Graphic GPS, WWV/H, Heath GC-100 II, HOPF
|
||||
serial and PCI, ONCORE, ulink331
|
||||
* Rewrite of the audio drivers
|
||||
|
||||
---
|
||||
(4.0.99)
|
||||
|
||||
* Driver updates: CHU, DCF, GPS/VME, Oncore, PCF, Ulink, WWVB, burst
|
||||
If you use the ONCORE driver with a HARDPPS kernel module,
|
||||
you *must* have a properly specified:
|
||||
pps <filename> [assert/clear] [hardpps]
|
||||
line in the /etc/ntp.conf file.
|
||||
* PARSE cleanup
|
||||
* PPS cleanup
|
||||
* ntpd, ntpq, ntpdate cleanup and fixes
|
||||
* NT port improvements
|
||||
* AIX, BSDI, DEC OSF, FreeBSD, NetBSD, Reliant, SCO, Solaris port improvements
|
||||
|
||||
---
|
||||
(4.0.98)
|
||||
|
||||
* Solaris kernel FLL bug is fixed in 106541-07
|
||||
* Bug/lint cleanup
|
||||
* PPS cleanup
|
||||
* ReliantUNIX patches
|
||||
* NetInfo support
|
||||
* Ultralink driver
|
||||
* Trimble OEM Ace-II support
|
||||
* DCF77 power choices
|
||||
* Oncore improvements
|
||||
|
||||
---
|
||||
(4.0.97)
|
||||
|
||||
* NT patches
|
||||
* AIX,SunOS,IRIX portability
|
||||
* NeXT portability
|
||||
* ntptimeset utility added
|
||||
* cygwin portability patches
|
||||
|
||||
---
|
||||
(4.0.96)
|
||||
|
||||
* -lnsl, -lsocket, -lgen configuration patches
|
||||
* Y2K patches from AT&T
|
||||
* Linux portability cruft
|
||||
|
||||
---
|
||||
(4.0.95)
|
||||
|
||||
* NT port cleanup/replacement
|
||||
* a few portability fixes
|
||||
* VARITEXT Parse clock added
|
||||
|
||||
---
|
||||
(4.0.94)
|
||||
|
||||
* PPS updates (including ntp.config options)
|
||||
* Lose the old DES stuff in favor of the (optional) RSAREF stuff
|
||||
* html cleanup/updates
|
||||
* numerous drivers cleaned up
|
||||
* numerous portability patches and code cleanup
|
||||
|
||||
---
|
||||
(4.0.93)
|
||||
|
||||
* Oncore refclock needs PPS or one of two ioctls.
|
||||
* Don't make ntptime under Linux. It doesn't compile for too many folks.
|
||||
* Autokey cleanup
|
||||
* ReliantUnix patches
|
||||
* html cleanup
|
||||
* tickadj cleanup
|
||||
* PARSE cleanup
|
||||
* IRIX -n32 cleanup
|
||||
* byte order cleanup
|
||||
* ntptrace improvements and patches
|
||||
* ntpdc improvements and patches
|
||||
* PPS cleanup
|
||||
* mx4200 cleanup
|
||||
* New clock state machine
|
||||
* SCO cleanup
|
||||
* Skip alias interfaces
|
||||
|
||||
---
|
||||
(4.0.92)
|
||||
|
||||
* chronolog and dumbclock refclocks
|
||||
* SCO updates
|
||||
* Cleanup/bugfixes
|
||||
* Y2K patches
|
||||
* Updated palisade driver
|
||||
* Plug memory leak
|
||||
* wharton kernel clock
|
||||
* Oncore clock upgrades
|
||||
* NMEA clock improvements
|
||||
* PPS improvements
|
||||
* AIX portability patches
|
||||
|
||||
---
|
||||
(4.0.91)
|
||||
|
||||
* New ONCORE driver
|
||||
* New MX4200 driver
|
||||
* Palisade improvements
|
||||
* config file bugfixes and problem reporting
|
||||
* autoconf upgrade and cleanup
|
||||
* HP-UX, IRIX lint cleanup
|
||||
* AIX portability patches
|
||||
* NT cleanup
|
||||
|
||||
---
|
||||
(4.0.90)
|
||||
|
||||
* Nanoseconds
|
||||
* New palisade driver
|
||||
* New Oncore driver
|
||||
|
||||
---
|
||||
(4.0.73)
|
||||
|
||||
* README.hackers added
|
||||
* PARSE driver is working again
|
||||
* Solaris 2.6 has nasty kernel bugs. DO NOT enable pll!
|
||||
* DES is out of the distribution.
|
||||
|
||||
---
|
||||
(4.0.72)
|
||||
|
||||
* K&R C compiling should work again.
|
||||
* IRIG patches.
|
||||
* MX4200 driver patches.
|
||||
* Jupiter driver added.
|
||||
* Palisade driver added. Needs work (ANSI, ntoh/hton, sizeof double, ???)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue