Merge libpcap-0.2.1.
Includes numerous improvements (see CHANGES), fixes PR bin/2031.
This commit is contained in:
parent
2b79ace362
commit
f17c8ad1a1
|
@ -1,5 +1,154 @@
|
|||
$NetBSD: CHANGES,v 1.2 1995/03/06 11:37:58 mycroft Exp $
|
||||
@(#) Header: CHANGES,v 1.4 94/06/20 19:22:33 leres Exp (LBL)
|
||||
$NetBSD: CHANGES,v 1.3 1996/12/13 08:25:54 mikel Exp $
|
||||
@(#) Header: CHANGES,v 1.34 96/07/23 14:36:14 leres Exp (LBL)
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
CHANGES
|
||||
FILES
|
||||
INSTALL
|
||||
Makefile.in
|
||||
README
|
||||
SUNOS4
|
||||
VERSION
|
||||
aclocal.m4
|
||||
bpf/net/bpf.h
|
||||
bpf/net/bpf_filter.c
|
||||
bpf_image.c
|
||||
config.guess
|
||||
config.sub
|
||||
configure
|
||||
configure.in
|
||||
etherent.c
|
||||
ethertype.h
|
||||
gencode.c
|
||||
gencode.h
|
||||
grammar.y
|
||||
inet.c
|
||||
install-sh
|
||||
lbl/gnuc.h
|
||||
lbl/os-solaris2.h
|
||||
lbl/os-sunos4.h
|
||||
mkdep
|
||||
nametoaddr.c
|
||||
optimize.c
|
||||
pcap-bpf.c
|
||||
pcap-dlpi.c
|
||||
pcap-enet.c
|
||||
pcap-int.h
|
||||
pcap-namedb.h
|
||||
pcap-nit.c
|
||||
pcap-nit.h
|
||||
pcap-null.c
|
||||
pcap-pf.c
|
||||
pcap-pf.h
|
||||
pcap-snit.c
|
||||
pcap-snoop.c
|
||||
pcap.3
|
||||
pcap.c
|
||||
pcap.h
|
||||
savefile.c
|
||||
scanner.l
|
|
@ -1,9 +1,16 @@
|
|||
# $NetBSD: Makefile,v 1.5 1996/10/18 05:45:04 thorpej Exp $
|
||||
# $NetBSD: Makefile,v 1.6 1996/12/13 08:25:56 mikel Exp $
|
||||
|
||||
LIB= pcap
|
||||
MAN= pcap.3
|
||||
|
||||
CFLAGS+=-I. -I${.CURDIR} -DFDDI
|
||||
LEX= flex
|
||||
|
||||
CFLAGS+=-I. -I${.CURDIR} -DYYBISON
|
||||
CFLAGS+=-DHAVE_MALLOC_H=1 -DHAVE_SYS_IOCCOM_H=1 -DHAVE_SYS_SOCKIO_H=1
|
||||
CFLAGS+=-DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_SOCKADDR_SA_LEN=1
|
||||
CFLAGS+=-DLBL_ALIGN=1
|
||||
LFLAGS+=-olex.yy.c -Ppcap_
|
||||
YFLAGS+=-ppcap_
|
||||
|
||||
HDRS= pcap.h pcap-namedb.h
|
||||
SRCS= pcap.c inet.c gencode.c optimize.c nametoaddr.c etherent.c \
|
||||
|
@ -23,3 +30,5 @@ includes:
|
|||
done
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
||||
.depend: grammar.c scanner.c
|
||||
|
|
|
@ -1,39 +1,28 @@
|
|||
$NetBSD: README,v 1.2 1995/03/06 11:38:07 mycroft Exp $
|
||||
@(#) Header: README,v 1.7 94/06/20 18:56:55 leres Exp (LBL)
|
||||
$NetBSD: README,v 1.3 1996/12/13 08:25:56 mikel Exp $
|
||||
@(#) Header: README,v 1.15 96/07/07 22:38:34 leres Exp (LBL)
|
||||
|
||||
LIBPCAP 0.0
|
||||
Lawrence Berkeley Laboratory
|
||||
LIBPCAP 0.2.1
|
||||
Lawrence Berkeley National Laboratory
|
||||
Network Research Group
|
||||
libpcap@ee.lbl.gov
|
||||
ftp://ftp.ee.lbl.gov/libpcap-*.tar.Z
|
||||
ftp://ftp.ee.lbl.gov/libpcap.tar.Z
|
||||
|
||||
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
|
||||
these interfaces, 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.
|
||||
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.
|
||||
|
||||
THIS IS AN ALPHA-QUALITY RELEASE. The interface is brand new and is
|
||||
likely to change. If you code to this interface, and want to track
|
||||
future versions, be prepared to update your code. We admit that this
|
||||
release is premature, but we're releasing it anyway because the tcpdump-3.0
|
||||
distribution requires it.
|
||||
|
||||
libpcap has been built and tested under SGI Irix 4.x & 5.2, SunOS 4.x,
|
||||
Solaris 2.3, BSD/386 v1.1, DEC/OSF v1.3 v2.0, and Ultrix 4.x. SunOS 3.5
|
||||
4.3BSD Reno/Tahoe and 4.4BSD are supported as well, but we currently
|
||||
do not have the resources to carry out testing in these environments
|
||||
(we suspect you'll run into problems under these systems -- please
|
||||
send us the patches if you fix any porting problems).
|
||||
Note well: this interface is new and is likely to change.
|
||||
|
||||
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 is in
|
||||
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 is in:
|
||||
|
||||
ftp://ftp.ee.lbl.gov/papers/bpf-usenix93.ps.Z.
|
||||
|
||||
|
@ -41,22 +30,21 @@ 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). We haven't tried
|
||||
taking advantage of other packet filter models first because they
|
||||
aren't general enough (i.e., only simple filters can be evaluated),
|
||||
and second because we don't have the time to modify the code generator
|
||||
(or write a filter translator) and BPF is more efficient anyway.
|
||||
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/386, NetBSD, and FreeBSD. DEC OSF/1
|
||||
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
|
||||
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.
|
||||
ftp://gatekeeper.dec.com/pub/DEC/net/bpfext42.tar.Z.
|
||||
|
||||
Please send bugs and comments to libpcap@ee.lbl.gov.
|
||||
Problems, bugs, questions, desirable enhancements, source code
|
||||
contributions, etc., should be sent to the email address
|
||||
"libpcap@ee.lbl.gov".
|
||||
|
||||
- Steve McCanne (mccanne@ee.lbl.gov)
|
||||
Craig Leres (leres@ee.lbl.gov)
|
||||
Van Jacobson (van@ee.lbl.gov)
|
||||
- Steve McCanne
|
||||
Craig Leres
|
||||
Van Jacobson
|
||||
|
|
|
@ -1,505 +0,0 @@
|
|||
dnl @(#) $Header: /cvsroot/src/lib/libpcap/Attic/aclocal.m4,v 1.1.1.1 1996/12/11 08:15:27 mikel Exp $ (LBL)
|
||||
dnl
|
||||
dnl Copyright (c) 1995, 1996
|
||||
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 ac_cv_gcc_vers
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_C_INIT,
|
||||
[$1=-O
|
||||
$2=""
|
||||
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
|
||||
AC_PROG_CC
|
||||
if test $ac_cv_prog_gcc = yes ; then
|
||||
if test "$SHLICC2" = yes ; then
|
||||
ac_cv_gcc_vers=2
|
||||
$1=-O2
|
||||
else
|
||||
AC_MSG_CHECKING(gcc version)
|
||||
AC_CACHE_VAL(ac_cv_gcc_vers,
|
||||
ac_cv_gcc_vers=`$CC -v 2>&1 | \
|
||||
sed -n -e '$s/.* //' -e '$s/\..*//p'`)
|
||||
AC_MSG_RESULT($ac_cv_gcc_vers)
|
||||
if test $ac_cv_gcc_vers -gt 1 ; then
|
||||
$1=-O2
|
||||
fi
|
||||
fi
|
||||
else
|
||||
AC_MSG_CHECKING(that $CC handles ansi prototypes)
|
||||
AC_CACHE_VAL(ac_cv_cc_ansi_prototypes,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[int frob(int, char *)],
|
||||
ac_cv_cc_ansi_prototypes=yes,
|
||||
ac_cv_cc_ansi_prototypes=no))
|
||||
AC_MSG_RESULT($ac_cv_cc_ansi_prototypes)
|
||||
if test $ac_cv_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_cc_hpux_cc_aa,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[int frob(int, char *)],
|
||||
ac_cv_cc_hpux_cc_aa=yes,
|
||||
ac_cv_cc_hpux_cc_aa=no))
|
||||
AC_MSG_RESULT($ac_cv_cc_hpux_cc_aa)
|
||||
if test $ac_cv_cc_hpux_cc_aa = no ; then
|
||||
AC_MSG_ERROR(see the INSTALL for more info)
|
||||
fi
|
||||
CFLAGS="$savedcflags"
|
||||
V_CCOPT="-Aa $V_CCOPT"
|
||||
AC_DEFINE(_HPUX_SOURCE)
|
||||
;;
|
||||
|
||||
sni*)
|
||||
AC_MSG_CHECKING(for SINIX ansi compiler ($CC -kansi))
|
||||
savedcflags="$CFLAGS"
|
||||
CFLAGS="-kansi"
|
||||
AC_CACHE_VAL(ac_cv_cc_sinix_kansi,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[int frob(int, char *)],
|
||||
ac_cv_cc_sinix_kansi=yes,
|
||||
ac_cv_cc_sinix_kansi=no))
|
||||
AC_MSG_RESULT($ac_cv_cc_sinix_kansi)
|
||||
if test $ac_cv_cc_sinix_kansi = no ; then
|
||||
AC_MSG_ERROR(see the INSTALL for more info)
|
||||
fi
|
||||
CFLAGS="$savedcflags"
|
||||
V_CCOPT="-kansi $V_CCOPT"
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_ERROR(see the INSTALL for more info)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
$2=-I/usr/local/include
|
||||
|
||||
case "$target_os" in
|
||||
|
||||
irix*)
|
||||
V_CCOPT="$V_CCOPT -xansi -signed -g3"
|
||||
;;
|
||||
|
||||
osf*)
|
||||
V_CCOPT="$V_CCOPT -g3"
|
||||
;;
|
||||
|
||||
ultrix*)
|
||||
AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
|
||||
AC_CACHE_VAL(ac_cv_cc_const_proto,
|
||||
AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>],
|
||||
[struct a { int b; };
|
||||
void c(const struct a *)],
|
||||
ac_cv_cc_const_proto=yes,
|
||||
ac_cv_cc_const_proto=no))
|
||||
AC_MSG_RESULT($ac_cv_cc_const_proto)
|
||||
if test $ac_cv_cc_const_proto = no ; then
|
||||
AC_DEFINE(const,)
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
|
||||
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
|
||||
AC_DEFUN(AC_LBL_LIBPCAP,
|
||||
[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
|
||||
places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
|
||||
egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
|
||||
for dir in ../libpcap $places libpcap ; do
|
||||
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"])
|
||||
|
||||
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_TYPE_SIGNAL
|
||||
if test "$ac_cv_type_signal" = void ; then
|
||||
AC_DEFINE(RETSIGVAL,)
|
||||
else
|
||||
AC_DEFINE(RETSIGVAL,(0))
|
||||
fi
|
||||
case "$target_os" in
|
||||
|
||||
irix*)
|
||||
AC_DEFINE(_BSD_SIGNALS)
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_CHECK_FUNCS(sigset)
|
||||
if test $ac_cv_func_sigset = yes ; then
|
||||
AC_DEFINE(signal, sigset)
|
||||
fi
|
||||
;;
|
||||
esac])
|
||||
|
||||
dnl
|
||||
dnl If using gcc, see if fixincludes should be run
|
||||
dnl
|
||||
dnl usage:
|
||||
dnl
|
||||
dnl AC_LBL_FIXINCLUDES
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_FIXINCLUDES,
|
||||
[if test $ac_cv_prog_gcc = yes ; then
|
||||
AC_MSG_CHECKING(if fixincludes is needed)
|
||||
AC_CACHE_VAL(ac_cv_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_gcc_fixincludes=yes,
|
||||
ac_cv_gcc_fixincludes=no))
|
||||
AC_MSG_RESULT($ac_cv_gcc_fixincludes)
|
||||
if test $ac_cv_gcc_fixincludes = no ; then
|
||||
# Don't cache failure
|
||||
unset ac_cv_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_CHECK_PROGS($1, flex, lex)
|
||||
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_flex_v24,
|
||||
if flex -V >/dev/null 2>&1; then
|
||||
ac_cv_flex_v24=yes
|
||||
else
|
||||
ac_cv_flex_v24=no
|
||||
fi)
|
||||
AC_MSG_RESULT($ac_cv_flex_v24)
|
||||
if test $ac_cv_flex_v24 = no ; then
|
||||
s="2.4 or higher required"
|
||||
AC_MSG_WARN(ignoring obsolete flex executable ($s))
|
||||
$1=lex
|
||||
fi
|
||||
fi
|
||||
AC_CHECK_PROGS($2, bison, yacc)
|
||||
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_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_union_wait=no,
|
||||
ac_cv_union_wait=yes))
|
||||
AC_MSG_RESULT($ac_cv_union_wait)
|
||||
if test $ac_cv_union_wait = yes ; then
|
||||
AC_DEFINE(DECLWAITSTATUS,union wait)
|
||||
else
|
||||
AC_DEFINE(DECLWAITSTATUS,int)
|
||||
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_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_sockaddr_has_sa_len=yes,
|
||||
ac_cv_sockaddr_has_sa_len=no))
|
||||
AC_MSG_RESULT($ac_cv_sockaddr_has_sa_len)
|
||||
if test $ac_cv_sockaddr_has_sa_len = yes ; then
|
||||
AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
|
||||
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_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_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_have_run_path=yes
|
||||
else
|
||||
ac_cv_have_run_path=no
|
||||
fi
|
||||
rm -f conftest*])
|
||||
AC_MSG_RESULT($ac_cv_have_run_path)
|
||||
])
|
||||
|
||||
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_unaligned_fail,
|
||||
[case "$target_cpu" in
|
||||
|
||||
alpha|hp*|mips|sparc)
|
||||
ac_cv_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_unaligned_fail=yes
|
||||
else
|
||||
./conftest >conftest.out
|
||||
if test ! -s conftest.out ; then
|
||||
ac_cv_unaligned_fail=yes
|
||||
else
|
||||
ac_cv_unaligned_fail=no
|
||||
fi
|
||||
fi
|
||||
rm -f conftest* core core.conftest
|
||||
;;
|
||||
esac])
|
||||
AC_MSG_RESULT($ac_cv_unaligned_fail)
|
||||
if test $ac_cv_unaligned_fail = yes ; then
|
||||
AC_DEFINE(LBL_ALIGN)
|
||||
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 $ac_cv_prog_gcc = yes -a -f .devel ; then
|
||||
if test $ac_cv_prog_gcc_g = yes ; then
|
||||
$1="-g $$1"
|
||||
fi
|
||||
$1="$$1 -Wall"
|
||||
if test $ac_cv_gcc_vers -gt 1 ; then
|
||||
$1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
|
||||
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)
|
||||
else
|
||||
AC_MSG_WARN(can't find $name)
|
||||
fi
|
||||
fi])
|
|
@ -1,257 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
||||
* 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/lib/libpcap/bpf/net/Attic/bpf.h,v 1.1.1.1 1996/12/11 08:15:50 mikel Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef BPF_MAJOR_VERSION
|
||||
|
||||
/* BSD style release date */
|
||||
#define BPF_RELEASE 199606
|
||||
|
||||
typedef int bpf_int32;
|
||||
typedef u_int bpf_u_int32;
|
||||
|
||||
/*
|
||||
* Alignment macros. BPF_WORDALIGN rounds up to the next
|
||||
* even multiple of BPF_ALIGNMENT.
|
||||
*/
|
||||
#define BPF_ALIGNMENT sizeof(bpf_int32)
|
||||
#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 BIOCSETF.
|
||||
*/
|
||||
struct bpf_program {
|
||||
u_int bf_len;
|
||||
struct bpf_insn *bf_insns;
|
||||
};
|
||||
|
||||
/*
|
||||
* Struct returned by BIOCGSTATS.
|
||||
*/
|
||||
struct bpf_stat {
|
||||
u_int bs_recv; /* number of packets received */
|
||||
u_int bs_drop; /* number of packets dropped */
|
||||
};
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
/*
|
||||
* BPF ioctls
|
||||
*
|
||||
* The first set is for compatibility with Sun's pcc style
|
||||
* header files. If your using gcc, we assume that you
|
||||
* have run fixincludes so the latter set should work.
|
||||
*/
|
||||
#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
|
||||
#define BIOCGBLEN _IOR(B,102, u_int)
|
||||
#define BIOCSBLEN _IOWR(B,102, u_int)
|
||||
#define BIOCSETF _IOW(B,103, struct bpf_program)
|
||||
#define BIOCFLUSH _IO(B,104)
|
||||
#define BIOCPROMISC _IO(B,105)
|
||||
#define BIOCGDLT _IOR(B,106, u_int)
|
||||
#define BIOCGETIF _IOR(B,107, struct ifreq)
|
||||
#define BIOCSETIF _IOW(B,108, struct ifreq)
|
||||
#define BIOCSRTIMEOUT _IOW(B,109, struct timeval)
|
||||
#define BIOCGRTIMEOUT _IOR(B,110, struct timeval)
|
||||
#define BIOCGSTATS _IOR(B,111, struct bpf_stat)
|
||||
#define BIOCIMMEDIATE _IOW(B,112, u_int)
|
||||
#define BIOCVERSION _IOR(B,113, struct bpf_version)
|
||||
#else
|
||||
#define BIOCGBLEN _IOR('B',102, u_int)
|
||||
#define BIOCSBLEN _IOWR('B',102, u_int)
|
||||
#define BIOCSETF _IOW('B',103, struct bpf_program)
|
||||
#define BIOCFLUSH _IO('B',104)
|
||||
#define BIOCPROMISC _IO('B',105)
|
||||
#define BIOCGDLT _IOR('B',106, u_int)
|
||||
#define BIOCGETIF _IOR('B',107, struct ifreq)
|
||||
#define BIOCSETIF _IOW('B',108, struct ifreq)
|
||||
#define BIOCSRTIMEOUT _IOW('B',109, struct timeval)
|
||||
#define BIOCGRTIMEOUT _IOR('B',110, struct timeval)
|
||||
#define BIOCGSTATS _IOR('B',111, struct bpf_stat)
|
||||
#define BIOCIMMEDIATE _IOW('B',112, u_int)
|
||||
#define BIOCVERSION _IOR('B',113, struct bpf_version)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure prepended to each packet.
|
||||
*/
|
||||
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) */
|
||||
};
|
||||
/*
|
||||
* Because the structure above is not a multiple of 4 bytes, some compilers
|
||||
* will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
|
||||
* Only the kernel needs to know about it; applications use bh_hdrlen.
|
||||
*/
|
||||
#ifdef KERNEL
|
||||
#define SIZEOF_BPF_HDR 18
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Data-link level type codes.
|
||||
*/
|
||||
#define DLT_NULL 0 /* no link-layer 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 */
|
||||
#define DLT_SLIP 8 /* Serial Line IP */
|
||||
#define DLT_PPP 9 /* Point-to-point Protocol */
|
||||
#define DLT_FDDI 10 /* FDDI */
|
||||
#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
|
||||
|
||||
/*
|
||||
* The instruction encondings.
|
||||
*/
|
||||
/* 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 }
|
||||
|
||||
#ifdef KERNEL
|
||||
extern u_int bpf_filter();
|
||||
extern void bpfattach();
|
||||
extern void bpf_tap();
|
||||
extern void bpf_mtap();
|
||||
#else
|
||||
#if __STDC__
|
||||
extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
|
||||
*/
|
||||
#define BPF_MEMWORDS 16
|
||||
|
||||
#endif
|
|
@ -1,534 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
||||
* 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
|
||||
*
|
||||
* static char rcsid[] =
|
||||
* "$Header: /cvsroot/src/lib/libpcap/bpf/net/Attic/bpf_filter.c,v 1.1.1.1 1996/12/11 08:15:50 mikel Exp $";
|
||||
*/
|
||||
#if !(defined(lint) || defined(KERNEL))
|
||||
static char rcsid[] =
|
||||
"@(#) $Header: /cvsroot/src/lib/libpcap/bpf/net/Attic/bpf_filter.c,v 1.1.1.1 1996/12/11 08:15:50 mikel Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <net/bpf.h>
|
||||
|
||||
#ifndef KERNEL
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define int32 bpf_int32
|
||||
#define u_int32 bpf_u_int32
|
||||
|
||||
#ifndef LBL_ALIGN
|
||||
#if defined(sparc) || defined(mips) || defined(ibm032) || \
|
||||
defined(__alpha) || defined(__hpux)
|
||||
#define LBL_ALIGN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LBL_ALIGN
|
||||
#include <netinet/in.h>
|
||||
|
||||
#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
|
||||
|
||||
#ifdef KERNEL
|
||||
#include <sys/mbuf.h>
|
||||
#define MINDEX(len, m, k) \
|
||||
{ \
|
||||
len = m->m_len; \
|
||||
while (k >= len) { \
|
||||
k -= len; \
|
||||
m = m->m_next; \
|
||||
if (m == 0) \
|
||||
return 0; \
|
||||
len = m->m_len; \
|
||||
} \
|
||||
}
|
||||
|
||||
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 || m0->m_len + 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
|
||||
*/
|
||||
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 (pc == 0)
|
||||
/*
|
||||
* No filter means accept all.
|
||||
*/
|
||||
return (u_int)-1;
|
||||
A = 0;
|
||||
X = 0;
|
||||
--pc;
|
||||
while (1) {
|
||||
++pc;
|
||||
switch (pc->code) {
|
||||
|
||||
default:
|
||||
#ifdef 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) {
|
||||
#ifdef KERNEL
|
||||
int merr;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
A = m_xword((struct mbuf *)p, 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) {
|
||||
#ifdef KERNEL
|
||||
int merr;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
A = m_xhalf((struct mbuf *)p, k, &merr);
|
||||
continue;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
A = EXTRACT_SHORT(&p[k]);
|
||||
continue;
|
||||
|
||||
case BPF_LD|BPF_B|BPF_ABS:
|
||||
k = pc->k;
|
||||
if (k >= buflen) {
|
||||
#ifdef KERNEL
|
||||
register struct mbuf *m;
|
||||
register int len;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
m = (struct mbuf *)p;
|
||||
MINDEX(len, m, k);
|
||||
A = mtod(m, 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) {
|
||||
#ifdef KERNEL
|
||||
int merr;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
A = m_xword((struct mbuf *)p, 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) {
|
||||
#ifdef KERNEL
|
||||
int merr;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
A = m_xhalf((struct mbuf *)p, 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) {
|
||||
#ifdef KERNEL
|
||||
register struct mbuf *m;
|
||||
register int len;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
m = (struct mbuf *)p;
|
||||
MINDEX(len, m, k);
|
||||
A = mtod(m, 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) {
|
||||
#ifdef KERNEL
|
||||
register struct mbuf *m;
|
||||
register int len;
|
||||
|
||||
if (buflen != 0)
|
||||
return 0;
|
||||
m = (struct mbuf *)p;
|
||||
MINDEX(len, m, k);
|
||||
X = (mtod(m, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KERNEL
|
||||
/*
|
||||
* 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 >= 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;
|
||||
}
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: bpf_image.c,v 1.2 1995/03/06 11:38:11 mycroft Exp $ */
|
||||
/* $NetBSD: bpf_image.c,v 1.3 1996/12/13 08:25:58 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1994
|
||||
* 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
|
||||
|
@ -23,18 +23,22 @@
|
|||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: bpf_image.c,v 1.12 94/01/31 03:22:34 leres Exp (LBL)";
|
||||
"@(#) Header: bpf_image.c,v 1.21 96/07/15 00:48:36 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <pcap.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
char *
|
||||
bpf_image(p, n)
|
||||
struct bpf_insn *p;
|
||||
|
@ -137,7 +141,7 @@ bpf_image(p, n)
|
|||
case BPF_JMP|BPF_JA:
|
||||
op = "ja";
|
||||
fmt = "%d";
|
||||
v = n + p->k;
|
||||
v = n + 1 + p->k;
|
||||
break;
|
||||
|
||||
case BPF_JMP|BPF_JGT|BPF_K:
|
||||
|
@ -242,12 +246,12 @@ bpf_image(p, n)
|
|||
|
||||
case BPF_ALU|BPF_AND|BPF_K:
|
||||
op = "and";
|
||||
fmt = "#%d";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_OR|BPF_K:
|
||||
op = "or";
|
||||
fmt = "#%d";
|
||||
fmt = "#0x%x";
|
||||
break;
|
||||
|
||||
case BPF_ALU|BPF_LSH|BPF_K:
|
||||
|
|
|
@ -1,600 +0,0 @@
|
|||
#! /bin/sh
|
||||
# Attempt to guess a canonical system name.
|
||||
# Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Written by Per Bothner <bothner@cygnus.com>.
|
||||
# The master version of this file is at the FSF in /home/gd/gnu/lib.
|
||||
#
|
||||
# This script attempts to guess a canonical system name similar to
|
||||
# config.sub. If it succeeds, it prints the system name on stdout, and
|
||||
# exits with 0. Otherwise, it exits with 1.
|
||||
#
|
||||
# The plan is that this can be called by configure scripts if you
|
||||
# don't specify an explicit system type (host/target name).
|
||||
#
|
||||
# Only a few systems have been added to this list; please add others
|
||||
# (but try to keep the structure clean).
|
||||
#
|
||||
|
||||
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
|
||||
# (ghazi@noc.rutgers.edu 8/24/94.)
|
||||
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
|
||||
PATH=$PATH:/.attbin ; export PATH
|
||||
fi
|
||||
|
||||
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
|
||||
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
|
||||
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
|
||||
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
|
||||
|
||||
trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
|
||||
|
||||
# Note: order is significant - the case branches are not exclusive.
|
||||
|
||||
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
alpha:OSF1:*:*)
|
||||
# A Vn.n version is a released version.
|
||||
# A Tn.n version is a released field test version.
|
||||
# A Xn.n version is an unreleased experimental baselevel.
|
||||
# 1.2 uses "1.2" for uname -r.
|
||||
echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//'`
|
||||
exit 0 ;;
|
||||
21064:Windows_NT:50:3)
|
||||
echo alpha-dec-winnt3.5
|
||||
exit 0 ;;
|
||||
Amiga*:UNIX_System_V:4.0:*)
|
||||
echo m68k-cbm-sysv4
|
||||
exit 0;;
|
||||
amiga:NetBSD:*:*)
|
||||
echo m68k-cbm-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
|
||||
echo arm-acorn-riscix${UNAME_RELEASE}
|
||||
exit 0;;
|
||||
Pyramid*:OSx*:*:*)
|
||||
if test "`(/bin/universe) 2>/dev/null`" = att ; then
|
||||
echo pyramid-pyramid-sysv3
|
||||
else
|
||||
echo pyramid-pyramid-bsd
|
||||
fi
|
||||
exit 0 ;;
|
||||
sun4*:SunOS:5.*:*)
|
||||
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
i86pc:SunOS:5.*:*)
|
||||
echo i386-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
sun4*:SunOS:6*:*)
|
||||
# According to config.sub, this is the proper way to canonicalize
|
||||
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
|
||||
# it's likely to be more like Solaris than SunOS4.
|
||||
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
sun4*:SunOS:*:*)
|
||||
case "`/usr/bin/arch -k`" in
|
||||
Series*|S4*)
|
||||
UNAME_RELEASE=`uname -v`
|
||||
;;
|
||||
esac
|
||||
# Japanese Language versions have a version number like `4.1.3-JL'.
|
||||
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
|
||||
exit 0 ;;
|
||||
sun3*:SunOS:*:*)
|
||||
echo m68k-sun-sunos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
atari*:NetBSD:*:*)
|
||||
echo m68k-atari-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
sun3*:NetBSD:*:*)
|
||||
echo m68k-sun-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mac68k:NetBSD:*:*)
|
||||
echo m68k-apple-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
RISC*:ULTRIX:*:*)
|
||||
echo mips-dec-ultrix${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
VAX*:ULTRIX*:*:*)
|
||||
echo vax-dec-ultrix${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mips:*:4*:UMIPS)
|
||||
echo mips-mips-riscos4sysv
|
||||
exit 0 ;;
|
||||
mips:*:5*:RISCos)
|
||||
echo mips-mips-riscos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
Night_Hawk:Power_UNIX:*:*)
|
||||
echo powerpc-harris-powerunix
|
||||
exit 0 ;;
|
||||
m88k:CX/UX:7*:*)
|
||||
echo m88k-harris-cxux7
|
||||
exit 0 ;;
|
||||
m88k:*:4*:R4*)
|
||||
echo m88k-motorola-sysv4
|
||||
exit 0 ;;
|
||||
m88k:*:3*:R3*)
|
||||
echo m88k-motorola-sysv3
|
||||
exit 0 ;;
|
||||
AViiON:dgux:*:*)
|
||||
# DG/UX returns AViiON for all architectures
|
||||
UNAME_PROCESSOR=`/usr/bin/uname -p`
|
||||
if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88100 ] ; then
|
||||
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
|
||||
-o ${TARGET_BINARY_INTERFACE}x = x ] ; then
|
||||
echo m88k-dg-dgux${UNAME_RELEASE}
|
||||
else
|
||||
echo m88k-dg-dguxbcs${UNAME_RELEASE}
|
||||
fi
|
||||
else echo i586-dg-dgux${UNAME_RELEASE}
|
||||
fi
|
||||
exit 0 ;;
|
||||
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
|
||||
echo m88k-dolphin-sysv3
|
||||
exit 0 ;;
|
||||
M88*:*:R3*:*)
|
||||
# Delta 88k system running SVR3
|
||||
echo m88k-motorola-sysv3
|
||||
exit 0 ;;
|
||||
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
|
||||
echo m88k-tektronix-sysv3
|
||||
exit 0 ;;
|
||||
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
|
||||
echo m68k-tektronix-bsd
|
||||
exit 0 ;;
|
||||
*:IRIX*:*:*)
|
||||
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
|
||||
exit 0 ;;
|
||||
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
|
||||
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
|
||||
exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
|
||||
i[34]86:AIX:*:*)
|
||||
echo i386-ibm-aix
|
||||
exit 0 ;;
|
||||
*:AIX:2:3)
|
||||
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
|
||||
sed 's/^ //' << EOF >dummy.c
|
||||
#include <sys/systemcfg.h>
|
||||
|
||||
main()
|
||||
{
|
||||
if (!__power_pc())
|
||||
exit(1);
|
||||
puts("powerpc-ibm-aix3.2.5");
|
||||
exit(0);
|
||||
}
|
||||
EOF
|
||||
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
|
||||
rm -f dummy.c dummy
|
||||
echo rs6000-ibm-aix3.2.5
|
||||
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
|
||||
echo rs6000-ibm-aix3.2.4
|
||||
else
|
||||
echo rs6000-ibm-aix3.2
|
||||
fi
|
||||
exit 0 ;;
|
||||
*:AIX:*:4)
|
||||
if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then
|
||||
IBM_ARCH=rs6000
|
||||
else
|
||||
IBM_ARCH=powerpc
|
||||
fi
|
||||
if [ -x /usr/bin/oslevel ] ; then
|
||||
IBM_REV=`/usr/bin/oslevel`
|
||||
else
|
||||
IBM_REV=4.${UNAME_RELEASE}
|
||||
fi
|
||||
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
|
||||
exit 0 ;;
|
||||
*:AIX:*:*)
|
||||
echo rs6000-ibm-aix
|
||||
exit 0 ;;
|
||||
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
|
||||
echo romp-ibm-bsd4.4
|
||||
exit 0 ;;
|
||||
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
|
||||
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
|
||||
exit 0 ;; # report: romp-ibm BSD 4.3
|
||||
*:BOSX:*:*)
|
||||
echo rs6000-bull-bosx
|
||||
exit 0 ;;
|
||||
DPX/2?00:B.O.S.:*:*)
|
||||
echo m68k-bull-sysv3
|
||||
exit 0 ;;
|
||||
9000/[34]??:4.3bsd:1.*:*)
|
||||
echo m68k-hp-bsd
|
||||
exit 0 ;;
|
||||
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
|
||||
echo m68k-hp-bsd4.4
|
||||
exit 0 ;;
|
||||
9000/[3478]??:HP-UX:*:*)
|
||||
case "${UNAME_MACHINE}" in
|
||||
9000/31? ) HP_ARCH=m68000 ;;
|
||||
9000/[34]?? ) HP_ARCH=m68k ;;
|
||||
9000/7?? | 9000/8?[679] ) HP_ARCH=hppa1.1 ;;
|
||||
9000/8?? ) HP_ARCH=hppa1.0 ;;
|
||||
esac
|
||||
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
|
||||
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
|
||||
exit 0 ;;
|
||||
3050*:HI-UX:*:*)
|
||||
sed 's/^ //' << EOF >dummy.c
|
||||
#include <unistd.h>
|
||||
int
|
||||
main ()
|
||||
{
|
||||
long cpu = sysconf (_SC_CPU_VERSION);
|
||||
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
|
||||
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
|
||||
results, however. */
|
||||
if (CPU_IS_PA_RISC (cpu))
|
||||
{
|
||||
switch (cpu)
|
||||
{
|
||||
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
|
||||
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
|
||||
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
|
||||
default: puts ("hppa-hitachi-hiuxwe2"); break;
|
||||
}
|
||||
}
|
||||
else if (CPU_IS_HP_MC68K (cpu))
|
||||
puts ("m68k-hitachi-hiuxwe2");
|
||||
else puts ("unknown-hitachi-hiuxwe2");
|
||||
exit (0);
|
||||
}
|
||||
EOF
|
||||
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
|
||||
rm -f dummy.c dummy
|
||||
echo unknown-hitachi-hiuxwe2
|
||||
exit 0 ;;
|
||||
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
|
||||
echo hppa1.1-hp-bsd
|
||||
exit 0 ;;
|
||||
9000/8??:4.3bsd:*:*)
|
||||
echo hppa1.0-hp-bsd
|
||||
exit 0 ;;
|
||||
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
|
||||
echo hppa1.1-hp-osf
|
||||
exit 0 ;;
|
||||
hp8??:OSF1:*:*)
|
||||
echo hppa1.0-hp-osf
|
||||
exit 0 ;;
|
||||
parisc*:Lites*:*:*)
|
||||
echo hppa1.1-hp-lites
|
||||
exit 0 ;;
|
||||
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
|
||||
echo c1-convex-bsd
|
||||
exit 0 ;;
|
||||
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
|
||||
if getsysinfo -f scalar_acc
|
||||
then echo c32-convex-bsd
|
||||
else echo c2-convex-bsd
|
||||
fi
|
||||
exit 0 ;;
|
||||
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
|
||||
echo c34-convex-bsd
|
||||
exit 0 ;;
|
||||
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
|
||||
echo c38-convex-bsd
|
||||
exit 0 ;;
|
||||
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
|
||||
echo c4-convex-bsd
|
||||
exit 0 ;;
|
||||
CRAY*X-MP:*:*:*)
|
||||
echo xmp-cray-unicos
|
||||
exit 0 ;;
|
||||
CRAY*Y-MP:*:*:*)
|
||||
echo ymp-cray-unicos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
CRAY*C90:*:*:*)
|
||||
echo c90-cray-unicos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
CRAY-2:*:*:*)
|
||||
echo cray2-cray-unicos
|
||||
exit 0 ;;
|
||||
hp3[0-9][05]:NetBSD:*:*)
|
||||
echo m68k-hp-netbsd${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
i[34]86:BSD/386:*:* | *:BSD/OS:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
*:FreeBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
|
||||
exit 0 ;;
|
||||
*:NetBSD:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
|
||||
exit 0 ;;
|
||||
i*:CYGWIN*:*)
|
||||
echo i386-unknown-cygwin32
|
||||
exit 0 ;;
|
||||
p*:CYGWIN*:*)
|
||||
echo powerpcle-unknown-cygwin32
|
||||
exit 0 ;;
|
||||
prep*:SunOS:5.*:*)
|
||||
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit 0 ;;
|
||||
*:GNU:*:*)
|
||||
echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
|
||||
exit 0 ;;
|
||||
*:Linux:*:*)
|
||||
# The BFD linker knows what the default object file format is, so
|
||||
# first see if it will tell us.
|
||||
ld_help_string=`ld --help 2>&1`
|
||||
if echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf_i[345]86"; then
|
||||
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
|
||||
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86linux"; then
|
||||
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
|
||||
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86coff"; then
|
||||
echo "${UNAME_MACHINE}-unknown-linuxcoff" ; exit 0
|
||||
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68kelf"; then
|
||||
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
|
||||
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68klinux"; then
|
||||
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
|
||||
elif test "${UNAME_MACHINE}" = "alpha" ; then
|
||||
echo alpha-unknown-linux ; exit 0
|
||||
else
|
||||
# Either a pre-BFD a.out linker (linuxoldld) or one that does not give us
|
||||
# useful --help. Gcc wants to distinguish between linuxoldld and linuxaout.
|
||||
test ! -d /usr/lib/ldscripts/. \
|
||||
&& echo "${UNAME_MACHINE}-unknown-linuxoldld" && exit 0
|
||||
# Determine whether the default compiler is a.out or elf
|
||||
cat >dummy.c <<EOF
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
#ifdef __ELF__
|
||||
printf ("%s-unknown-linux\n", argv[1]);
|
||||
#else
|
||||
printf ("%s-unknown-linuxaout\n", argv[1]);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
|
||||
rm -f dummy.c dummy
|
||||
fi ;;
|
||||
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
|
||||
# are messed up and put the nodename in both sysname and nodename.
|
||||
i[34]86:DYNIX/ptx:4*:*)
|
||||
echo i386-sequent-sysv4
|
||||
exit 0 ;;
|
||||
i[34]86:*:4.*:* | i[34]86:SYSTEM_V:4.*:*)
|
||||
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
|
||||
echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
|
||||
else
|
||||
echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}
|
||||
fi
|
||||
exit 0 ;;
|
||||
i[34]86:*:3.2:*)
|
||||
if test -f /usr/options/cb.name; then
|
||||
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
|
||||
echo ${UNAME_MACHINE}-unknown-isc$UNAME_REL
|
||||
elif /bin/uname -X 2>/dev/null >/dev/null ; then
|
||||
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
|
||||
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
|
||||
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
|
||||
&& UNAME_MACHINE=i586
|
||||
echo ${UNAME_MACHINE}-unknown-sco$UNAME_REL
|
||||
else
|
||||
echo ${UNAME_MACHINE}-unknown-sysv32
|
||||
fi
|
||||
exit 0 ;;
|
||||
Intel:Mach:3*:*)
|
||||
echo i386-unknown-mach3
|
||||
exit 0 ;;
|
||||
paragon:*:*:*)
|
||||
echo i860-intel-osf1
|
||||
exit 0 ;;
|
||||
i860:*:4.*:*) # i860-SVR4
|
||||
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
|
||||
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
|
||||
else # Add other i860-SVR4 vendors below as they are discovered.
|
||||
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
|
||||
fi
|
||||
exit 0 ;;
|
||||
mini*:CTIX:SYS*5:*)
|
||||
# "miniframe"
|
||||
echo m68010-convergent-sysv
|
||||
exit 0 ;;
|
||||
M680[234]0:*:R3V[567]*:*)
|
||||
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
|
||||
3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0)
|
||||
uname -p 2>/dev/null | grep 86 >/dev/null \
|
||||
&& echo i486-ncr-sysv4.3 && exit 0 ;;
|
||||
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
|
||||
uname -p 2>/dev/null | grep 86 >/dev/null \
|
||||
&& echo i486-ncr-sysv4 && exit 0 ;;
|
||||
m680[234]0:LynxOS:2.[23]*:*)
|
||||
echo m68k-lynx-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
mc68030:UNIX_System_V:4.*:*)
|
||||
echo m68k-atari-sysv4
|
||||
exit 0 ;;
|
||||
i[34]86:LynxOS:2.[23]*:*)
|
||||
echo i386-lynx-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
TSUNAMI:LynxOS:2.[23]*:*)
|
||||
echo sparc-lynx-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
rs6000:LynxOS:2.[23]*:*)
|
||||
echo rs6000-lynx-lynxos${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
RM*:SINIX-*:*:*)
|
||||
echo mips-sni-sysv4
|
||||
exit 0 ;;
|
||||
*:SINIX-*:*:*)
|
||||
if uname -p 2>/dev/null >/dev/null ; then
|
||||
UNAME_MACHINE=`(uname -p) 2>/dev/null`
|
||||
echo ${UNAME_MACHINE}-sni-sysv4
|
||||
else
|
||||
echo ns32k-sni-sysv
|
||||
fi
|
||||
exit 0 ;;
|
||||
mc68*:A/UX:*:*)
|
||||
echo m68k-apple-aux${UNAME_RELEASE}
|
||||
exit 0 ;;
|
||||
R3000:*System_V*:*:*)
|
||||
if [ -d /usr/nec ]; then
|
||||
echo mips-nec-sysv${UNAME_RELEASE}
|
||||
else
|
||||
echo mips-unknown-sysv${UNAME_RELEASE}
|
||||
fi
|
||||
exit 0 ;;
|
||||
esac
|
||||
|
||||
#echo '(No uname command or uname output not recognized.)' 1>&2
|
||||
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
|
||||
|
||||
cat >dummy.c <<EOF
|
||||
#ifdef _SEQUENT_
|
||||
# include <sys/types.h>
|
||||
# include <sys/utsname.h>
|
||||
#endif
|
||||
main ()
|
||||
{
|
||||
#if defined (sony)
|
||||
#if defined (MIPSEB)
|
||||
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
|
||||
I don't know.... */
|
||||
printf ("mips-sony-bsd\n"); exit (0);
|
||||
#else
|
||||
#include <sys/param.h>
|
||||
printf ("m68k-sony-newsos%s\n",
|
||||
#ifdef NEWSOS4
|
||||
"4"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
); exit (0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (__arm) && defined (__acorn) && defined (__unix)
|
||||
printf ("arm-acorn-riscix"); exit (0);
|
||||
#endif
|
||||
|
||||
#if defined (hp300) && !defined (hpux)
|
||||
printf ("m68k-hp-bsd\n"); exit (0);
|
||||
#endif
|
||||
|
||||
#if defined (NeXT)
|
||||
#if !defined (__ARCHITECTURE__)
|
||||
#define __ARCHITECTURE__ "m68k"
|
||||
#endif
|
||||
int version;
|
||||
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
|
||||
printf ("%s-next-nextstep%s\n", __ARCHITECTURE__, version==2 ? "2" : "3");
|
||||
exit (0);
|
||||
#endif
|
||||
|
||||
#if defined (MULTIMAX) || defined (n16)
|
||||
#if defined (UMAXV)
|
||||
printf ("ns32k-encore-sysv\n"); exit (0);
|
||||
#else
|
||||
#if defined (CMU)
|
||||
printf ("ns32k-encore-mach\n"); exit (0);
|
||||
#else
|
||||
printf ("ns32k-encore-bsd\n"); exit (0);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (__386BSD__)
|
||||
printf ("i386-unknown-bsd\n"); exit (0);
|
||||
#endif
|
||||
|
||||
#if defined (sequent)
|
||||
#if defined (i386)
|
||||
printf ("i386-sequent-dynix\n"); exit (0);
|
||||
#endif
|
||||
#if defined (ns32000)
|
||||
printf ("ns32k-sequent-dynix\n"); exit (0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (_SEQUENT_)
|
||||
struct utsname un;
|
||||
|
||||
uname(&un);
|
||||
|
||||
if (strncmp(un.version, "V2", 2) == 0) {
|
||||
printf ("i386-sequent-ptx2\n"); exit (0);
|
||||
}
|
||||
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
|
||||
printf ("i386-sequent-ptx1\n"); exit (0);
|
||||
}
|
||||
printf ("i386-sequent-ptx\n"); exit (0);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (vax)
|
||||
#if !defined (ultrix)
|
||||
printf ("vax-dec-bsd\n"); exit (0);
|
||||
#else
|
||||
printf ("vax-dec-ultrix\n"); exit (0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (alliant) && defined (i860)
|
||||
printf ("i860-alliant-bsd\n"); exit (0);
|
||||
#endif
|
||||
|
||||
exit (1);
|
||||
}
|
||||
EOF
|
||||
|
||||
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
|
||||
rm -f dummy.c dummy
|
||||
|
||||
# Apollos put the system type in the environment.
|
||||
|
||||
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
|
||||
|
||||
# Convex versions that predate uname can use getsysinfo(1)
|
||||
|
||||
if [ -x /usr/convex/getsysinfo ]
|
||||
then
|
||||
case `getsysinfo -f cpu_type` in
|
||||
c1*)
|
||||
echo c1-convex-bsd
|
||||
exit 0 ;;
|
||||
c2*)
|
||||
if getsysinfo -f scalar_acc
|
||||
then echo c32-convex-bsd
|
||||
else echo c2-convex-bsd
|
||||
fi
|
||||
exit 0 ;;
|
||||
c34*)
|
||||
echo c34-convex-bsd
|
||||
exit 0 ;;
|
||||
c38*)
|
||||
echo c38-convex-bsd
|
||||
exit 0 ;;
|
||||
c4*)
|
||||
echo c4-convex-bsd
|
||||
exit 0 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
#echo '(Unable to guess system type)' 1>&2
|
||||
|
||||
exit 1
|
|
@ -1,867 +0,0 @@
|
|||
#! /bin/sh
|
||||
# Configuration validation subroutine script, version 1.1.
|
||||
# Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
# This file is (in principle) common to ALL GNU software.
|
||||
# The presence of a machine in this file suggests that SOME GNU software
|
||||
# can handle that machine. It does not imply ALL GNU software can.
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Configuration subroutine to validate and canonicalize a configuration type.
|
||||
# Supply the specified configuration type as an argument.
|
||||
# If it is invalid, we print an error message on stderr and exit with code 1.
|
||||
# Otherwise, we print the canonical config type on stdout and succeed.
|
||||
|
||||
# This file is supposed to be the same for all GNU packages
|
||||
# and recognize all the CPU types, system types and aliases
|
||||
# that are meaningful with *any* GNU software.
|
||||
# Each package is responsible for reporting which valid configurations
|
||||
# it does not support. The user should be able to distinguish
|
||||
# a failure to support a valid configuration from a meaningless
|
||||
# configuration.
|
||||
|
||||
# The goal of this file is to map all the various variations of a given
|
||||
# machine specification into a single specification in the form:
|
||||
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
|
||||
# It is wrong to echo any other type of specification.
|
||||
|
||||
if [ x$1 = x ]
|
||||
then
|
||||
echo Configuration name missing. 1>&2
|
||||
echo "Usage: $0 CPU-MFR-OPSYS" 1>&2
|
||||
echo "or $0 ALIAS" 1>&2
|
||||
echo where ALIAS is a recognized configuration type. 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# First pass through any local machine types.
|
||||
case $1 in
|
||||
*local*)
|
||||
echo $1
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# Separate what the user gave into CPU-COMPANY and OS (if any).
|
||||
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
|
||||
if [ $basic_machine != $1 ]
|
||||
then os=`echo $1 | sed 's/.*-/-/'`
|
||||
else os=; fi
|
||||
|
||||
### Let's recognize common machines as not being operating systems so
|
||||
### that things like config.sub decstation-3100 work. We also
|
||||
### recognize some manufacturers as not being operating systems, so we
|
||||
### can provide default operating systems below.
|
||||
case $os in
|
||||
-sun*os*)
|
||||
# Prevent following clause from handling this invalid input.
|
||||
;;
|
||||
-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
|
||||
-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
|
||||
-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
|
||||
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
|
||||
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
|
||||
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp )
|
||||
os=
|
||||
basic_machine=$1
|
||||
;;
|
||||
-hiux*)
|
||||
os=-hiuxwe2
|
||||
;;
|
||||
-sco4)
|
||||
os=-sco3.2v4
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-sco3.2.[4-9]*)
|
||||
os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-sco3.2v[4-9]*)
|
||||
# Don't forget version if it is 3.2v4 or newer.
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-sco*)
|
||||
os=-sco3.2v2
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-isc)
|
||||
os=-isc2.2
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-clix*)
|
||||
basic_machine=clipper-intergraph
|
||||
;;
|
||||
-isc*)
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'`
|
||||
;;
|
||||
-lynx*)
|
||||
os=-lynxos
|
||||
;;
|
||||
-ptx*)
|
||||
basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
|
||||
;;
|
||||
-windowsnt*)
|
||||
os=`echo $os | sed -e 's/windowsnt/winnt/'`
|
||||
;;
|
||||
esac
|
||||
|
||||
# Decode aliases for certain CPU-COMPANY combinations.
|
||||
case $basic_machine in
|
||||
# Recognize the basic CPU types without company name.
|
||||
# Some are omitted here because they have special meanings below.
|
||||
tahoe | i[345]86 | i860 | m68k | m68000 | m88k | ns32k | arm \
|
||||
| arme[lb] | pyramid \
|
||||
| tron | a29k | 580 | i960 | h8300 | hppa1.0 | hppa1.1 \
|
||||
| alpha | we32k | ns16k | clipper | sparclite | i370 | sh \
|
||||
| powerpc | powerpcle | sparc64 | 1750a | dsp16xx | mips64 | mipsel \
|
||||
| pdp11 | mips64el | mips64orion | mips64orionel \
|
||||
| sparc)
|
||||
basic_machine=$basic_machine-unknown
|
||||
;;
|
||||
# Object if more than one company name word.
|
||||
*-*-*)
|
||||
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
|
||||
exit 1
|
||||
;;
|
||||
# Recognize the basic CPU types with company name.
|
||||
vax-* | tahoe-* | i[345]86-* | i860-* | m68k-* | m68000-* | m88k-* \
|
||||
| sparc-* | ns32k-* | fx80-* | arm-* | c[123]* \
|
||||
| mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* | power-* \
|
||||
| none-* | 580-* | cray2-* | h8300-* | i960-* | xmp-* | ymp-* \
|
||||
| hppa1.0-* | hppa1.1-* | alpha-* | we32k-* | cydra-* | ns16k-* \
|
||||
| pn-* | np1-* | xps100-* | clipper-* | orion-* | sparclite-* \
|
||||
| pdp11-* | sh-* | powerpc-* | powerpcle-* | sparc64-* | mips64-* | mipsel-* \
|
||||
| mips64el-* | mips64orion-* | mips64orionel-*)
|
||||
;;
|
||||
# Recognize the various machine names and aliases which stand
|
||||
# for a CPU type and a company and sometimes even an OS.
|
||||
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
|
||||
basic_machine=m68000-att
|
||||
;;
|
||||
3b*)
|
||||
basic_machine=we32k-att
|
||||
;;
|
||||
alliant | fx80)
|
||||
basic_machine=fx80-alliant
|
||||
;;
|
||||
altos | altos3068)
|
||||
basic_machine=m68k-altos
|
||||
;;
|
||||
am29k)
|
||||
basic_machine=a29k-none
|
||||
os=-bsd
|
||||
;;
|
||||
amdahl)
|
||||
basic_machine=580-amdahl
|
||||
os=-sysv
|
||||
;;
|
||||
amiga | amiga-*)
|
||||
basic_machine=m68k-cbm
|
||||
;;
|
||||
amigados)
|
||||
basic_machine=m68k-cbm
|
||||
os=-amigados
|
||||
;;
|
||||
amigaunix | amix)
|
||||
basic_machine=m68k-cbm
|
||||
os=-sysv4
|
||||
;;
|
||||
apollo68)
|
||||
basic_machine=m68k-apollo
|
||||
os=-sysv
|
||||
;;
|
||||
balance)
|
||||
basic_machine=ns32k-sequent
|
||||
os=-dynix
|
||||
;;
|
||||
convex-c1)
|
||||
basic_machine=c1-convex
|
||||
os=-bsd
|
||||
;;
|
||||
convex-c2)
|
||||
basic_machine=c2-convex
|
||||
os=-bsd
|
||||
;;
|
||||
convex-c32)
|
||||
basic_machine=c32-convex
|
||||
os=-bsd
|
||||
;;
|
||||
convex-c34)
|
||||
basic_machine=c34-convex
|
||||
os=-bsd
|
||||
;;
|
||||
convex-c38)
|
||||
basic_machine=c38-convex
|
||||
os=-bsd
|
||||
;;
|
||||
cray | ymp)
|
||||
basic_machine=ymp-cray
|
||||
os=-unicos
|
||||
;;
|
||||
cray2)
|
||||
basic_machine=cray2-cray
|
||||
os=-unicos
|
||||
;;
|
||||
crds | unos)
|
||||
basic_machine=m68k-crds
|
||||
;;
|
||||
da30 | da30-*)
|
||||
basic_machine=m68k-da30
|
||||
;;
|
||||
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
|
||||
basic_machine=mips-dec
|
||||
;;
|
||||
delta | 3300 | motorola-3300 | motorola-delta \
|
||||
| 3300-motorola | delta-motorola)
|
||||
basic_machine=m68k-motorola
|
||||
;;
|
||||
delta88)
|
||||
basic_machine=m88k-motorola
|
||||
os=-sysv3
|
||||
;;
|
||||
dpx20 | dpx20-*)
|
||||
basic_machine=rs6000-bull
|
||||
os=-bosx
|
||||
;;
|
||||
dpx2* | dpx2*-bull)
|
||||
basic_machine=m68k-bull
|
||||
os=-sysv3
|
||||
;;
|
||||
ebmon29k)
|
||||
basic_machine=a29k-amd
|
||||
os=-ebmon
|
||||
;;
|
||||
elxsi)
|
||||
basic_machine=elxsi-elxsi
|
||||
os=-bsd
|
||||
;;
|
||||
encore | umax | mmax)
|
||||
basic_machine=ns32k-encore
|
||||
;;
|
||||
fx2800)
|
||||
basic_machine=i860-alliant
|
||||
;;
|
||||
genix)
|
||||
basic_machine=ns32k-ns
|
||||
;;
|
||||
gmicro)
|
||||
basic_machine=tron-gmicro
|
||||
os=-sysv
|
||||
;;
|
||||
h3050r* | hiux*)
|
||||
basic_machine=hppa1.1-hitachi
|
||||
os=-hiuxwe2
|
||||
;;
|
||||
h8300hms)
|
||||
basic_machine=h8300-hitachi
|
||||
os=-hms
|
||||
;;
|
||||
harris)
|
||||
basic_machine=m88k-harris
|
||||
os=-sysv3
|
||||
;;
|
||||
hp300-*)
|
||||
basic_machine=m68k-hp
|
||||
;;
|
||||
hp300bsd)
|
||||
basic_machine=m68k-hp
|
||||
os=-bsd
|
||||
;;
|
||||
hp300hpux)
|
||||
basic_machine=m68k-hp
|
||||
os=-hpux
|
||||
;;
|
||||
hp9k2[0-9][0-9] | hp9k31[0-9])
|
||||
basic_machine=m68000-hp
|
||||
;;
|
||||
hp9k3[2-9][0-9])
|
||||
basic_machine=m68k-hp
|
||||
;;
|
||||
hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7)
|
||||
basic_machine=hppa1.1-hp
|
||||
;;
|
||||
hp9k8[0-9][0-9] | hp8[0-9][0-9])
|
||||
basic_machine=hppa1.0-hp
|
||||
;;
|
||||
i370-ibm* | ibm*)
|
||||
basic_machine=i370-ibm
|
||||
os=-mvs
|
||||
;;
|
||||
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
|
||||
i[345]86v32)
|
||||
basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'`
|
||||
os=-sysv32
|
||||
;;
|
||||
i[345]86v4*)
|
||||
basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'`
|
||||
os=-sysv4
|
||||
;;
|
||||
i[345]86v)
|
||||
basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'`
|
||||
os=-sysv
|
||||
;;
|
||||
i[345]86sol2)
|
||||
basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'`
|
||||
os=-solaris2
|
||||
;;
|
||||
iris | iris4d)
|
||||
basic_machine=mips-sgi
|
||||
case $os in
|
||||
-irix*)
|
||||
;;
|
||||
*)
|
||||
os=-irix4
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
isi68 | isi)
|
||||
basic_machine=m68k-isi
|
||||
os=-sysv
|
||||
;;
|
||||
m88k-omron*)
|
||||
basic_machine=m88k-omron
|
||||
;;
|
||||
magnum | m3230)
|
||||
basic_machine=mips-mips
|
||||
os=-sysv
|
||||
;;
|
||||
merlin)
|
||||
basic_machine=ns32k-utek
|
||||
os=-sysv
|
||||
;;
|
||||
miniframe)
|
||||
basic_machine=m68000-convergent
|
||||
;;
|
||||
mips3*-*)
|
||||
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
|
||||
;;
|
||||
mips3*)
|
||||
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
|
||||
;;
|
||||
ncr3000)
|
||||
basic_machine=i486-ncr
|
||||
os=-sysv4
|
||||
;;
|
||||
news | news700 | news800 | news900)
|
||||
basic_machine=m68k-sony
|
||||
os=-newsos
|
||||
;;
|
||||
news1000)
|
||||
basic_machine=m68030-sony
|
||||
os=-newsos
|
||||
;;
|
||||
news-3600 | risc-news)
|
||||
basic_machine=mips-sony
|
||||
os=-newsos
|
||||
;;
|
||||
next | m*-next )
|
||||
basic_machine=m68k-next
|
||||
case $os in
|
||||
-nextstep* )
|
||||
;;
|
||||
-ns2*)
|
||||
os=-nextstep2
|
||||
;;
|
||||
*)
|
||||
os=-nextstep3
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
nh3000)
|
||||
basic_machine=m68k-harris
|
||||
os=-cxux
|
||||
;;
|
||||
nh[45]000)
|
||||
basic_machine=m88k-harris
|
||||
os=-cxux
|
||||
;;
|
||||
nindy960)
|
||||
basic_machine=i960-intel
|
||||
os=-nindy
|
||||
;;
|
||||
np1)
|
||||
basic_machine=np1-gould
|
||||
;;
|
||||
pa-hitachi)
|
||||
basic_machine=hppa1.1-hitachi
|
||||
os=-hiuxwe2
|
||||
;;
|
||||
paragon)
|
||||
basic_machine=i860-intel
|
||||
os=-osf
|
||||
;;
|
||||
pbd)
|
||||
basic_machine=sparc-tti
|
||||
;;
|
||||
pbb)
|
||||
basic_machine=m68k-tti
|
||||
;;
|
||||
pc532 | pc532-*)
|
||||
basic_machine=ns32k-pc532
|
||||
;;
|
||||
pentium | p5 | p6)
|
||||
# We don't have specific support for the Intel Pentium (p6) followon yet, so just call it a Pentium
|
||||
basic_machine=i586-intel
|
||||
;;
|
||||
pentium-* | p5-* | p6-*)
|
||||
# We don't have specific support for the Intel Pentium (p6) followon yet, so just call it a Pentium
|
||||
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
k5)
|
||||
# We don't have specific support for AMD's K5 yet, so just call it a Pentium
|
||||
basic_machine=i586-amd
|
||||
;;
|
||||
nexen)
|
||||
# We don't have specific support for Nexgen yet, so just call it a Pentium
|
||||
basic_machine=i586-nexgen
|
||||
;;
|
||||
pn)
|
||||
basic_machine=pn-gould
|
||||
;;
|
||||
power) basic_machine=rs6000-ibm
|
||||
;;
|
||||
ppc) basic_machine=powerpc-unknown
|
||||
;;
|
||||
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
ppcle | powerpclittle | ppc-le | powerpc-little)
|
||||
basic_machine=powerpcle-unknown
|
||||
;;
|
||||
ppcle-* | powerpclittle-*)
|
||||
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
|
||||
;;
|
||||
ps2)
|
||||
basic_machine=i386-ibm
|
||||
;;
|
||||
rm[46]00)
|
||||
basic_machine=mips-siemens
|
||||
;;
|
||||
rtpc | rtpc-*)
|
||||
basic_machine=romp-ibm
|
||||
;;
|
||||
sequent)
|
||||
basic_machine=i386-sequent
|
||||
;;
|
||||
sh)
|
||||
basic_machine=sh-hitachi
|
||||
os=-hms
|
||||
;;
|
||||
sps7)
|
||||
basic_machine=m68k-bull
|
||||
os=-sysv2
|
||||
;;
|
||||
spur)
|
||||
basic_machine=spur-unknown
|
||||
;;
|
||||
sun2)
|
||||
basic_machine=m68000-sun
|
||||
;;
|
||||
sun2os3)
|
||||
basic_machine=m68000-sun
|
||||
os=-sunos3
|
||||
;;
|
||||
sun2os4)
|
||||
basic_machine=m68000-sun
|
||||
os=-sunos4
|
||||
;;
|
||||
sun3os3)
|
||||
basic_machine=m68k-sun
|
||||
os=-sunos3
|
||||
;;
|
||||
sun3os4)
|
||||
basic_machine=m68k-sun
|
||||
os=-sunos4
|
||||
;;
|
||||
sun4os3)
|
||||
basic_machine=sparc-sun
|
||||
os=-sunos3
|
||||
;;
|
||||
sun4os4)
|
||||
basic_machine=sparc-sun
|
||||
os=-sunos4
|
||||
;;
|
||||
sun4sol2)
|
||||
basic_machine=sparc-sun
|
||||
os=-solaris2
|
||||
;;
|
||||
sun3 | sun3-*)
|
||||
basic_machine=m68k-sun
|
||||
;;
|
||||
sun4)
|
||||
basic_machine=sparc-sun
|
||||
;;
|
||||
sun386 | sun386i | roadrunner)
|
||||
basic_machine=i386-sun
|
||||
;;
|
||||
symmetry)
|
||||
basic_machine=i386-sequent
|
||||
os=-dynix
|
||||
;;
|
||||
tower | tower-32)
|
||||
basic_machine=m68k-ncr
|
||||
;;
|
||||
udi29k)
|
||||
basic_machine=a29k-amd
|
||||
os=-udi
|
||||
;;
|
||||
ultra3)
|
||||
basic_machine=a29k-nyu
|
||||
os=-sym1
|
||||
;;
|
||||
vaxv)
|
||||
basic_machine=vax-dec
|
||||
os=-sysv
|
||||
;;
|
||||
vms)
|
||||
basic_machine=vax-dec
|
||||
os=-vms
|
||||
;;
|
||||
vxworks960)
|
||||
basic_machine=i960-wrs
|
||||
os=-vxworks
|
||||
;;
|
||||
vxworks68)
|
||||
basic_machine=m68k-wrs
|
||||
os=-vxworks
|
||||
;;
|
||||
vxworks29k)
|
||||
basic_machine=a29k-wrs
|
||||
os=-vxworks
|
||||
;;
|
||||
xmp)
|
||||
basic_machine=xmp-cray
|
||||
os=-unicos
|
||||
;;
|
||||
xps | xps100)
|
||||
basic_machine=xps100-honeywell
|
||||
;;
|
||||
none)
|
||||
basic_machine=none-none
|
||||
os=-none
|
||||
;;
|
||||
|
||||
# Here we handle the default manufacturer of certain CPU types. It is in
|
||||
# some cases the only manufacturer, in others, it is the most popular.
|
||||
mips)
|
||||
basic_machine=mips-mips
|
||||
;;
|
||||
romp)
|
||||
basic_machine=romp-ibm
|
||||
;;
|
||||
rs6000)
|
||||
basic_machine=rs6000-ibm
|
||||
;;
|
||||
vax)
|
||||
basic_machine=vax-dec
|
||||
;;
|
||||
pdp11)
|
||||
basic_machine=pdp11-dec
|
||||
;;
|
||||
we32k)
|
||||
basic_machine=we32k-att
|
||||
;;
|
||||
sparc)
|
||||
basic_machine=sparc-sun
|
||||
;;
|
||||
cydra)
|
||||
basic_machine=cydra-cydrome
|
||||
;;
|
||||
orion)
|
||||
basic_machine=orion-highlevel
|
||||
;;
|
||||
orion105)
|
||||
basic_machine=clipper-highlevel
|
||||
;;
|
||||
*)
|
||||
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Here we canonicalize certain aliases for manufacturers.
|
||||
case $basic_machine in
|
||||
*-digital*)
|
||||
basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
|
||||
;;
|
||||
*-commodore*)
|
||||
basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# Decode manufacturer-specific aliases for certain operating systems.
|
||||
|
||||
if [ x"$os" != x"" ]
|
||||
then
|
||||
case $os in
|
||||
# -solaris* is a basic system type, with this one exception.
|
||||
-solaris1 | -solaris1.*)
|
||||
os=`echo $os | sed -e 's|solaris1|sunos4|'`
|
||||
;;
|
||||
-solaris)
|
||||
os=-solaris2
|
||||
;;
|
||||
-unixware* | svr4*)
|
||||
os=-sysv4
|
||||
;;
|
||||
-gnu/linux*)
|
||||
os=`echo $os | sed -e 's|gnu/linux|linux|'`
|
||||
;;
|
||||
# First accept the basic system types.
|
||||
# The portable systems comes first.
|
||||
# Each alternative MUST END IN A *, to match a version number.
|
||||
# -sysv* is not here because it comes later, after sysvr4.
|
||||
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
|
||||
| -vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[345]* \
|
||||
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
|
||||
| -amigados* | -msdos* | -newsos* | -unicos* | -aos* \
|
||||
| -nindy* | -vxworks* | -ebmon* | -hms* | -mvs* | -clix* \
|
||||
| -riscos* | -linux* | -uniplus* | -iris* | -rtu* | -xenix* \
|
||||
| -hiux* | -386bsd* | -netbsd* | -freebsd* | -riscix* \
|
||||
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \
|
||||
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
|
||||
| -udi* | -eabi* | -lites* )
|
||||
# Remember, each alternative MUST END IN *, to match a version number.
|
||||
;;
|
||||
-sunos5*)
|
||||
os=`echo $os | sed -e 's|sunos5|solaris2|'`
|
||||
;;
|
||||
-sunos6*)
|
||||
os=`echo $os | sed -e 's|sunos6|solaris3|'`
|
||||
;;
|
||||
-osfrose*)
|
||||
os=-osfrose
|
||||
;;
|
||||
-osf*)
|
||||
os=-osf
|
||||
;;
|
||||
-utek*)
|
||||
os=-bsd
|
||||
;;
|
||||
-dynix*)
|
||||
os=-bsd
|
||||
;;
|
||||
-acis*)
|
||||
os=-aos
|
||||
;;
|
||||
-ctix* | -uts*)
|
||||
os=-sysv
|
||||
;;
|
||||
# Preserve the version number of sinix5.
|
||||
-sinix5.*)
|
||||
os=`echo $os | sed -e 's|sinix|sysv|'`
|
||||
;;
|
||||
-sinix*)
|
||||
os=-sysv4
|
||||
;;
|
||||
-triton*)
|
||||
os=-sysv3
|
||||
;;
|
||||
-oss*)
|
||||
os=-sysv3
|
||||
;;
|
||||
-svr4)
|
||||
os=-sysv4
|
||||
;;
|
||||
-svr3)
|
||||
os=-sysv3
|
||||
;;
|
||||
-sysvr4)
|
||||
os=-sysv4
|
||||
;;
|
||||
# This must come after -sysvr4.
|
||||
-sysv*)
|
||||
;;
|
||||
-xenix)
|
||||
os=-xenix
|
||||
;;
|
||||
-none)
|
||||
;;
|
||||
*)
|
||||
# Get rid of the `-' at the beginning of $os.
|
||||
os=`echo $os | sed 's/[^-]*-//'`
|
||||
echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
|
||||
# Here we handle the default operating systems that come with various machines.
|
||||
# The value should be what the vendor currently ships out the door with their
|
||||
# machine or put another way, the most popular os provided with the machine.
|
||||
|
||||
# Note that if you're going to try to match "-MANUFACTURER" here (say,
|
||||
# "-sun"), then you have to tell the case statement up towards the top
|
||||
# that MANUFACTURER isn't an operating system. Otherwise, code above
|
||||
# will signal an error saying that MANUFACTURER isn't an operating
|
||||
# system, and we'll never get to this point.
|
||||
|
||||
case $basic_machine in
|
||||
*-acorn)
|
||||
os=-riscix1.2
|
||||
;;
|
||||
arm*-semi)
|
||||
os=-aout
|
||||
;;
|
||||
pdp11-*)
|
||||
os=-none
|
||||
;;
|
||||
*-dec | vax-*)
|
||||
os=-ultrix4.2
|
||||
;;
|
||||
m68*-apollo)
|
||||
os=-domain
|
||||
;;
|
||||
i386-sun)
|
||||
os=-sunos4.0.2
|
||||
;;
|
||||
m68000-sun)
|
||||
os=-sunos3
|
||||
# This also exists in the configure program, but was not the
|
||||
# default.
|
||||
# os=-sunos4
|
||||
;;
|
||||
*-tti) # must be before sparc entry or we get the wrong os.
|
||||
os=-sysv3
|
||||
;;
|
||||
sparc-* | *-sun)
|
||||
os=-sunos4.1.1
|
||||
;;
|
||||
*-ibm)
|
||||
os=-aix
|
||||
;;
|
||||
*-hp)
|
||||
os=-hpux
|
||||
;;
|
||||
*-hitachi)
|
||||
os=-hiux
|
||||
;;
|
||||
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
|
||||
os=-sysv
|
||||
;;
|
||||
*-cbm)
|
||||
os=-amigados
|
||||
;;
|
||||
*-dg)
|
||||
os=-dgux
|
||||
;;
|
||||
*-dolphin)
|
||||
os=-sysv3
|
||||
;;
|
||||
m68k-ccur)
|
||||
os=-rtu
|
||||
;;
|
||||
m88k-omron*)
|
||||
os=-luna
|
||||
;;
|
||||
*-sequent)
|
||||
os=-ptx
|
||||
;;
|
||||
*-crds)
|
||||
os=-unos
|
||||
;;
|
||||
*-ns)
|
||||
os=-genix
|
||||
;;
|
||||
i370-*)
|
||||
os=-mvs
|
||||
;;
|
||||
*-next)
|
||||
os=-nextstep3
|
||||
;;
|
||||
*-gould)
|
||||
os=-sysv
|
||||
;;
|
||||
*-highlevel)
|
||||
os=-bsd
|
||||
;;
|
||||
*-encore)
|
||||
os=-bsd
|
||||
;;
|
||||
*-sgi)
|
||||
os=-irix
|
||||
;;
|
||||
*-siemens)
|
||||
os=-sysv4
|
||||
;;
|
||||
*-masscomp)
|
||||
os=-rtu
|
||||
;;
|
||||
*)
|
||||
os=-none
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Here we handle the case where we know the os, and the CPU type, but not the
|
||||
# manufacturer. We pick the logical manufacturer.
|
||||
vendor=unknown
|
||||
case $basic_machine in
|
||||
*-unknown)
|
||||
case $os in
|
||||
-riscix*)
|
||||
vendor=acorn
|
||||
;;
|
||||
-sunos*)
|
||||
vendor=sun
|
||||
;;
|
||||
-lynxos*)
|
||||
vendor=lynx
|
||||
;;
|
||||
-aix*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-hpux*)
|
||||
vendor=hp
|
||||
;;
|
||||
-hiux*)
|
||||
vendor=hitachi
|
||||
;;
|
||||
-unos*)
|
||||
vendor=crds
|
||||
;;
|
||||
-dgux*)
|
||||
vendor=dg
|
||||
;;
|
||||
-luna*)
|
||||
vendor=omron
|
||||
;;
|
||||
-genix*)
|
||||
vendor=ns
|
||||
;;
|
||||
-mvs*)
|
||||
vendor=ibm
|
||||
;;
|
||||
-ptx*)
|
||||
vendor=sequent
|
||||
;;
|
||||
-vxworks*)
|
||||
vendor=wrs
|
||||
;;
|
||||
esac
|
||||
basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
|
||||
;;
|
||||
esac
|
||||
|
||||
echo $basic_machine$os
|
|
@ -1,140 +0,0 @@
|
|||
dnl @(#) $Header: /cvsroot/src/lib/libpcap/Attic/configure.in,v 1.1.1.1 1996/12/11 08:15:29 mikel Exp $ (LBL)
|
||||
dnl
|
||||
dnl Copyright (c) 1994, 1995, 1996
|
||||
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_INIT(pcap.c)
|
||||
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
umask 002
|
||||
|
||||
if test -z "$PWD" ; then
|
||||
PWD=`pwd`
|
||||
fi
|
||||
|
||||
AC_LBL_C_INIT(V_CCOPT, V_INCLS)
|
||||
|
||||
AC_CHECK_HEADERS(malloc.h sys/ioccom.h sys/sockio.h)
|
||||
|
||||
AC_LBL_FIXINCLUDES
|
||||
|
||||
AC_CHECK_FUNCS(ether_hostton strerror)
|
||||
|
||||
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
|
||||
AC_MSG_CHECKING(packet capture type)
|
||||
if 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/net/raw.h ; then
|
||||
V_PCAP=snoop
|
||||
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)
|
||||
|
||||
case "$V_PCAP" in
|
||||
|
||||
null)
|
||||
AC_MSG_WARN(cannot determine packet capture interface)
|
||||
AC_MSG_WARN((see INSTALL for more info))
|
||||
;;
|
||||
|
||||
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)
|
||||
|
||||
case "$target_os" in
|
||||
|
||||
hpux9*)
|
||||
AC_DEFINE(HAVE_HPUX9)
|
||||
;;
|
||||
|
||||
esac
|
||||
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")
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_LBL_LEX_AND_YACC(V_LEX, V_YACC, pcap_)
|
||||
|
||||
case "$target_os" in
|
||||
|
||||
aix*)
|
||||
dnl Workaround to enable certain features
|
||||
AC_DEFINE(_SUN)
|
||||
;;
|
||||
|
||||
solaris*)
|
||||
AC_DEFINE(HAVE_SOLARIS)
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_PROGS(V_RANLIB, ranlib, @true)
|
||||
|
||||
AC_LBL_DEVEL(V_CCOPT)
|
||||
|
||||
AC_LBL_SOCKADDR_SA_LEN
|
||||
|
||||
AC_LBL_UNALIGNED_ACCESS
|
||||
|
||||
if test -r lbl/gnuc.h ; then
|
||||
rm -f gnuc.h
|
||||
ln -s lbl/gnuc.h gnuc.h
|
||||
fi
|
||||
|
||||
rm -f bpf_filter.c
|
||||
ln -s bpf/net/bpf_filter.c bpf_filter.c
|
||||
rm -f net
|
||||
ln -s bpf/net net
|
||||
|
||||
AC_SUBST(V_CCOPT)
|
||||
AC_SUBST(V_INCLS)
|
||||
AC_SUBST(V_LEX)
|
||||
AC_SUBST(V_PCAP)
|
||||
AC_SUBST(V_RANLIB)
|
||||
AC_SUBST(V_YACC)
|
||||
|
||||
AC_PROG_INSTALL
|
||||
|
||||
AC_OUTPUT(Makefile)
|
||||
|
||||
if test -f .devel ; then
|
||||
make depend
|
||||
fi
|
||||
exit 0
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: etherent.c,v 1.2 1995/03/06 11:38:14 mycroft Exp $ */
|
||||
/* $NetBSD: etherent.c,v 1.3 1996/12/13 08:26:01 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* 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
|
||||
|
@ -20,20 +20,26 @@
|
|||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: etherent.c,v 1.8 94/06/20 19:07:50 leres Exp (LBL)";
|
||||
"@(#) Header: etherent.c,v 1.19 96/07/15 00:48:47 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static inline int xdtoi(int);
|
||||
|
@ -85,66 +91,71 @@ pcap_next_etherent(FILE *fp)
|
|||
register int c, d, i;
|
||||
char *bp;
|
||||
static struct pcap_etherent e;
|
||||
static int nline = 1;
|
||||
top:
|
||||
while (nline) {
|
||||
|
||||
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 ethernet address, skip the line. */
|
||||
else if (!isxdigit(c))
|
||||
cannot be etehrnet address, skip the line. */
|
||||
if (!isxdigit(c)) {
|
||||
c = skip_line(fp);
|
||||
else {
|
||||
/* must be the start of an address */
|
||||
for (i = 0; i < 6; i += 1) {
|
||||
d = xdtoi(c);
|
||||
c = getc(fp);
|
||||
if (c != ':') {
|
||||
d <<= 4;
|
||||
d |= xdtoi(c);
|
||||
c = getc(fp);
|
||||
}
|
||||
e.addr[i] = d;
|
||||
if (c != ':')
|
||||
break;
|
||||
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);
|
||||
}
|
||||
nline = 0;
|
||||
e.addr[i] = d;
|
||||
if (c != ':')
|
||||
break;
|
||||
c = getc(fp);
|
||||
}
|
||||
if (c == EOF)
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
/* If we started a new line, 'c' holds the char past the ether addr,
|
||||
which we assume is white space. If we are continuing a line,
|
||||
'c' is garbage. In either case, we can throw it away. */
|
||||
/* Must be whitespace */
|
||||
if (!isspace(c)) {
|
||||
c = skip_line(fp);
|
||||
continue;
|
||||
}
|
||||
c = skip_space(fp);
|
||||
|
||||
c = skip_space(fp);
|
||||
if (c == '\n') {
|
||||
nline = 1;
|
||||
goto top;
|
||||
}
|
||||
else if (c == '#') {
|
||||
(void)skip_line(fp);
|
||||
nline = 1;
|
||||
goto top;
|
||||
}
|
||||
else if (c == EOF)
|
||||
return 0;
|
||||
/* hit end of line... */
|
||||
if (c == '\n')
|
||||
continue;
|
||||
|
||||
/* Must be a 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';
|
||||
if (c == '\n')
|
||||
nline = 1;
|
||||
if (c == '#') {
|
||||
c = skip_line(fp);
|
||||
continue;
|
||||
}
|
||||
|
||||
return &e;
|
||||
/* 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,7 +1,7 @@
|
|||
/* $NetBSD: ethertype.h,v 1.2 1995/03/06 11:38:17 mycroft Exp $ */
|
||||
/* $NetBSD: ethertype.h,v 1.3 1996/12/13 08:26:02 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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
|
||||
|
@ -20,15 +20,20 @@
|
|||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @(#) Header: ethertype.h,v 1.2 94/06/14 20:03:27 leres Exp (LBL)
|
||||
* @(#) Header: ethertype.h,v 1.6 96/07/14 18:21:49 leres Exp (LBL)
|
||||
*/
|
||||
|
||||
/* Map between Ethernet protocol types and names */
|
||||
/* Types missing from some systems */
|
||||
|
||||
/* Add other Ethernet packet types here */
|
||||
#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
|
||||
|
@ -41,6 +46,12 @@
|
|||
#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
|
||||
|
@ -56,21 +67,12 @@
|
|||
#ifndef ETHERTYPE_VPROD
|
||||
#define ETHERTYPE_VPROD 0x805c
|
||||
#endif
|
||||
#ifndef ETHERTYPE_LOOPBACK
|
||||
#define ETHERTYPE_LOOPBACK 0x9000
|
||||
#endif
|
||||
|
||||
#ifndef ETHERTYPE_ATALK
|
||||
#define ETHERTYPE_ATALK 0x809b /* XXX */
|
||||
#define ETHERTYPE_ATALK 0x809b
|
||||
#endif
|
||||
#ifndef ETHERTYPE_AARP
|
||||
#define ETHERTYPE_AARP 0x80f3
|
||||
#endif
|
||||
#ifndef ETHERTYPE_NS
|
||||
#define ETHERTYPE_NS 0x0600
|
||||
#ifndef ETHERTYPE_LOOPBACK
|
||||
#define ETHERTYPE_LOOPBACK 0x9000
|
||||
#endif
|
||||
|
||||
#ifndef ETHERTYPE_REVARP
|
||||
#define ETHERTYPE_REVARP 0x8035
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: gencode.c,v 1.4 1996/05/29 04:05:52 cgd Exp $ */
|
||||
/* $NetBSD: gencode.c,v 1.5 1996/12/13 08:26:03 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994
|
||||
* 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
|
||||
|
@ -22,64 +22,63 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: gencode.c,v 1.55 94/06/20 19:07:53 leres Exp (LBL)";
|
||||
"@(#) Header: gencode.c,v 1.88 96/07/23 01:30:41 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
#include <setjmp.h>
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "ethertype.h"
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#endif
|
||||
|
||||
#ifndef ETHERTYPE_REVARP
|
||||
#define ETHERTYPE_REVARP 0x8035
|
||||
#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
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#define JMP(c) ((c)|BPF_JMP|BPF_K)
|
||||
|
||||
/* Locals */
|
||||
static jmp_buf top_ctx;
|
||||
static pcap_t *bpf_pcap;
|
||||
|
||||
/* XXX */
|
||||
#ifdef PCAP_FDDIPAD
|
||||
int pcap_fddipad = PCAP_FDDIPAD;
|
||||
#else
|
||||
int pcap_fddipad;
|
||||
#endif
|
||||
|
||||
/* VARARGS */
|
||||
volatile void
|
||||
#if __STDC__ || defined(SOLARIS)
|
||||
bpf_error(char *fmt, ...)
|
||||
__dead void
|
||||
#if __STDC__
|
||||
bpf_error(const char *fmt, ...)
|
||||
#else
|
||||
bpf_error(fmt, va_alist)
|
||||
char *fmt;
|
||||
const char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
|
@ -129,29 +128,25 @@ static inline void syntax(void);
|
|||
|
||||
static void backpatch(struct block *, struct block *);
|
||||
static void merge(struct block *, struct block *);
|
||||
static struct block *gen_cmp(u_int, u_int, int32_t);
|
||||
static struct block *gen_mcmp(u_int, u_int, int32_t, u_int32_t);
|
||||
static struct block *gen_bcmp(u_int, u_int, u_char *);
|
||||
static struct block *gen_cmp(u_int, u_int, bpf_int32);
|
||||
static struct block *gen_mcmp(u_int, u_int, bpf_int32, bpf_u_int32);
|
||||
static struct block *gen_bcmp(u_int, u_int, const u_char *);
|
||||
static struct block *gen_uncond(int);
|
||||
static inline struct block *gen_true(void);
|
||||
static inline struct block *gen_false(void);
|
||||
static struct block *gen_linktype(int);
|
||||
static struct block *gen_hostop(u_int32_t, u_int32_t, int, int, u_int, u_int);
|
||||
static struct block *gen_ehostop(u_char *, int);
|
||||
#ifdef FDDI
|
||||
static struct block *gen_fhostop(u_char *, int);
|
||||
#endif
|
||||
static struct block *gen_dnhostop(u_int32_t, int, u_int);
|
||||
static struct block *gen_host(u_int32_t, u_int32_t, int, int);
|
||||
static struct block *gen_gateway(u_char *, u_int32_t **, int, int);
|
||||
static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
|
||||
static struct block *gen_ehostop(const u_char *, int);
|
||||
static struct block *gen_fhostop(const u_char *, int);
|
||||
static struct block *gen_dnhostop(bpf_u_int32, int, u_int);
|
||||
static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int);
|
||||
static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int);
|
||||
static struct block *gen_ipfrag(void);
|
||||
static struct block *gen_portatom(int, int32_t);
|
||||
static struct block *gen_portatom(int, bpf_int32);
|
||||
struct block *gen_portop(int, int, int);
|
||||
static struct block *gen_port(int, int, int);
|
||||
static int lookup_proto(char *, int);
|
||||
static int lookup_proto(const char *, int);
|
||||
static struct block *gen_proto(int, int, int);
|
||||
static u_int32_t net_mask(u_int32_t *);
|
||||
static u_int32_t net_mask(u_int32_t *);
|
||||
static struct slist *xfer_to_x(struct arth *);
|
||||
static struct slist *xfer_to_a(struct arth *);
|
||||
static struct block *gen_len(int, int);
|
||||
|
@ -187,9 +182,12 @@ freechunks()
|
|||
{
|
||||
int i;
|
||||
|
||||
cur_chunk = 0;
|
||||
for (i = 0; i < NCHUNKS; ++i)
|
||||
if (chunks[i].m)
|
||||
if (chunks[i].m != NULL) {
|
||||
free(chunks[i].m);
|
||||
chunks[i].m = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -197,10 +195,11 @@ freechunks()
|
|||
*/
|
||||
char *
|
||||
sdup(s)
|
||||
char *s;
|
||||
register const char *s;
|
||||
{
|
||||
int n = strlen(s) + 1;
|
||||
char *cp = newchunk(n);
|
||||
|
||||
strcpy(cp, s);
|
||||
return (cp);
|
||||
}
|
||||
|
@ -246,26 +245,30 @@ syntax()
|
|||
bpf_error("syntax error in filter expression");
|
||||
}
|
||||
|
||||
static u_int32_t netmask;
|
||||
static bpf_u_int32 netmask;
|
||||
static int snaplen;
|
||||
|
||||
int
|
||||
pcap_compile(pcap_t *p, struct bpf_program *program,
|
||||
char *buf, int optimize, u_int32_t mask)
|
||||
char *buf, int optimize, bpf_u_int32 mask)
|
||||
{
|
||||
extern int n_errors;
|
||||
int len;
|
||||
|
||||
n_errors = 0;
|
||||
root = NULL;
|
||||
bpf_pcap = p;
|
||||
if (setjmp(top_ctx))
|
||||
if (setjmp(top_ctx)) {
|
||||
freechunks();
|
||||
return (-1);
|
||||
}
|
||||
|
||||
netmask = mask;
|
||||
snaplen = pcap_snapshot(p);
|
||||
|
||||
lex_init(buf ? buf : "");
|
||||
init_linktype(pcap_datalink(p));
|
||||
pcap_parse();
|
||||
(void)pcap_parse();
|
||||
|
||||
if (n_errors)
|
||||
syntax();
|
||||
|
@ -371,7 +374,7 @@ gen_not(b)
|
|||
static struct block *
|
||||
gen_cmp(offset, size, v)
|
||||
u_int offset, size;
|
||||
int32_t v;
|
||||
bpf_int32 v;
|
||||
{
|
||||
struct slist *s;
|
||||
struct block *b;
|
||||
|
@ -389,8 +392,8 @@ gen_cmp(offset, size, v)
|
|||
static struct block *
|
||||
gen_mcmp(offset, size, v, mask)
|
||||
u_int offset, size;
|
||||
int32_t v;
|
||||
u_int32_t mask;
|
||||
bpf_int32 v;
|
||||
bpf_u_int32 mask;
|
||||
{
|
||||
struct block *b = gen_cmp(offset, size, v);
|
||||
struct slist *s;
|
||||
|
@ -405,15 +408,16 @@ gen_mcmp(offset, size, v, mask)
|
|||
|
||||
static struct block *
|
||||
gen_bcmp(offset, size, v)
|
||||
u_int offset, size;
|
||||
u_char *v;
|
||||
register u_int offset, size;
|
||||
register const u_char *v;
|
||||
{
|
||||
struct block *b, *tmp;
|
||||
register struct block *b, *tmp;
|
||||
|
||||
b = NULL;
|
||||
while (size >= 4) {
|
||||
u_char *p = &v[size - 4];
|
||||
int32_t w = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
||||
register const u_char *p = &v[size - 4];
|
||||
bpf_int32 w = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
||||
|
||||
tmp = gen_cmp(offset + size - 4, BPF_W, w);
|
||||
if (b != NULL)
|
||||
gen_and(b, tmp);
|
||||
|
@ -421,8 +425,9 @@ gen_bcmp(offset, size, v)
|
|||
size -= 4;
|
||||
}
|
||||
while (size >= 2) {
|
||||
u_char *p = &v[size - 2];
|
||||
int32_t w = (p[0] << 8) | p[1];
|
||||
register const u_char *p = &v[size - 2];
|
||||
bpf_int32 w = (p[0] << 8) | p[1];
|
||||
|
||||
tmp = gen_cmp(offset + size - 2, BPF_H, w);
|
||||
if (b != NULL)
|
||||
gen_and(b, tmp);
|
||||
|
@ -430,7 +435,7 @@ gen_bcmp(offset, size, v)
|
|||
size -= 2;
|
||||
}
|
||||
if (size > 0) {
|
||||
tmp = gen_cmp(offset, BPF_B, (int32_t)v[0]);
|
||||
tmp = gen_cmp(offset, BPF_B, (bpf_int32)v[0]);
|
||||
if (b != NULL)
|
||||
gen_and(b, tmp);
|
||||
b = tmp;
|
||||
|
@ -446,9 +451,6 @@ gen_bcmp(offset, size, v)
|
|||
static u_int off_linktype;
|
||||
static u_int off_nl;
|
||||
static int linktype;
|
||||
#ifdef FDDI
|
||||
extern int fddipad;
|
||||
#endif
|
||||
|
||||
static void
|
||||
init_linktype(type)
|
||||
|
@ -473,8 +475,8 @@ init_linktype(type)
|
|||
return;
|
||||
|
||||
case DLT_NULL:
|
||||
off_linktype = -1;
|
||||
off_nl = 0;
|
||||
off_linktype = 0;
|
||||
off_nl = 4;
|
||||
return;
|
||||
|
||||
case DLT_PPP:
|
||||
|
@ -482,22 +484,35 @@ init_linktype(type)
|
|||
off_nl = 4;
|
||||
return;
|
||||
|
||||
#ifdef FDDI
|
||||
case DLT_FDDI:
|
||||
/*
|
||||
* FDDI doesn't really have a link-level type field.
|
||||
* We assume that SSAP = SNAP is being used and pick
|
||||
* out the encapsulated Ethernet type.
|
||||
*/
|
||||
off_linktype = 19 + fddipad;
|
||||
off_nl = 21 + fddipad;
|
||||
return;
|
||||
off_linktype = 19;
|
||||
#ifdef PCAP_FDDIPAD
|
||||
off_linktype += pcap_fddipad;
|
||||
#endif
|
||||
off_nl = 21;
|
||||
#ifdef PCAP_FDDIPAD
|
||||
off_nl += pcap_fddipad;
|
||||
#endif
|
||||
return;
|
||||
|
||||
case DLT_IEEE802:
|
||||
off_linktype = 20;
|
||||
off_nl = 22;
|
||||
return;
|
||||
|
||||
case DLT_ATM_RFC1483:
|
||||
/*
|
||||
* assume routed, non-ISO PDUs
|
||||
* (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
|
||||
*/
|
||||
off_linktype = 6;
|
||||
off_nl = 8;
|
||||
return;
|
||||
}
|
||||
bpf_error("unknown data link type 0x%x", linktype);
|
||||
/* NOTREACHED */
|
||||
|
@ -545,14 +560,21 @@ gen_linktype(proto)
|
|||
if (proto == ETHERTYPE_IP)
|
||||
proto = 0x0021; /* XXX - need ppp.h defs */
|
||||
break;
|
||||
|
||||
case DLT_NULL:
|
||||
/* XXX */
|
||||
if (proto == ETHERTYPE_IP)
|
||||
return (gen_cmp(0, BPF_W, (bpf_int32)AF_INET));
|
||||
else
|
||||
return gen_false();
|
||||
}
|
||||
return gen_cmp(off_linktype, BPF_H, (int32_t)proto);
|
||||
return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto);
|
||||
}
|
||||
|
||||
static struct block *
|
||||
gen_hostop(addr, mask, dir, proto, src_off, dst_off)
|
||||
u_int32_t addr;
|
||||
u_int32_t mask;
|
||||
bpf_u_int32 addr;
|
||||
bpf_u_int32 mask;
|
||||
int dir, proto;
|
||||
u_int src_off, dst_off;
|
||||
{
|
||||
|
@ -586,17 +608,17 @@ gen_hostop(addr, mask, dir, proto, src_off, dst_off)
|
|||
abort();
|
||||
}
|
||||
b0 = gen_linktype(proto);
|
||||
b1 = gen_mcmp(offset, BPF_W, (int32_t)addr, mask);
|
||||
b1 = gen_mcmp(offset, BPF_W, (bpf_int32)addr, mask);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
}
|
||||
|
||||
static struct block *
|
||||
gen_ehostop(eaddr, dir)
|
||||
u_char *eaddr;
|
||||
int dir;
|
||||
register const u_char *eaddr;
|
||||
register int dir;
|
||||
{
|
||||
struct block *b0, *b1;
|
||||
register struct block *b0, *b1;
|
||||
|
||||
switch (dir) {
|
||||
case Q_SRC:
|
||||
|
@ -622,23 +644,30 @@ gen_ehostop(eaddr, dir)
|
|||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
#ifdef FDDI
|
||||
/*
|
||||
* Like gen_ehostop, but for DLT_FDDI
|
||||
*/
|
||||
static struct block *
|
||||
gen_fhostop(eaddr, dir)
|
||||
u_char *eaddr;
|
||||
int dir;
|
||||
register const u_char *eaddr;
|
||||
register int dir;
|
||||
{
|
||||
struct block *b0, *b1;
|
||||
|
||||
switch (dir) {
|
||||
case Q_SRC:
|
||||
return gen_bcmp(6 + 1 + fddipad, 6, eaddr);
|
||||
#ifdef PCAP_FDDIPAD
|
||||
return gen_bcmp(6 + 1 + pcap_fddipad, 6, eaddr);
|
||||
#else
|
||||
return gen_bcmp(6 + 1, 6, eaddr);
|
||||
#endif
|
||||
|
||||
case Q_DST:
|
||||
return gen_bcmp(0 + 1 + fddipad, 6, eaddr);
|
||||
#ifdef PCAP_FDDIPAD
|
||||
return gen_bcmp(0 + 1 + pcap_fddipad, 6, eaddr);
|
||||
#else
|
||||
return gen_bcmp(0 + 1, 6, eaddr);
|
||||
#endif
|
||||
|
||||
case Q_AND:
|
||||
b0 = gen_fhostop(eaddr, Q_SRC);
|
||||
|
@ -656,7 +685,6 @@ gen_fhostop(eaddr, dir)
|
|||
abort();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is quite tricky because there may be pad bytes in front of the
|
||||
|
@ -678,7 +706,7 @@ gen_fhostop(eaddr, dir)
|
|||
*/
|
||||
static struct block *
|
||||
gen_dnhostop(addr, dir, base_off)
|
||||
u_int32_t addr;
|
||||
bpf_u_int32 addr;
|
||||
int dir;
|
||||
u_int base_off;
|
||||
{
|
||||
|
@ -719,23 +747,25 @@ gen_dnhostop(addr, dir, base_off)
|
|||
b0 = gen_linktype(ETHERTYPE_DN);
|
||||
/* Check for pad = 1, long header case */
|
||||
tmp = gen_mcmp(base_off + 2, BPF_H,
|
||||
(int32_t)ntohs(0x0681), (int32_t)ntohs(0x07FF));
|
||||
b1 = gen_cmp(base_off + 2 + 1 + offset_lh, BPF_H, (int32_t)ntohs(addr));
|
||||
(bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF));
|
||||
b1 = gen_cmp(base_off + 2 + 1 + offset_lh,
|
||||
BPF_H, (bpf_int32)ntohs(addr));
|
||||
gen_and(tmp, b1);
|
||||
/* Check for pad = 0, long header case */
|
||||
tmp = gen_mcmp(base_off + 2, BPF_B, (int32_t)0x06, (int32_t)0x7);
|
||||
b2 = gen_cmp(base_off + 2 + offset_lh, BPF_H, (int32_t)ntohs(addr));
|
||||
tmp = gen_mcmp(base_off + 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7);
|
||||
b2 = gen_cmp(base_off + 2 + offset_lh, BPF_H, (bpf_int32)ntohs(addr));
|
||||
gen_and(tmp, b2);
|
||||
gen_or(b2, b1);
|
||||
/* Check for pad = 1, short header case */
|
||||
tmp = gen_mcmp(base_off + 2, BPF_H,
|
||||
(int32_t)ntohs(0x0281), (int32_t)ntohs(0x07FF));
|
||||
b2 = gen_cmp(base_off + 2 + 1 + offset_sh, BPF_H, (int32_t)ntohs(addr));
|
||||
(bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF));
|
||||
b2 = gen_cmp(base_off + 2 + 1 + offset_sh,
|
||||
BPF_H, (bpf_int32)ntohs(addr));
|
||||
gen_and(tmp, b2);
|
||||
gen_or(b2, b1);
|
||||
/* Check for pad = 0, short header case */
|
||||
tmp = gen_mcmp(base_off + 2, BPF_B, (int32_t)0x02, (int32_t)0x7);
|
||||
b2 = gen_cmp(base_off + 2 + offset_sh, BPF_H, (int32_t)ntohs(addr));
|
||||
tmp = gen_mcmp(base_off + 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7);
|
||||
b2 = gen_cmp(base_off + 2 + offset_sh, BPF_H, (bpf_int32)ntohs(addr));
|
||||
gen_and(tmp, b2);
|
||||
gen_or(b2, b1);
|
||||
|
||||
|
@ -746,8 +776,8 @@ gen_dnhostop(addr, dir, base_off)
|
|||
|
||||
static struct block *
|
||||
gen_host(addr, mask, proto, dir)
|
||||
u_int32_t addr;
|
||||
u_int32_t mask;
|
||||
bpf_u_int32 addr;
|
||||
bpf_u_int32 mask;
|
||||
int proto;
|
||||
int dir;
|
||||
{
|
||||
|
@ -784,9 +814,21 @@ gen_host(addr, mask, proto, dir)
|
|||
case Q_ICMP:
|
||||
bpf_error("'icmp' modifier applied to host");
|
||||
|
||||
case Q_IGMP:
|
||||
bpf_error("'igmp' modifier applied to host");
|
||||
|
||||
case Q_IGRP:
|
||||
bpf_error("'igrp' modifier applied to host");
|
||||
|
||||
case Q_ATALK:
|
||||
bpf_error("ATALK host filtering not implemented");
|
||||
|
||||
case Q_DECNET:
|
||||
return gen_dnhostop(addr, dir, off_nl);
|
||||
|
||||
case Q_SCA:
|
||||
bpf_error("SCA host filtering not implemented");
|
||||
|
||||
case Q_LAT:
|
||||
bpf_error("LAT host filtering not implemented");
|
||||
|
||||
|
@ -804,8 +846,8 @@ gen_host(addr, mask, proto, dir)
|
|||
|
||||
static struct block *
|
||||
gen_gateway(eaddr, alist, proto, dir)
|
||||
u_char *eaddr;
|
||||
u_int32_t **alist;
|
||||
const u_char *eaddr;
|
||||
bpf_u_int32 **alist;
|
||||
int proto;
|
||||
int dir;
|
||||
{
|
||||
|
@ -821,16 +863,15 @@ gen_gateway(eaddr, alist, proto, dir)
|
|||
case Q_RARP:
|
||||
if (linktype == DLT_EN10MB)
|
||||
b0 = gen_ehostop(eaddr, Q_OR);
|
||||
#ifdef FDDI
|
||||
else if (linktype == DLT_FDDI)
|
||||
b0 = gen_fhostop(eaddr, Q_OR);
|
||||
#endif
|
||||
else
|
||||
bpf_error("'gateway' supported only on ethernet or FDDI");
|
||||
bpf_error(
|
||||
"'gateway' supported only on ethernet or FDDI");
|
||||
|
||||
b1 = gen_host(**alist++, 0xffffffffL, proto, Q_OR);
|
||||
b1 = gen_host(**alist++, 0xffffffff, proto, Q_OR);
|
||||
while (*alist) {
|
||||
tmp = gen_host(**alist++, 0xffffffffL, proto, Q_OR);
|
||||
tmp = gen_host(**alist++, 0xffffffff, proto, Q_OR);
|
||||
gen_or(b1, tmp);
|
||||
b1 = tmp;
|
||||
}
|
||||
|
@ -852,19 +893,34 @@ gen_proto_abbrev(proto)
|
|||
|
||||
case Q_TCP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (int32_t)IPPROTO_TCP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_TCP);
|
||||
gen_and(b0, b1);
|
||||
break;
|
||||
|
||||
case Q_UDP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (int32_t)IPPROTO_UDP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_UDP);
|
||||
gen_and(b0, b1);
|
||||
break;
|
||||
|
||||
case Q_ICMP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (int32_t)IPPROTO_ICMP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_ICMP);
|
||||
gen_and(b0, b1);
|
||||
break;
|
||||
|
||||
case Q_IGMP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)2);
|
||||
gen_and(b0, b1);
|
||||
break;
|
||||
|
||||
#ifndef IPPROTO_IGRP
|
||||
#define IPPROTO_IGRP 9
|
||||
#endif
|
||||
case Q_IGRP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (long)IPPROTO_IGRP);
|
||||
gen_and(b0, b1);
|
||||
break;
|
||||
|
||||
|
@ -883,10 +939,18 @@ gen_proto_abbrev(proto)
|
|||
case Q_LINK:
|
||||
bpf_error("link layer applied in wrong context");
|
||||
|
||||
case Q_ATALK:
|
||||
b1 = gen_linktype(ETHERTYPE_ATALK);
|
||||
break;
|
||||
|
||||
case Q_DECNET:
|
||||
b1 = gen_linktype(ETHERTYPE_DN);
|
||||
break;
|
||||
|
||||
case Q_SCA:
|
||||
b1 = gen_linktype(ETHERTYPE_SCA);
|
||||
break;
|
||||
|
||||
case Q_LAT:
|
||||
b1 = gen_linktype(ETHERTYPE_LAT);
|
||||
break;
|
||||
|
@ -925,7 +989,7 @@ gen_ipfrag()
|
|||
static struct block *
|
||||
gen_portatom(off, v)
|
||||
int off;
|
||||
int32_t v;
|
||||
bpf_int32 v;
|
||||
{
|
||||
struct slist *s;
|
||||
struct block *b;
|
||||
|
@ -950,29 +1014,29 @@ gen_portop(port, proto, dir)
|
|||
struct block *b0, *b1, *tmp;
|
||||
|
||||
/* ip proto 'proto' */
|
||||
tmp = gen_cmp(off_nl + 9, BPF_B, (int32_t)proto);
|
||||
tmp = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)proto);
|
||||
b0 = gen_ipfrag();
|
||||
gen_and(tmp, b0);
|
||||
|
||||
switch (dir) {
|
||||
case Q_SRC:
|
||||
b1 = gen_portatom(0, (int32_t)port);
|
||||
b1 = gen_portatom(0, (bpf_int32)port);
|
||||
break;
|
||||
|
||||
case Q_DST:
|
||||
b1 = gen_portatom(2, (int32_t)port);
|
||||
b1 = gen_portatom(2, (bpf_int32)port);
|
||||
break;
|
||||
|
||||
case Q_OR:
|
||||
case Q_DEFAULT:
|
||||
tmp = gen_portatom(0, (int32_t)port);
|
||||
b1 = gen_portatom(2, (int32_t)port);
|
||||
tmp = gen_portatom(0, (bpf_int32)port);
|
||||
b1 = gen_portatom(2, (bpf_int32)port);
|
||||
gen_or(tmp, b1);
|
||||
break;
|
||||
|
||||
case Q_AND:
|
||||
tmp = gen_portatom(0, (int32_t)port);
|
||||
b1 = gen_portatom(2, (int32_t)port);
|
||||
tmp = gen_portatom(0, (bpf_int32)port);
|
||||
b1 = gen_portatom(2, (bpf_int32)port);
|
||||
gen_and(tmp, b1);
|
||||
break;
|
||||
|
||||
|
@ -1016,12 +1080,13 @@ gen_port(port, ip_proto, dir)
|
|||
|
||||
static int
|
||||
lookup_proto(name, proto)
|
||||
char *name;
|
||||
int proto;
|
||||
register const char *name;
|
||||
register int proto;
|
||||
{
|
||||
int v;
|
||||
register int v;
|
||||
|
||||
switch (proto) {
|
||||
|
||||
case Q_DEFAULT:
|
||||
case Q_IP:
|
||||
v = pcap_nametoproto(name);
|
||||
|
@ -1058,7 +1123,7 @@ gen_proto(v, proto, dir)
|
|||
case Q_DEFAULT:
|
||||
case Q_IP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (int32_t)v);
|
||||
b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)v);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
|
||||
|
@ -1070,10 +1135,18 @@ gen_proto(v, proto, dir)
|
|||
bpf_error("rarp does not encapsulate another protocol");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_ATALK:
|
||||
bpf_error("atalk encapsulation is not specifiable");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_DECNET:
|
||||
bpf_error("decnet encapsulation is not specifiable");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_SCA:
|
||||
bpf_error("sca does not encapsulate another protocol");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_LAT:
|
||||
bpf_error("lat does not encapsulate another protocol");
|
||||
/* NOTREACHED */
|
||||
|
@ -1101,6 +1174,14 @@ gen_proto(v, proto, dir)
|
|||
bpf_error("'icmp proto' is bogus");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_IGMP:
|
||||
bpf_error("'igmp proto' is bogus");
|
||||
/* NOTREACHED */
|
||||
|
||||
case Q_IGRP:
|
||||
bpf_error("'igrp proto' is bogus");
|
||||
/* NOTREACHED */
|
||||
|
||||
default:
|
||||
abort();
|
||||
/* NOTREACHED */
|
||||
|
@ -1108,31 +1189,15 @@ gen_proto(v, proto, dir)
|
|||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* Left justify 'addr' and return its resulting network mask.
|
||||
*/
|
||||
static u_int32_t
|
||||
net_mask(addr)
|
||||
u_int32_t *addr;
|
||||
{
|
||||
register u_int32_t m = 0xffffffff;
|
||||
|
||||
if (*addr)
|
||||
while ((*addr & 0xff000000) == 0)
|
||||
*addr <<= 8, m <<= 8;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
struct block *
|
||||
gen_scode(name, q)
|
||||
char *name;
|
||||
register const char *name;
|
||||
struct qual q;
|
||||
{
|
||||
int proto = q.proto;
|
||||
int dir = q.dir;
|
||||
u_char *eaddr;
|
||||
u_int32_t mask, addr, **alist;
|
||||
bpf_u_int32 mask, addr, **alist;
|
||||
struct block *b, *tmp;
|
||||
int port, real_proto;
|
||||
|
||||
|
@ -1142,28 +1207,36 @@ gen_scode(name, q)
|
|||
addr = pcap_nametonetaddr(name);
|
||||
if (addr == 0)
|
||||
bpf_error("unknown network '%s'", name);
|
||||
mask = net_mask(&addr);
|
||||
/* Left justify network addr and calculate its network mask */
|
||||
mask = 0xffffffff;
|
||||
while (addr && (addr & 0xff000000) == 0) {
|
||||
addr <<= 8;
|
||||
mask <<= 8;
|
||||
}
|
||||
return gen_host(addr, mask, proto, dir);
|
||||
|
||||
case Q_DEFAULT:
|
||||
case Q_HOST:
|
||||
if (proto == Q_LINK) {
|
||||
switch (linktype) {
|
||||
|
||||
case DLT_EN10MB:
|
||||
eaddr = pcap_ether_hostton(name);
|
||||
if (eaddr == NULL)
|
||||
bpf_error("unknown ether host '%s'", name);
|
||||
bpf_error(
|
||||
"unknown ether host '%s'", name);
|
||||
return gen_ehostop(eaddr, dir);
|
||||
|
||||
#ifdef FDDI
|
||||
case DLT_FDDI:
|
||||
eaddr = pcap_ether_hostton(name);
|
||||
if (eaddr == NULL)
|
||||
bpf_error("unknown FDDI host '%s'", name);
|
||||
bpf_error(
|
||||
"unknown FDDI host '%s'", name);
|
||||
return gen_fhostop(eaddr, dir);
|
||||
#endif
|
||||
|
||||
default:
|
||||
bpf_error("only ethernet/FDDI supports link-level host name");
|
||||
bpf_error(
|
||||
"only ethernet/FDDI supports link-level host name");
|
||||
break;
|
||||
}
|
||||
} else if (proto == Q_DECNET) {
|
||||
|
@ -1177,9 +1250,9 @@ gen_scode(name, q)
|
|||
alist = pcap_nametoaddr(name);
|
||||
if (alist == NULL || *alist == NULL)
|
||||
bpf_error("unknown host '%s'", name);
|
||||
b = gen_host(**alist++, 0xffffffffL, proto, dir);
|
||||
b = gen_host(**alist++, 0xffffffff, proto, dir);
|
||||
while (*alist) {
|
||||
tmp = gen_host(**alist++, 0xffffffffL,
|
||||
tmp = gen_host(**alist++, 0xffffffff,
|
||||
proto, dir);
|
||||
gen_or(b, tmp);
|
||||
b = tmp;
|
||||
|
@ -1234,13 +1307,57 @@ gen_scode(name, q)
|
|||
}
|
||||
|
||||
struct block *
|
||||
gen_ncode(v, q)
|
||||
u_int32_t v;
|
||||
gen_mcode(s1, s2, masklen, q)
|
||||
register const char *s1, *s2;
|
||||
register int masklen;
|
||||
struct qual q;
|
||||
{
|
||||
u_int32_t mask;
|
||||
register int nlen, mlen;
|
||||
bpf_u_int32 n, m;
|
||||
|
||||
nlen = __pcap_atoin(s1, &n);
|
||||
/* Promote short ipaddr */
|
||||
n <<= 32 - nlen;
|
||||
|
||||
if (s2 != NULL) {
|
||||
mlen = __pcap_atoin(s2, &m);
|
||||
/* Promote short ipaddr */
|
||||
m <<= 32 - mlen;
|
||||
} else {
|
||||
/* Convert mask len to mask */
|
||||
if (masklen > 32)
|
||||
bpf_error("mask length must be <= 32");
|
||||
m = 0xffffffff << (32 - masklen);
|
||||
}
|
||||
|
||||
switch (q.addr) {
|
||||
|
||||
case Q_NET:
|
||||
return gen_host(n, m, q.proto, q.dir);
|
||||
|
||||
default:
|
||||
bpf_error("Mask syntax for networks only");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
struct block *
|
||||
gen_ncode(s, v, q)
|
||||
register const char *s;
|
||||
bpf_u_int32 v;
|
||||
struct qual q;
|
||||
{
|
||||
bpf_u_int32 mask;
|
||||
int proto = q.proto;
|
||||
int dir = q.dir;
|
||||
register int vlen;
|
||||
|
||||
if (s == NULL)
|
||||
vlen = 32;
|
||||
else if (q.proto == Q_DECNET)
|
||||
vlen = __pcap_atodn(s, &v);
|
||||
else
|
||||
vlen = __pcap_atoin(s, &v);
|
||||
|
||||
switch (q.addr) {
|
||||
|
||||
|
@ -1252,7 +1369,18 @@ gen_ncode(v, q)
|
|||
else if (proto == Q_LINK) {
|
||||
bpf_error("illegal link layer address");
|
||||
} else {
|
||||
mask = net_mask(&v);
|
||||
mask = 0xffffffff;
|
||||
if (s == NULL && q.addr == Q_NET) {
|
||||
/* Promote short net number */
|
||||
while (v && (v & 0xff000000) == 0) {
|
||||
v <<= 8;
|
||||
mask <<= 8;
|
||||
}
|
||||
} else {
|
||||
/* Promote short ipaddr */
|
||||
v <<= 32 - vlen;
|
||||
mask <<= 32 - vlen;
|
||||
}
|
||||
return gen_host(v, mask, proto, dir);
|
||||
}
|
||||
|
||||
|
@ -1288,16 +1416,14 @@ gen_ncode(v, q)
|
|||
|
||||
struct block *
|
||||
gen_ecode(eaddr, q)
|
||||
u_char *eaddr;
|
||||
register const u_char *eaddr;
|
||||
struct qual q;
|
||||
{
|
||||
if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
|
||||
if (linktype == DLT_EN10MB)
|
||||
return gen_ehostop(eaddr, (int)q.dir);
|
||||
#ifdef FDDI
|
||||
if (linktype == DLT_FDDI)
|
||||
return gen_fhostop(eaddr, (int)q.dir);
|
||||
#endif
|
||||
}
|
||||
bpf_error("ethernet address used in non-ether expression");
|
||||
/* NOTREACHED */
|
||||
|
@ -1380,7 +1506,9 @@ gen_load(proto, index, size)
|
|||
case Q_IP:
|
||||
case Q_ARP:
|
||||
case Q_RARP:
|
||||
case Q_ATALK:
|
||||
case Q_DECNET:
|
||||
case Q_SCA:
|
||||
case Q_LAT:
|
||||
case Q_MOPRC:
|
||||
case Q_MOPDL:
|
||||
|
@ -1400,6 +1528,8 @@ gen_load(proto, index, size)
|
|||
case Q_TCP:
|
||||
case Q_UDP:
|
||||
case Q_ICMP:
|
||||
case Q_IGMP:
|
||||
case Q_IGRP:
|
||||
s = new_stmt(BPF_LDX|BPF_MSH|BPF_B);
|
||||
s->s.k = off_nl;
|
||||
sappend(s, xfer_to_a(index));
|
||||
|
@ -1436,6 +1566,10 @@ gen_relation(code, a0, a1, reversed)
|
|||
s1 = xfer_to_a(a0);
|
||||
s2 = new_stmt(BPF_ALU|BPF_SUB|BPF_X);
|
||||
b = new_block(JMP(code));
|
||||
if (code == BPF_JGT || code == BPF_JGE) {
|
||||
reversed = !reversed;
|
||||
b->s.k = 0x80000000;
|
||||
}
|
||||
if (reversed)
|
||||
gen_not(b);
|
||||
|
||||
|
@ -1592,10 +1726,9 @@ gen_len(jmp, n)
|
|||
struct block *b;
|
||||
|
||||
s = new_stmt(BPF_LD|BPF_LEN);
|
||||
s->next = new_stmt(BPF_ALU|BPF_SUB|BPF_K);
|
||||
s->next->s.k = n;
|
||||
b = new_block(JMP(jmp));
|
||||
b->stmts = s;
|
||||
b->s.k = n;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
@ -1631,16 +1764,16 @@ gen_byteop(op, idx, val)
|
|||
abort();
|
||||
|
||||
case '=':
|
||||
return gen_cmp((u_int)idx, BPF_B, (int32_t)val);
|
||||
return gen_cmp((u_int)idx, BPF_B, (bpf_int32)val);
|
||||
|
||||
case '<':
|
||||
b = gen_cmp((u_int)idx, BPF_B, (int32_t)val);
|
||||
b = gen_cmp((u_int)idx, BPF_B, (bpf_int32)val);
|
||||
b->s.code = JMP(BPF_JGE);
|
||||
gen_not(b);
|
||||
return b;
|
||||
|
||||
case '>':
|
||||
b = gen_cmp((u_int)idx, BPF_B, (int32_t)val);
|
||||
b = gen_cmp((u_int)idx, BPF_B, (bpf_int32)val);
|
||||
b->s.code = JMP(BPF_JGT);
|
||||
return b;
|
||||
|
||||
|
@ -1664,7 +1797,7 @@ struct block *
|
|||
gen_broadcast(proto)
|
||||
int proto;
|
||||
{
|
||||
u_int32_t hostmask;
|
||||
bpf_u_int32 hostmask;
|
||||
struct block *b0, *b1, *b2;
|
||||
static u_char ebroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
|
||||
|
@ -1674,19 +1807,17 @@ gen_broadcast(proto)
|
|||
case Q_LINK:
|
||||
if (linktype == DLT_EN10MB)
|
||||
return gen_ehostop(ebroadcast, Q_DST);
|
||||
#ifdef FDDI
|
||||
if (linktype == DLT_FDDI)
|
||||
return gen_fhostop(ebroadcast, Q_DST);
|
||||
#endif
|
||||
bpf_error("not a broadcast link");
|
||||
break;
|
||||
|
||||
case Q_IP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
hostmask = ~netmask;
|
||||
b1 = gen_mcmp(off_nl + 16, BPF_W, (int32_t)0, hostmask);
|
||||
b1 = gen_mcmp(off_nl + 16, BPF_W, (bpf_int32)0, hostmask);
|
||||
b2 = gen_mcmp(off_nl + 16, BPF_W,
|
||||
(int32_t)(~0 & hostmask), hostmask);
|
||||
(bpf_int32)(~0 & hostmask), hostmask);
|
||||
gen_or(b1, b2);
|
||||
gen_and(b0, b2);
|
||||
return b2;
|
||||
|
@ -1730,7 +1861,7 @@ gen_multicast(proto)
|
|||
|
||||
case Q_IP:
|
||||
b0 = gen_linktype(ETHERTYPE_IP);
|
||||
b1 = gen_cmp(off_nl + 16, BPF_B, (int32_t)224);
|
||||
b1 = gen_cmp(off_nl + 16, BPF_B, (bpf_int32)224);
|
||||
b1->s.code = JMP(BPF_JGE);
|
||||
gen_and(b0, b1);
|
||||
return b1;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: gencode.h,v 1.3 1996/05/26 23:50:39 cgd Exp $ */
|
||||
/* $NetBSD: gencode.h,v 1.4 1996/12/13 08:26:04 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994
|
||||
* 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
|
||||
|
@ -20,14 +20,13 @@
|
|||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @(#) Header: gencode.h,v 1.20 94/06/12 14:29:30 leres Exp (LBL)
|
||||
* @(#) Header: gencode.h,v 1.36 96/07/17 00:11:34 leres Exp (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
* filter.h must be included before this file.
|
||||
*/
|
||||
/*XXX*/
|
||||
#include "gnuc.h"
|
||||
|
||||
/* Address qualifers. */
|
||||
/* Address qualifiers. */
|
||||
|
||||
#define Q_HOST 1
|
||||
#define Q_NET 2
|
||||
|
@ -44,13 +43,18 @@
|
|||
#define Q_TCP 5
|
||||
#define Q_UDP 6
|
||||
#define Q_ICMP 7
|
||||
#define Q_IGMP 8
|
||||
#define Q_IGRP 9
|
||||
|
||||
#define Q_DECNET 8
|
||||
#define Q_LAT 9
|
||||
#define Q_MOPRC 10
|
||||
#define Q_MOPDL 11
|
||||
|
||||
/* Directional qualifers. */
|
||||
#define Q_ATALK 10
|
||||
#define Q_DECNET 11
|
||||
#define Q_LAT 12
|
||||
#define Q_SCA 13
|
||||
#define Q_MOPRC 14
|
||||
#define Q_MOPDL 15
|
||||
|
||||
/* Directional qualifiers. */
|
||||
|
||||
#define Q_SRC 1
|
||||
#define Q_DST 2
|
||||
|
@ -62,7 +66,7 @@
|
|||
|
||||
struct stmt {
|
||||
int code;
|
||||
int32_t k;
|
||||
bpf_int32 k;
|
||||
};
|
||||
|
||||
struct slist {
|
||||
|
@ -74,14 +78,14 @@ struct slist {
|
|||
* A bit vector to represent definition sets. We assume TOT_REGISTERS
|
||||
* is smaller than 8*sizeof(atomset).
|
||||
*/
|
||||
typedef u_int32_t atomset;
|
||||
typedef bpf_u_int32 atomset;
|
||||
#define ATOMMASK(n) (1 << (n))
|
||||
#define ATOMELEM(d, n) (d & ATOMMASK(n))
|
||||
|
||||
/*
|
||||
* An unbounded set.
|
||||
*/
|
||||
typedef u_int32_t *uset;
|
||||
typedef bpf_u_int32 *uset;
|
||||
|
||||
/*
|
||||
* Total number of atomic entities, including accumulator (A) and index (X).
|
||||
|
@ -103,6 +107,8 @@ struct block {
|
|||
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;
|
||||
|
@ -116,8 +122,8 @@ struct block {
|
|||
atomset def, kill;
|
||||
atomset in_use;
|
||||
atomset out_use;
|
||||
int32_t oval;
|
||||
int32_t val[N_ATOMS];
|
||||
int oval;
|
||||
int val[N_ATOMS];
|
||||
};
|
||||
|
||||
struct arth {
|
||||
|
@ -133,10 +139,6 @@ struct qual {
|
|||
unsigned char pad;
|
||||
};
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define volatile
|
||||
#endif
|
||||
|
||||
struct arth *gen_loadi(int);
|
||||
struct arth *gen_load(int, struct arth *, int);
|
||||
struct arth *gen_loadlen(void);
|
||||
|
@ -147,9 +149,10 @@ void gen_and(struct block *, struct block *);
|
|||
void gen_or(struct block *, struct block *);
|
||||
void gen_not(struct block *);
|
||||
|
||||
struct block *gen_scode(char *, struct qual);
|
||||
struct block *gen_ecode(u_char *, struct qual);
|
||||
struct block *gen_ncode(u_int32_t, struct qual);
|
||||
struct block *gen_scode(const char *, struct qual);
|
||||
struct block *gen_ecode(const u_char *, struct qual);
|
||||
struct block *gen_mcode(const char *, const char *, int, struct qual);
|
||||
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);
|
||||
|
@ -160,10 +163,13 @@ struct block *gen_multicast(int);
|
|||
struct block *gen_inbound(int);
|
||||
|
||||
void bpf_optimize(struct block **);
|
||||
volatile void bpf_error(char *, ...);
|
||||
#if __STDC__
|
||||
__dead void bpf_error(const char *, ...)
|
||||
__attribute__((volatile, format (printf, 1, 2)));
|
||||
#endif
|
||||
|
||||
void finish_parse(struct block *);
|
||||
char *sdup(char *);
|
||||
char *sdup(const char *);
|
||||
|
||||
struct bpf_insn *icode_to_fcode(struct block *, int *);
|
||||
int pcap_parse(void);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
%{
|
||||
/* $NetBSD: grammar.y,v 1.2 1995/03/06 11:38:27 mycroft Exp $ */
|
||||
/* $NetBSD: grammar.y,v 1.3 1996/12/13 08:26:05 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
|
||||
* 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
|
||||
|
@ -24,24 +24,34 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: grammar.y,v 1.39 94/06/14 20:09:25 leres Exp (LBL)";
|
||||
"@(#) Header: grammar.y,v 1.54 96/07/17 00:11:34 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#define QSET(q, p, d, a) (q).proto = (p),\
|
||||
(q).dir = (d),\
|
||||
|
@ -60,6 +70,9 @@ yyerror(char *msg)
|
|||
}
|
||||
|
||||
#ifndef YYBISON
|
||||
int yyparse(void);
|
||||
|
||||
int
|
||||
pcap_parse()
|
||||
{
|
||||
return (yyparse());
|
||||
|
@ -70,7 +83,7 @@ pcap_parse()
|
|||
|
||||
%union {
|
||||
int i;
|
||||
u_long h;
|
||||
bpf_u_int32 h;
|
||||
u_char *e;
|
||||
char *s;
|
||||
struct stmt *stmt;
|
||||
|
@ -91,9 +104,9 @@ pcap_parse()
|
|||
%type <rblk> other
|
||||
|
||||
%token DST SRC HOST GATEWAY
|
||||
%token NET PORT LESS GREATER PROTO BYTE
|
||||
%token ARP RARP IP TCP UDP ICMP
|
||||
%token DECNET LAT MOPRC MOPDL
|
||||
%token NET MASK PORT LESS GREATER PROTO BYTE
|
||||
%token ARP RARP IP TCP UDP ICMP IGMP IGRP
|
||||
%token ATALK DECNET LAT SCA MOPRC MOPDL
|
||||
%token TK_BROADCAST TK_MULTICAST
|
||||
%token NUM INBOUND OUTBOUND
|
||||
%token LINK
|
||||
|
@ -104,7 +117,7 @@ pcap_parse()
|
|||
|
||||
%type <s> ID
|
||||
%type <e> EID
|
||||
%type <h> HID
|
||||
%type <s> HID
|
||||
%type <i> NUM
|
||||
|
||||
%left OR AND
|
||||
|
@ -135,24 +148,24 @@ and: AND { $$ = $<blk>0; }
|
|||
or: OR { $$ = $<blk>0; }
|
||||
;
|
||||
id: nid
|
||||
| pnum { $$.b = gen_ncode((u_long)$1,
|
||||
| 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 MASK HID { $$.b = gen_mcode($1, $3, 0,
|
||||
$$.q = $<blk>0.q); }
|
||||
| HID {
|
||||
/* Decide how to parse HID based on proto */
|
||||
$$.q = $<blk>0.q;
|
||||
switch ($$.q.proto) {
|
||||
case Q_DECNET:
|
||||
$$.b =
|
||||
gen_ncode(__pcap_atodn((char *)$1),
|
||||
$$.q);
|
||||
$$.b = gen_ncode($1, 0, $$.q);
|
||||
break;
|
||||
default:
|
||||
$$.b =
|
||||
gen_ncode(__pcap_atoin((char *)$1),
|
||||
$$.q);
|
||||
$$.b = gen_ncode($1, 0, $$.q);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +180,7 @@ 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((u_long)$1,
|
||||
qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
|
||||
$$.q = $<blk>0.q); }
|
||||
| pid
|
||||
;
|
||||
|
@ -216,8 +229,12 @@ pname: LINK { $$ = Q_LINK; }
|
|||
| TCP { $$ = Q_TCP; }
|
||||
| UDP { $$ = Q_UDP; }
|
||||
| ICMP { $$ = Q_ICMP; }
|
||||
| IGMP { $$ = Q_IGMP; }
|
||||
| IGRP { $$ = Q_IGRP; }
|
||||
| ATALK { $$ = Q_ATALK; }
|
||||
| DECNET { $$ = Q_DECNET; }
|
||||
| LAT { $$ = Q_LAT; }
|
||||
| SCA { $$ = Q_SCA; }
|
||||
| MOPDL { $$ = Q_MOPDL; }
|
||||
| MOPRC { $$ = Q_MOPRC; }
|
||||
;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: inet.c,v 1.3 1996/05/26 23:50:40 cgd Exp $ */
|
||||
/* $NetBSD: inet.c,v 1.4 1996/12/13 08:26:06 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
* 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
|
||||
|
@ -35,27 +35,40 @@
|
|||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: inet.c,v 1.4 94/06/07 01:16:50 leres Exp (LBL)";
|
||||
"@(#) Header: inet.c,v 1.18 96/07/15 00:48:49 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef SOLARIS
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
#include <sys/time.h> /* concession to AIX */
|
||||
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#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.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/* Not all systems have IFF_LOOPBACK */
|
||||
#ifdef IFF_LOOPBACK
|
||||
|
@ -100,7 +113,7 @@ pcap_lookupdev(errbuf)
|
|||
mp = NULL;
|
||||
minunit = 666;
|
||||
for (; ifrp < ifend; ifrp = ifnext) {
|
||||
#if BSD - 0 >= 199006
|
||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||
n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
|
||||
if (n < sizeof(*ifrp))
|
||||
ifnext = ifrp + 1;
|
||||
|
@ -151,7 +164,7 @@ pcap_lookupdev(errbuf)
|
|||
int
|
||||
pcap_lookupnet(device, netp, maskp, errbuf)
|
||||
register char *device;
|
||||
register u_int32_t *netp, *maskp;
|
||||
register bpf_u_int32 *netp, *maskp;
|
||||
register char *errbuf;
|
||||
{
|
||||
register int fd;
|
||||
|
@ -163,6 +176,11 @@ pcap_lookupnet(device, netp, maskp, errbuf)
|
|||
(void)sprintf(errbuf, "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) {
|
||||
(void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
|
||||
|
|
|
@ -1,238 +0,0 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
# 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,7 +1,7 @@
|
|||
/* $NetBSD: nametoaddr.c,v 1.4 1996/05/26 23:50:41 cgd Exp $ */
|
||||
/* $NetBSD: nametoaddr.c,v 1.5 1996/12/13 08:26:07 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1991, 1992, 1993, 1994
|
||||
* 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
|
||||
|
@ -26,11 +26,18 @@
|
|||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: nametoaddr.c,v 1.21 94/06/20 19:07:54 leres Exp (LBL)";
|
||||
"@(#) Header: nametoaddr.c,v 1.43 96/07/17 00:11:41 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h> /* concession to AIX */
|
||||
#include <sys/socket.h>
|
||||
|
||||
#if __STDC__
|
||||
struct mbuf;
|
||||
struct rtentry;
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
@ -38,19 +45,19 @@ static char rcsid[] =
|
|||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __NetBSD__
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <memory.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifndef NTOHL
|
||||
|
@ -64,24 +71,24 @@ static inline int xdtoi(int);
|
|||
* Convert host name to internet address.
|
||||
* Return 0 upon failure.
|
||||
*/
|
||||
u_int32_t **
|
||||
bpf_u_int32 **
|
||||
pcap_nametoaddr(const char *name)
|
||||
{
|
||||
#ifndef h_addr
|
||||
static u_int32_t *hlist[2];
|
||||
static bpf_u_int32 *hlist[2];
|
||||
#endif
|
||||
u_int32_t **p;
|
||||
bpf_u_int32 **p;
|
||||
struct hostent *hp;
|
||||
|
||||
if ((hp = gethostbyname(name)) != NULL) {
|
||||
#ifndef h_addr
|
||||
hlist[0] = (u_int32_t *)hp->h_addr;
|
||||
hlist[0] = (bpf_u_int32 *)hp->h_addr;
|
||||
NTOHL(hp->h_addr);
|
||||
return hlist;
|
||||
#else
|
||||
for (p = (u_int32_t **)hp->h_addr_list; *p; ++p)
|
||||
for (p = (bpf_u_int32 **)hp->h_addr_list; *p; ++p)
|
||||
NTOHL(**p);
|
||||
return (u_int32_t **)hp->h_addr_list;
|
||||
return (bpf_u_int32 **)hp->h_addr_list;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -92,7 +99,7 @@ pcap_nametoaddr(const char *name)
|
|||
* Convert net name to internet address.
|
||||
* Return 0 upon failure.
|
||||
*/
|
||||
u_long
|
||||
bpf_u_int32
|
||||
pcap_nametonetaddr(const char *name)
|
||||
{
|
||||
struct netent *np;
|
||||
|
@ -133,14 +140,12 @@ pcap_nametoport(const char *name, int *port, int *proto)
|
|||
sp = getservbyname(name, other);
|
||||
if (sp != 0) {
|
||||
NTOHS(sp->s_port);
|
||||
#ifdef notdef
|
||||
if (*port != sp->s_port)
|
||||
/* Can't handle ambiguous names that refer
|
||||
to different port numbers. */
|
||||
#ifdef notdef
|
||||
warning("ambiguous port %s in /etc/services",
|
||||
name);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
*proto = PROTO_UNDEF;
|
||||
}
|
||||
|
@ -186,8 +191,10 @@ struct eproto eproto_db[] = {
|
|||
{ "sprite", ETHERTYPE_SPRITE },
|
||||
{ "mopdl", ETHERTYPE_MOPDL },
|
||||
{ "moprc", ETHERTYPE_MOPRC },
|
||||
{ "atalk", ETHERTYPE_ATALK },
|
||||
{ "decnet", ETHERTYPE_DN },
|
||||
{ "lat", ETHERTYPE_LAT },
|
||||
{ "sca", ETHERTYPE_SCA },
|
||||
{ "lanbridge", ETHERTYPE_LANBRIDGE },
|
||||
{ "vexp", ETHERTYPE_VEXP },
|
||||
{ "vprod", ETHERTYPE_VPROD },
|
||||
|
@ -225,42 +232,44 @@ xdtoi(c)
|
|||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
u_long
|
||||
__pcap_atoin(const char *s)
|
||||
int
|
||||
__pcap_atoin(const char *s, bpf_u_int32 *addr)
|
||||
{
|
||||
u_long addr = 0;
|
||||
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;
|
||||
*addr <<= 8;
|
||||
*addr |= n & 0xff;
|
||||
len += 8;
|
||||
if (*s == '\0')
|
||||
return addr;
|
||||
return len;
|
||||
++s;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
u_long
|
||||
__pcap_atodn(const char *s)
|
||||
int
|
||||
__pcap_atodn(const char *s, bpf_u_int32 *addr)
|
||||
{
|
||||
#define AREASHIFT 10
|
||||
#define AREAMASK 0176000
|
||||
#define NODEMASK 01777
|
||||
|
||||
u_long addr = 0;
|
||||
u_int node, area;
|
||||
|
||||
if (sscanf((char *)s, "%d.%d", &area, &node) != 2)
|
||||
bpf_error("malformed decnet address '%s'", s);
|
||||
|
||||
addr = (area << AREASHIFT) & AREAMASK;
|
||||
addr |= (node & NODEMASK);
|
||||
*addr = (area << AREASHIFT) & AREAMASK;
|
||||
*addr |= (node & NODEMASK);
|
||||
|
||||
return(addr);
|
||||
return(32);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -289,7 +298,7 @@ pcap_ether_aton(const char *s)
|
|||
return (e);
|
||||
}
|
||||
|
||||
#ifndef ETHER_SERVICE
|
||||
#ifndef HAVE_ETHER_HOSTTON
|
||||
/* Roll our own */
|
||||
u_char *
|
||||
pcap_ether_hostton(const char *name)
|
||||
|
@ -322,18 +331,20 @@ pcap_ether_hostton(const char *name)
|
|||
return (NULL);
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef sgi
|
||||
extern int ether_hostton(char *, struct ether_addr *);
|
||||
#endif
|
||||
|
||||
/* Use the os supplied routines */
|
||||
u_char *
|
||||
pcap_ether_hostton(const char *name)
|
||||
{
|
||||
register u_char *ap;
|
||||
u_char a[6];
|
||||
#ifndef sgi
|
||||
extern int ether_hostton(char *, struct ether_addr *);
|
||||
#endif
|
||||
|
||||
ap = NULL;
|
||||
if (ether_hostton((char*)name, (struct ether_addr *)a) == 0) {
|
||||
if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) {
|
||||
ap = (u_char *)malloc(6);
|
||||
if (ap != NULL)
|
||||
memcpy(ap, a, 6);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: optimize.c,v 1.4 1996/05/26 23:50:42 cgd Exp $ */
|
||||
/* $NetBSD: optimize.c,v 1.5 1996/12/13 08:26:08 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 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
|
||||
|
@ -24,28 +24,27 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: optimize.c,v 1.45 94/06/20 19:07:55 leres Exp (LBL)";
|
||||
"@(#) Header: optimize.c,v 1.59 96/07/15 00:48:49 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef __osf__
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#ifdef __NetBSD__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <memory.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifdef BDEBUG
|
||||
extern int dflag;
|
||||
#endif
|
||||
|
||||
#define A_ATOM BPF_MEMWORDS
|
||||
|
@ -99,8 +98,8 @@ static int atomdef(struct stmt *);
|
|||
static void compute_local_ud(struct block *);
|
||||
static void find_ud(struct block *);
|
||||
static void init_val(void);
|
||||
static int32_t F(int, int32_t, int32_t);
|
||||
static inline void vstore(struct stmt *, int32_t *, int32_t, int);
|
||||
static int F(int, int, int);
|
||||
static inline void vstore(struct stmt *, int *, int, int);
|
||||
static void opt_blk(struct block *, int);
|
||||
static int use_conflict(struct block *, struct block *);
|
||||
static void opt_j(struct edge *);
|
||||
|
@ -111,11 +110,11 @@ static inline void link_inedge(struct edge *, struct block *);
|
|||
static void find_inedges(struct block *);
|
||||
static void opt_root(struct block **);
|
||||
static void opt_loop(struct block *, int);
|
||||
static void fold_op(struct stmt *, int32_t, int32_t);
|
||||
static void fold_op(struct stmt *, int, int);
|
||||
static inline struct slist *this_op(struct slist *);
|
||||
static void opt_not(struct block *);
|
||||
static void opt_peep(struct block *);
|
||||
static void opt_stmt(struct stmt *, int32_t[], int);
|
||||
static void opt_stmt(struct stmt *, int[], int);
|
||||
static void deadstmt(struct stmt *, struct stmt *[]);
|
||||
static void opt_deadstores(struct block *);
|
||||
static void opt_blk(struct block *, int);
|
||||
|
@ -127,7 +126,10 @@ static int slength(struct slist *);
|
|||
static int count_blocks(struct block *);
|
||||
static void number_blks_r(struct block *);
|
||||
static int count_stmts(struct block *);
|
||||
static void convert_code_r(struct block *);
|
||||
static int convert_code_r(struct block *);
|
||||
#ifdef BDEBUG
|
||||
static void opt_dump(struct block *);
|
||||
#endif
|
||||
|
||||
static int n_blocks;
|
||||
struct block **blocks;
|
||||
|
@ -141,8 +143,8 @@ struct edge **edges;
|
|||
static int nodewords;
|
||||
static int edgewords;
|
||||
struct block **levels;
|
||||
u_int32_t *space;
|
||||
#define BITS_PER_WORD (8*sizeof(u_int32_t))
|
||||
bpf_u_int32 *space;
|
||||
#define BITS_PER_WORD (8*sizeof(bpf_u_int32))
|
||||
/*
|
||||
* True if a is in uset {p}
|
||||
*/
|
||||
|
@ -166,7 +168,7 @@ u_int32_t *space;
|
|||
*/
|
||||
#define SET_INTERSECT(a, b, n)\
|
||||
{\
|
||||
register u_int32_t *_x = a, *_y = b;\
|
||||
register bpf_u_int32 *_x = a, *_y = b;\
|
||||
register int _n = n;\
|
||||
while (--_n >= 0) *_x++ &= *_y++;\
|
||||
}
|
||||
|
@ -176,7 +178,7 @@ u_int32_t *space;
|
|||
*/
|
||||
#define SET_SUBTRACT(a, b, n)\
|
||||
{\
|
||||
register u_int32_t *_x = a, *_y = b;\
|
||||
register bpf_u_int32 *_x = a, *_y = b;\
|
||||
register int _n = n;\
|
||||
while (--_n >= 0) *_x++ &=~ *_y++;\
|
||||
}
|
||||
|
@ -186,7 +188,7 @@ u_int32_t *space;
|
|||
*/
|
||||
#define SET_UNION(a, b, n)\
|
||||
{\
|
||||
register u_int32_t *_x = a, *_y = b;\
|
||||
register bpf_u_int32 *_x = a, *_y = b;\
|
||||
register int _n = n;\
|
||||
while (--_n >= 0) *_x++ |= *_y++;\
|
||||
}
|
||||
|
@ -247,7 +249,7 @@ find_dom(root)
|
|||
{
|
||||
int i;
|
||||
struct block *b;
|
||||
u_int32_t *x;
|
||||
bpf_u_int32 *x;
|
||||
|
||||
/*
|
||||
* Initialize sets to contain all nodes.
|
||||
|
@ -498,8 +500,8 @@ find_ud(root)
|
|||
*/
|
||||
struct valnode {
|
||||
int code;
|
||||
int32_t v0, v1;
|
||||
int32_t val;
|
||||
int v0, v1;
|
||||
int val;
|
||||
struct valnode *next;
|
||||
};
|
||||
|
||||
|
@ -513,7 +515,7 @@ static int maxval;
|
|||
|
||||
struct vmapinfo {
|
||||
int is_const;
|
||||
int32_t const_val;
|
||||
bpf_int32 const_val;
|
||||
};
|
||||
|
||||
struct vmapinfo *vmap;
|
||||
|
@ -530,10 +532,10 @@ init_val()
|
|||
}
|
||||
|
||||
/* Because we really don't have an IR, this stuff is a little messy. */
|
||||
static int32_t
|
||||
static int
|
||||
F(code, v0, v1)
|
||||
int code;
|
||||
int32_t v0, v1;
|
||||
int v0, v1;
|
||||
{
|
||||
u_int hash;
|
||||
int val;
|
||||
|
@ -566,8 +568,8 @@ F(code, v0, v1)
|
|||
static inline void
|
||||
vstore(s, valp, newval, alter)
|
||||
struct stmt *s;
|
||||
int32_t *valp;
|
||||
int32_t newval;
|
||||
int *valp;
|
||||
int newval;
|
||||
int alter;
|
||||
{
|
||||
if (alter && *valp == newval)
|
||||
|
@ -579,9 +581,9 @@ vstore(s, valp, newval, alter)
|
|||
static void
|
||||
fold_op(s, v0, v1)
|
||||
struct stmt *s;
|
||||
int32_t v0, v1;
|
||||
int v0, v1;
|
||||
{
|
||||
int32_t a, b;
|
||||
bpf_int32 a, b;
|
||||
|
||||
a = vmap[v0].const_val;
|
||||
b = vmap[v1].const_val;
|
||||
|
@ -659,7 +661,6 @@ opt_peep(b)
|
|||
struct slist *s;
|
||||
struct slist *next, *last;
|
||||
int val;
|
||||
int32_t v;
|
||||
|
||||
s = b->stmts;
|
||||
if (s == 0)
|
||||
|
@ -766,7 +767,16 @@ opt_peep(b)
|
|||
!ATOMELEM(b->out_use, A_ATOM)) {
|
||||
val = b->val[X_ATOM];
|
||||
if (vmap[val].is_const) {
|
||||
int op;
|
||||
|
||||
b->s.k += vmap[val].const_val;
|
||||
op = BPF_OP(b->s.code);
|
||||
if (op == BPF_JGT || op == BPF_JGE) {
|
||||
struct block *t = JT(b);
|
||||
JT(b) = JF(b);
|
||||
JF(b) = t;
|
||||
b->s.k += 0x80000000;
|
||||
}
|
||||
last->s.code = NOP;
|
||||
done = 0;
|
||||
} else if (b->s.k == 0) {
|
||||
|
@ -785,8 +795,17 @@ opt_peep(b)
|
|||
*/
|
||||
else if (last->s.code == (BPF_ALU|BPF_SUB|BPF_K) &&
|
||||
!ATOMELEM(b->out_use, A_ATOM)) {
|
||||
int op;
|
||||
|
||||
b->s.k += last->s.k;
|
||||
last->s.code = NOP;
|
||||
op = BPF_OP(b->s.code);
|
||||
if (op == BPF_JGT || op == BPF_JGE) {
|
||||
struct block *t = JT(b);
|
||||
JT(b) = JF(b);
|
||||
JF(b) = t;
|
||||
b->s.k += 0x80000000;
|
||||
}
|
||||
done = 0;
|
||||
}
|
||||
/*
|
||||
|
@ -807,7 +826,7 @@ opt_peep(b)
|
|||
*/
|
||||
val = b->val[A_ATOM];
|
||||
if (vmap[val].is_const && BPF_SRC(b->s.code) == BPF_K) {
|
||||
v = vmap[val].const_val;
|
||||
bpf_int32 v = vmap[val].const_val;
|
||||
switch (BPF_OP(b->s.code)) {
|
||||
|
||||
case BPF_JEQ:
|
||||
|
@ -815,11 +834,11 @@ opt_peep(b)
|
|||
break;
|
||||
|
||||
case BPF_JGT:
|
||||
v = v > b->s.k;
|
||||
v = (unsigned)v > b->s.k;
|
||||
break;
|
||||
|
||||
case BPF_JGE:
|
||||
v = v >= b->s.k;
|
||||
v = (unsigned)v >= b->s.k;
|
||||
break;
|
||||
|
||||
case BPF_JSET:
|
||||
|
@ -847,11 +866,11 @@ opt_peep(b)
|
|||
static void
|
||||
opt_stmt(s, val, alter)
|
||||
struct stmt *s;
|
||||
int32_t val[];
|
||||
int val[];
|
||||
int alter;
|
||||
{
|
||||
int op;
|
||||
int32_t v;
|
||||
int v;
|
||||
|
||||
switch (s->code) {
|
||||
|
||||
|
@ -1085,7 +1104,7 @@ opt_blk(b, do_stmts)
|
|||
struct slist *s;
|
||||
struct edge *p;
|
||||
int i;
|
||||
int32_t aval;
|
||||
bpf_int32 aval;
|
||||
|
||||
/*
|
||||
* Initialize the atom values.
|
||||
|
@ -1112,12 +1131,17 @@ opt_blk(b, do_stmts)
|
|||
/*
|
||||
* This is a special case: if we don't use anything from this
|
||||
* block, and we load the accumulator with value that is
|
||||
* already there, eliminate all the statements.
|
||||
* already there, or if this block is a return,
|
||||
* eliminate all the statements.
|
||||
*/
|
||||
if (do_stmts && b->out_use == 0 && aval != 0 &&
|
||||
b->val[A_ATOM] == aval)
|
||||
b->stmts = 0;
|
||||
else {
|
||||
if (do_stmts &&
|
||||
((b->out_use == 0 && aval != 0 &&b->val[A_ATOM] == aval) ||
|
||||
BPF_CLASS(b->s.code) == BPF_RET)) {
|
||||
if (b->stmts != 0) {
|
||||
b->stmts = 0;
|
||||
done = 0;
|
||||
}
|
||||
} else {
|
||||
opt_peep(b);
|
||||
opt_deadstores(b);
|
||||
}
|
||||
|
@ -1229,7 +1253,7 @@ opt_j(ep)
|
|||
*/
|
||||
top:
|
||||
for (i = 0; i < edgewords; ++i) {
|
||||
register u_int32_t x = ep->edom[i];
|
||||
register bpf_u_int32 x = ep->edom[i];
|
||||
|
||||
while (x != 0) {
|
||||
k = ffs(x) - 1;
|
||||
|
@ -1522,6 +1546,14 @@ opt_root(b)
|
|||
if (tmp != 0)
|
||||
sappend(s, tmp);
|
||||
(*b)->stmts = s;
|
||||
|
||||
/*
|
||||
* If the root node is a return, then there is no
|
||||
* point executing any statements (since the bpf machine
|
||||
* has no side effects).
|
||||
*/
|
||||
if (BPF_CLASS((*b)->s.code) == BPF_RET)
|
||||
(*b)->stmts = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1762,7 +1794,7 @@ static void
|
|||
opt_init(root)
|
||||
struct block *root;
|
||||
{
|
||||
u_int32_t *p;
|
||||
bpf_u_int32 *p;
|
||||
int i, n, max_stmts;
|
||||
|
||||
/*
|
||||
|
@ -1784,11 +1816,11 @@ opt_init(root)
|
|||
*/
|
||||
levels = (struct block **)malloc(n_blocks * sizeof(*levels));
|
||||
|
||||
edgewords = n_edges / (8 * sizeof(u_int32_t)) + 1;
|
||||
nodewords = n_blocks / (8 * sizeof(u_int32_t)) + 1;
|
||||
edgewords = n_edges / (8 * sizeof(bpf_u_int32)) + 1;
|
||||
nodewords = n_blocks / (8 * sizeof(bpf_u_int32)) + 1;
|
||||
|
||||
/* XXX */
|
||||
space = (u_int32_t *)malloc(2 * n_blocks * nodewords * sizeof(*space)
|
||||
space = (bpf_u_int32 *)malloc(2 * n_blocks * nodewords * sizeof(*space)
|
||||
+ n_edges * edgewords * sizeof(*space));
|
||||
p = space;
|
||||
all_dom_sets = p;
|
||||
|
@ -1841,7 +1873,13 @@ static struct bpf_insn *ftail;
|
|||
int bids[1000];
|
||||
#endif
|
||||
|
||||
static void
|
||||
/*
|
||||
* Returns true if successful. Returns false if a branch has
|
||||
* an offset that is too large. If so, we have marked that
|
||||
* branch so that on a subsequent iteration, it will be treated
|
||||
* properly.
|
||||
*/
|
||||
static int
|
||||
convert_code_r(p)
|
||||
struct block *p;
|
||||
{
|
||||
|
@ -1849,16 +1887,20 @@ convert_code_r(p)
|
|||
struct slist *src;
|
||||
int slen;
|
||||
u_int off;
|
||||
int extrajmps; /* number of extra jumps inserted */
|
||||
|
||||
if (p == 0 || isMarked(p))
|
||||
return;
|
||||
return (1);
|
||||
Mark(p);
|
||||
|
||||
convert_code_r(JF(p));
|
||||
convert_code_r(JT(p));
|
||||
if (convert_code_r(JF(p)) == 0)
|
||||
return (0);
|
||||
if (convert_code_r(JT(p)) == 0)
|
||||
return (0);
|
||||
|
||||
slen = slength(p->stmts);
|
||||
dst = ftail -= slen + 1;
|
||||
dst = ftail -= (slen + 1 + p->longjt + p->longjf);
|
||||
/* inflate length by any extra jumps */
|
||||
|
||||
p->offset = dst - fstart;
|
||||
|
||||
|
@ -1875,15 +1917,42 @@ convert_code_r(p)
|
|||
dst->code = (u_short)p->s.code;
|
||||
dst->k = p->s.k;
|
||||
if (JT(p)) {
|
||||
extrajmps = 0;
|
||||
off = JT(p)->offset - (p->offset + slen) - 1;
|
||||
if (off >= 256)
|
||||
bpf_error("long jumps not supported");
|
||||
dst->jt = off;
|
||||
if (off >= 256) {
|
||||
/* offset too large for branch, must add a jump */
|
||||
if (p->longjt == 0) {
|
||||
/* mark this instruction and retry */
|
||||
p->longjt++;
|
||||
return(0);
|
||||
}
|
||||
/* branch if T to following jump */
|
||||
dst->jt = extrajmps;
|
||||
extrajmps++;
|
||||
dst[extrajmps].code = BPF_JMP|BPF_JA;
|
||||
dst[extrajmps].k = off - extrajmps;
|
||||
}
|
||||
else
|
||||
dst->jt = off;
|
||||
off = JF(p)->offset - (p->offset + slen) - 1;
|
||||
if (off >= 256)
|
||||
bpf_error("long jumps not supported");
|
||||
dst->jf = off;
|
||||
if (off >= 256) {
|
||||
/* offset too large for branch, must add a jump */
|
||||
if (p->longjf == 0) {
|
||||
/* mark this instruction and retry */
|
||||
p->longjf++;
|
||||
return(0);
|
||||
}
|
||||
/* branch if F to following jump */
|
||||
/* if two jumps are inserted, F goes to second one */
|
||||
dst->jf = extrajmps;
|
||||
extrajmps++;
|
||||
dst[extrajmps].code = BPF_JMP|BPF_JA;
|
||||
dst[extrajmps].k = off - extrajmps;
|
||||
}
|
||||
else
|
||||
dst->jf = off;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1899,21 +1968,30 @@ icode_to_fcode(root, lenp)
|
|||
int n;
|
||||
struct bpf_insn *fp;
|
||||
|
||||
unMarkAll();
|
||||
n = *lenp = count_stmts(root);
|
||||
|
||||
fp = (struct bpf_insn *)malloc(sizeof(*fp) * n);
|
||||
memset((char *)fp, 0, sizeof(*fp) * n);
|
||||
fstart = fp;
|
||||
ftail = fp + n;
|
||||
|
||||
unMarkAll();
|
||||
convert_code_r(root);
|
||||
/*
|
||||
* Loop doing convert_codr_r() until no branches remain
|
||||
* with too-large offsets.
|
||||
*/
|
||||
while (1) {
|
||||
unMarkAll();
|
||||
n = *lenp = count_stmts(root);
|
||||
|
||||
fp = (struct bpf_insn *)malloc(sizeof(*fp) * n);
|
||||
memset((char *)fp, 0, sizeof(*fp) * n);
|
||||
fstart = fp;
|
||||
ftail = fp + n;
|
||||
|
||||
unMarkAll();
|
||||
if (convert_code_r(root))
|
||||
break;
|
||||
free(fp);
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
#ifdef BDEBUG
|
||||
static void
|
||||
opt_dump(root)
|
||||
struct block *root;
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: pcap-bpf.c,v 1.3 1995/04/29 05:42:31 cgd Exp $ */
|
||||
/* $NetBSD: pcap-bpf.c,v 1.4 1996/12/13 08:26:09 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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
|
||||
|
@ -22,35 +22,39 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)Header: pcap-bpf.c,v 1.14 94/06/03 19:58:49 leres Exp (LBL)";
|
||||
"@(#)Header: pcap-bpf.c,v 1.26 96/07/15 00:48:50 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <string.h>
|
||||
#ifdef __NetBSD__
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
int
|
||||
pcap_stats(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
struct bpf_stat s;
|
||||
|
||||
if (ioctl(p->fd, BIOCGSTATS, &s) < 0) {
|
||||
if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) {
|
||||
sprintf(p->errbuf, "BIOCGSTATS: %s", pcap_strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
@ -87,8 +91,9 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
|||
* The lseek() to 0 will fix things.
|
||||
*/
|
||||
case EINVAL:
|
||||
if ((long)(tell(p->fd) + p->bufsize) < 0) {
|
||||
(void)lseek(p->fd, 0, 0);
|
||||
if (lseek(p->fd, 0L, SEEK_CUR) +
|
||||
p->bufsize < 0) {
|
||||
(void)lseek(p->fd, 0L, SEEK_SET);
|
||||
goto again;
|
||||
}
|
||||
/* fall through */
|
||||
|
@ -213,7 +218,7 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
|
|||
goto bad;
|
||||
}
|
||||
p->bufsize = v;
|
||||
p->buffer = (u_char*)malloc(p->bufsize);
|
||||
p->buffer = (u_char *)malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
|
||||
goto bad;
|
||||
|
@ -221,6 +226,7 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
|
|||
|
||||
return (p);
|
||||
bad:
|
||||
(void)close(fd);
|
||||
free(p);
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: pcap-int.h,v 1.2 1995/03/06 11:38:47 mycroft Exp $ */
|
||||
/* $NetBSD: pcap-int.h,v 1.3 1996/12/13 08:26:10 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
* 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
|
||||
|
@ -32,7 +32,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: pcap-int.h,v 1.7 94/06/14 20:03:33 leres Exp (LBL)
|
||||
* @(#) Header: pcap-int.h,v 1.17 96/07/12 22:45:52 leres Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef pcap_int_h
|
||||
|
@ -53,14 +53,13 @@ struct pcap_sf {
|
|||
|
||||
struct pcap_md {
|
||||
struct pcap_stat stat;
|
||||
#ifdef PCAP_PF
|
||||
/*XXX*/
|
||||
int use_bpf;
|
||||
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 */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct pcap {
|
||||
|
@ -68,6 +67,7 @@ struct pcap {
|
|||
int snapshot;
|
||||
int linktype;
|
||||
int tzoff; /* timezone offset */
|
||||
int offset; /* offset for proper alignment */
|
||||
|
||||
struct pcap_sf sf;
|
||||
struct pcap_md md;
|
||||
|
@ -94,7 +94,21 @@ struct pcap {
|
|||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
};
|
||||
|
||||
int yylex(void);
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
/* XXX should these be in pcap.h? */
|
||||
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
|
||||
|
||||
/* Ultrix pads to make everything line up on a nice boundary */
|
||||
#if defined(ultrix) || defined(__alpha)
|
||||
#define PCAP_FDDIPAD 3
|
||||
#endif
|
||||
|
||||
/* XXX */
|
||||
extern int pcap_fddipad;
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: pcap-namedb.h,v 1.3 1996/05/26 23:50:44 cgd Exp $ */
|
||||
/* $NetBSD: pcap-namedb.h,v 1.4 1996/12/13 08:26:10 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
* 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
|
||||
|
@ -32,7 +32,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: pcap-namedb.h,v 1.2 94/06/14 20:03:34 leres Exp (LBL)
|
||||
* @(#) Header: pcap-namedb.h,v 1.5 96/07/14 03:00:14 leres Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_ethers_h
|
||||
|
@ -40,7 +40,7 @@
|
|||
|
||||
/*
|
||||
* As returned by the pcap_next_etherent()
|
||||
* XXX this stuff doesn't belong in this inteface, but this
|
||||
* 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
|
||||
|
@ -56,8 +56,8 @@ struct pcap_etherent *pcap_next_etherent(FILE *);
|
|||
u_char *pcap_ether_hostton(const char*);
|
||||
u_char *pcap_ether_aton(const char *);
|
||||
|
||||
u_int32_t **pcap_nametoaddr(const char *);
|
||||
u_long pcap_nametonetaddr(const char *);
|
||||
bpf_u_int32 **pcap_nametoaddr(const char *);
|
||||
bpf_u_int32 pcap_nametonetaddr(const char *);
|
||||
|
||||
int pcap_nametoport(const char *, int *, int *);
|
||||
int pcap_nametoproto(const char *);
|
||||
|
@ -71,8 +71,8 @@ int pcap_nametoeproto(const char *);
|
|||
#define PROTO_UNDEF -1
|
||||
|
||||
/* XXX move these to pcap-int.h? */
|
||||
u_long __pcap_atodn(const char *);
|
||||
u_long __pcap_atoin(const char *);
|
||||
int __pcap_atodn(const char *, bpf_u_int32 *);
|
||||
int __pcap_atoin(const char *, bpf_u_int32 *);
|
||||
u_short __pcap_nametodnaddr(const char *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 1995
|
||||
* 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 char rcsid[] =
|
||||
"@(#)$Header: /cvsroot/src/lib/libpcap/Attic/pcap-null.c,v 1.1.1.1 1996/12/11 08:15:43 mikel Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "gnuc.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";
|
||||
|
||||
int
|
||||
pcap_stats(pcap_t *p, struct pcap_stat *ps)
|
||||
{
|
||||
|
||||
(void)sprintf(p->errbuf, "pcap_stats: %s", nosup);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
|
||||
(void)sprintf(p->errbuf, "pcap_read: %s", nosup);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
|
||||
{
|
||||
|
||||
(void)strcpy(ebuf, nosup);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
|
||||
if (p->sf.rfile == NULL) {
|
||||
(void)sprintf(p->errbuf, "pcap_setfilter: %s", nosup);
|
||||
return (-1);
|
||||
}
|
||||
p->fcode = *fp;
|
||||
return (0);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
.\" $NetBSD: pcap.3,v 1.3 1996/05/26 23:50:46 cgd Exp $
|
||||
.\" $NetBSD: pcap.3,v 1.4 1996/12/13 08:26:12 mikel Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1994
|
||||
.\" 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
|
||||
|
@ -19,7 +19,7 @@
|
|||
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.\"
|
||||
.TH PCAP 3 "14 Jun 1994"
|
||||
.TH PCAP 3 "18 July 1996"
|
||||
.SH NAME
|
||||
pcap \- Packet Capture library
|
||||
.SH SYNOPSIS
|
||||
|
@ -57,10 +57,6 @@ u_char *sp)
|
|||
.ft
|
||||
.LP
|
||||
.ft B
|
||||
int pcap_immediate(pcap_t *p)
|
||||
.ft
|
||||
.LP
|
||||
.ft B
|
||||
int pcap_compile(pcap_t *p, struct bpf_program *fp,
|
||||
.ti +8
|
||||
char *str, int optimize, u_int32_t netmask)
|
||||
|
@ -131,7 +127,7 @@ fails and returns
|
|||
.B pcap_dump_open()
|
||||
is called to open a ``savefile'' for writing. The name "-" in a synonym
|
||||
for
|
||||
.BR stdin .
|
||||
.BR stdout .
|
||||
.B NULL
|
||||
is returned on failure.
|
||||
.I p
|
||||
|
@ -209,17 +205,6 @@ outputs a packet to the ``savefile'' opened with
|
|||
.BR pcap_dump_open() .
|
||||
Note that its calling arguments are suitable for use with
|
||||
.BR pcap_dispatch() .
|
||||
.ft B
|
||||
(??? this guy is kind of weird.)
|
||||
.ft
|
||||
.PP
|
||||
.B pcap_immediate()
|
||||
sets ``immediate'' mode.
|
||||
If this isn't supported by the under lying packet capture, -1 is
|
||||
returned and the error text can be obtained with
|
||||
.B pcap_perror()
|
||||
or
|
||||
.BR pcap_geterr() .
|
||||
.PP
|
||||
.B pcap_compile()
|
||||
is used to compile the string
|
||||
|
@ -287,7 +272,8 @@ returns the name of the ``savefile.''
|
|||
.B int pcap_stats()
|
||||
returns 0 and fills in a
|
||||
.B pcap_stat
|
||||
struct with packet statistics. If there is an error or the under lying
|
||||
struct. The values represent packet statistics from the start of the
|
||||
run to the time of the call. If there is an error or the under lying
|
||||
packet capture doesn't support packet statistics, -1 is returned and
|
||||
the error text can be obtained with
|
||||
.B pcap_perror()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: pcap.c,v 1.2 1995/03/06 11:39:05 mycroft Exp $ */
|
||||
/* $NetBSD: pcap.c,v 1.3 1996/12/13 08:26:13 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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
|
||||
|
@ -35,23 +35,35 @@
|
|||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: pcap.c,v 1.12 94/06/12 14:32:23 leres Exp (LBL)";
|
||||
"@(#) Header: pcap.c,v 1.25 96/06/05 21:45:26 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
int
|
||||
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
{
|
||||
register int cc;
|
||||
|
||||
if (p->sf.rfile != NULL)
|
||||
return (pcap_offline_read(p, cnt, callback, user));
|
||||
else
|
||||
return (pcap_read(p, cnt, callback, user));
|
||||
/* XXX keep reading until we get something (or an error occurs) */
|
||||
do {
|
||||
cc = pcap_read(p, cnt, callback, user);
|
||||
} while (cc == 0);
|
||||
return (cc);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -59,7 +71,7 @@ pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
|||
{
|
||||
for (;;) {
|
||||
int n = pcap_dispatch(p, cnt, callback, user);
|
||||
if (n < 0)
|
||||
if (n <= 0)
|
||||
return (n);
|
||||
if (cnt > 0) {
|
||||
cnt -= n;
|
||||
|
@ -89,7 +101,7 @@ 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)
|
||||
if (pcap_dispatch(p, 1, pcap_oneshot, (u_char*)&s) <= 0)
|
||||
return (0);
|
||||
return (s.pkt);
|
||||
}
|
||||
|
@ -154,8 +166,18 @@ pcap_geterr(pcap_t *p)
|
|||
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)sprintf(ebuf, "Unknown error: %d", errnum);
|
||||
return(ebuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -165,7 +187,7 @@ pcap_close(pcap_t *p)
|
|||
if (p->fd >= 0)
|
||||
close(p->fd);
|
||||
if (p->sf.rfile != NULL) {
|
||||
fclose(p->sf.rfile);
|
||||
(void)fclose(p->sf.rfile);
|
||||
if (p->sf.base != NULL)
|
||||
free(p->sf.base);
|
||||
} else if (p->buffer != NULL)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: pcap.h,v 1.4 1996/05/26 23:50:47 cgd Exp $ */
|
||||
/* $NetBSD: pcap.h,v 1.5 1996/12/13 08:26:13 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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
|
||||
|
@ -32,7 +32,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) Header: pcap.h,v 1.15 94/06/14 20:03:34 leres Exp (LBL)
|
||||
* @(#) Header: pcap.h,v 1.20 96/07/12 19:24:15 leres Exp (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_h
|
||||
|
@ -65,7 +65,7 @@ typedef struct pcap_dumper pcap_dumper_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 longs so compilers won't insert unwanted
|
||||
* Many fields here are 32 bit ints so compilers won't insert unwanted
|
||||
* padding; these files need to be interchangeable across architectures.
|
||||
*/
|
||||
struct pcap_file_header {
|
||||
|
@ -102,7 +102,7 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
|
|||
const u_char *);
|
||||
|
||||
char *pcap_lookupdev(char *);
|
||||
int pcap_lookupnet(char *, u_int32_t *, u_int32_t *, char *);
|
||||
int pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *);
|
||||
pcap_t *pcap_open_live(char *, int, int, int, char *);
|
||||
pcap_t *pcap_open_offline(char *, char *);
|
||||
void pcap_close(pcap_t *);
|
||||
|
@ -115,7 +115,8 @@ int pcap_setfilter(pcap_t *, struct bpf_program *);
|
|||
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, u_int32_t);
|
||||
int pcap_compile(pcap_t *, struct bpf_program *, char *, int,
|
||||
bpf_u_int32);
|
||||
/* XXX */
|
||||
int pcap_freecode(pcap_t *, struct bpf_program *);
|
||||
int pcap_datalink(pcap_t *);
|
||||
|
@ -135,5 +136,4 @@ void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
|
|||
/* XXX this guy lives in the bpf tree */
|
||||
u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
|
||||
char *bpf_image(struct bpf_insn *, int);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: savefile.c,v 1.2 1995/03/06 11:39:10 mycroft Exp $ */
|
||||
/* $NetBSD: savefile.c,v 1.3 1996/12/13 08:26:14 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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
|
||||
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#)Header: savefile.c,v 1.16 94/06/20 19:07:56 leres Exp (LBL)";
|
||||
"@(#)Header: savefile.c,v 1.30 96/07/15 00:48:52 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -39,8 +39,6 @@ static char rcsid[] =
|
|||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
@ -49,6 +47,11 @@ static char rcsid[] =
|
|||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#define TCPDUMP_MAGIC 0xa1b2c3d4
|
||||
|
||||
/*
|
||||
|
@ -116,11 +119,7 @@ pcap_open_offline(char *fname, char *errbuf)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
bzero(p, sizeof(*p));
|
||||
#else
|
||||
memset(p, 0, sizeof(*p));
|
||||
#endif
|
||||
memset((char *)p, 0, sizeof(*p));
|
||||
/*
|
||||
* Set this field so we don't close stdin in pcap_close!
|
||||
*/
|
||||
|
@ -156,12 +155,33 @@ pcap_open_offline(char *fname, char *errbuf)
|
|||
p->linktype = hdr.linktype;
|
||||
p->sf.rfile = fp;
|
||||
p->bufsize = hdr.snaplen;
|
||||
|
||||
/* Align link header as required for proper data alignment */
|
||||
linklen = 14; /* XXX */
|
||||
/* XXX should handle all types */
|
||||
switch (p->linktype) {
|
||||
|
||||
case DLT_EN10MB:
|
||||
linklen = 14;
|
||||
break;
|
||||
|
||||
case DLT_FDDI:
|
||||
linklen = 13 + 8; /* fddi_header + llc */
|
||||
break;
|
||||
|
||||
case DLT_NULL:
|
||||
default:
|
||||
linklen = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
p->sf.base = (u_char *)malloc(p->bufsize + BPF_ALIGNMENT);
|
||||
p->buffer = p->sf.base + BPF_ALIGNMENT - (linklen % BPF_ALIGNMENT);
|
||||
p->sf.version_major = hdr.version_major;
|
||||
p->sf.version_minor = hdr.version_minor;
|
||||
#ifdef PCAP_FDDIPAD
|
||||
/* XXX padding only needed for kernel fcode */
|
||||
pcap_fddipad = 0;
|
||||
#endif
|
||||
|
||||
return (p);
|
||||
bad:
|
||||
|
@ -206,15 +226,38 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
|
|||
}
|
||||
|
||||
if (hdr->caplen > buflen) {
|
||||
sprintf(p->errbuf, "bad dump file format");
|
||||
return (-1);
|
||||
}
|
||||
/*
|
||||
* This can happen due to Solaris 2.3 systems tripping
|
||||
* over the BUFMOD problem and not setting the snapshot
|
||||
* correctly in the savefile header. If the caplen isn't
|
||||
* grossly wrong, try to salvage.
|
||||
*/
|
||||
static u_char *tp = NULL;
|
||||
static int tsize = 0;
|
||||
|
||||
/* read the packet itself */
|
||||
if (tsize < hdr->caplen) {
|
||||
tsize = ((hdr->caplen + 1023) / 1024) * 1024;
|
||||
if (tp != NULL)
|
||||
free((u_char *)tp);
|
||||
tp = (u_char *)malloc(tsize);
|
||||
if (tp == NULL) {
|
||||
sprintf(p->errbuf, "BUFMOD hack malloc");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if (fread((char *)tp, hdr->caplen, 1, fp) != 1) {
|
||||
sprintf(p->errbuf, "truncated dump file");
|
||||
return (-1);
|
||||
}
|
||||
memcpy((char *)buf, (char *)tp, buflen);
|
||||
|
||||
if (fread((char *)buf, hdr->caplen, 1, fp) != 1) {
|
||||
sprintf(p->errbuf, "truncated dump file");
|
||||
return (-1);
|
||||
} else {
|
||||
/* read the packet itself */
|
||||
|
||||
if (fread((char *)buf, hdr->caplen, 1, fp) != 1) {
|
||||
sprintf(p->errbuf, "truncated dump file");
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -234,8 +277,11 @@ pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
|||
struct pcap_pkthdr h;
|
||||
|
||||
status = sf_next_packet(p, &h, p->buffer, p->bufsize);
|
||||
if (status)
|
||||
return (-1);
|
||||
if (status) {
|
||||
if (status == 1)
|
||||
return (0);
|
||||
return (status);
|
||||
}
|
||||
|
||||
if (fcode == NULL ||
|
||||
bpf_filter(fcode, p->buffer, h.len, h.caplen)) {
|
||||
|
@ -254,7 +300,10 @@ pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
|||
void
|
||||
pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
|
||||
{
|
||||
FILE * f = (FILE *)user;
|
||||
register FILE *f;
|
||||
|
||||
f = (FILE *)user;
|
||||
/* XXX we should check the return status */
|
||||
(void)fwrite((char *)h, sizeof(*h), 1, f);
|
||||
(void)fwrite((char *)sp, h->caplen, 1, f);
|
||||
}
|
||||
|
@ -283,5 +332,11 @@ pcap_dump_open(pcap_t *p, char *fname)
|
|||
void
|
||||
pcap_dump_close(pcap_dumper_t *p)
|
||||
{
|
||||
fclose((FILE *)p);
|
||||
|
||||
#ifdef notyet
|
||||
if (ferror((FILE *)p))
|
||||
return-an-error;
|
||||
/* XXX should check return from fclose() too */
|
||||
#endif
|
||||
(void)fclose((FILE *)p);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
%{
|
||||
/* $NetBSD: scanner.l,v 1.2 1995/03/06 11:39:12 mycroft Exp $ */
|
||||
/* $NetBSD: scanner.l,v 1.3 1996/12/13 08:26:15 mikel Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
|
||||
* 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
|
||||
|
@ -24,21 +24,24 @@
|
|||
|
||||
#ifndef lint
|
||||
static char rcsid[] =
|
||||
"@(#) Header: scanner.l,v 1.40 94/06/10 17:21:44 mccanne Exp (LBL)";
|
||||
"@(#) Header: scanner.l,v 1.53 96/07/17 00:11:34 leres Exp (LBL)";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <pcap.h>
|
||||
#include <pcap-namedb.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "gencode.h"
|
||||
#include <pcap-namedb.h>
|
||||
#include "y.tab.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define inline
|
||||
#include "gnuc.h"
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
static int stoi(char *);
|
||||
|
@ -65,6 +68,7 @@ static inline int xdtoi(int);
|
|||
#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
|
||||
#endif
|
||||
|
||||
#define yylval pcap_lval
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
static char *in_buffer;
|
||||
|
@ -88,14 +92,19 @@ ip return IP;
|
|||
tcp return TCP;
|
||||
udp return UDP;
|
||||
icmp return ICMP;
|
||||
igmp return IGMP;
|
||||
igrp return IGRP;
|
||||
|
||||
atalk return ATALK;
|
||||
decnet return DECNET;
|
||||
lat return LAT;
|
||||
sca return SCA;
|
||||
moprc return MOPRC;
|
||||
mopdl return MOPDL;
|
||||
|
||||
host return HOST;
|
||||
net return NET;
|
||||
mask return MASK;
|
||||
port return PORT;
|
||||
proto return PROTO;
|
||||
|
||||
|
|
Loading…
Reference in New Issue