summaryrefslogtreecommitdiff
path: root/lib/libpcap
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1999-07-20 04:49:57 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1999-07-20 04:49:57 +0000
commit71485f8b41b88ac37f4b80682b25979427a1bfd7 (patch)
tree06f48d6e0fc6dad8042285ca695cda2714e85857 /lib/libpcap
parent8f264cbfafae23f6fdc50edac746009289631659 (diff)
changes brought in from v0.4; started by brad, more by me, being tested by mts
Diffstat (limited to 'lib/libpcap')
-rw-r--r--lib/libpcap/CHANGES146
-rw-r--r--lib/libpcap/Makefile21
-rw-r--r--lib/libpcap/README8
-rw-r--r--lib/libpcap/VERSION1
-rw-r--r--lib/libpcap/bpf_image.c15
-rw-r--r--lib/libpcap/etherent.c16
-rw-r--r--lib/libpcap/ethertype.h42
-rw-r--r--lib/libpcap/gencode.c315
-rw-r--r--lib/libpcap/gencode.h25
-rw-r--r--lib/libpcap/grammar.y46
-rw-r--r--lib/libpcap/inet.c26
-rw-r--r--lib/libpcap/nametoaddr.c47
-rw-r--r--lib/libpcap/optimize.c15
-rw-r--r--lib/libpcap/pcap-bpf.c36
-rw-r--r--lib/libpcap/pcap-int.h19
-rw-r--r--lib/libpcap/pcap-namedb.h8
-rw-r--r--lib/libpcap/pcap.364
-rw-r--r--lib/libpcap/pcap.c35
-rw-r--r--lib/libpcap/pcap.h14
-rw-r--r--lib/libpcap/ppp.h52
-rw-r--r--lib/libpcap/savefile.c48
-rw-r--r--lib/libpcap/scanner.l19
-rw-r--r--lib/libpcap/shlib_version4
23 files changed, 722 insertions, 300 deletions
diff --git a/lib/libpcap/CHANGES b/lib/libpcap/CHANGES
index a820af9ae17..06101172336 100644
--- a/lib/libpcap/CHANGES
+++ b/lib/libpcap/CHANGES
@@ -1,6 +1,148 @@
-$OpenBSD: CHANGES,v 1.4 1996/07/12 13:19:06 mickey Exp $
+$OpenBSD: CHANGES,v 1.5 1999/07/20 04:49:54 deraadt Exp $
$NetBSD: CHANGES,v 1.2 1995/03/06 11:37:58 mycroft Exp $
-@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/CHANGES,v 1.4 1996/07/12 13:19:06 mickey Exp $ (LBL)
+@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/CHANGES,v 1.5 1999/07/20 04:49:54 deraadt Exp $ (LBL)
+
+v0.4 Sat Jul 25 12:40:09 PDT 1998
+
+- Fix endian problem with DLT_NULL devices. From FreeBSD via Bill
+ Fenner (fenner@parc.xerox.com)
+
+- Fix alignment problem with FDDI under DLPI. This was causing core
+ dumps under Solaris.
+
+- Added configure options to disable flex and bison. Resulted from a
+ bug report by barnett@grymoire.crd.ge.com (Bruce Barnett). Also added
+ options to disable gcc and to force a particular packet capture type.
+
+- Added support for Fore ATM interfaces (qaa and fa) under IRIX. Thanks
+ to John Hawkinson (jhawk@mit.edu)
+
+- Change Linux PPP and SLIP to use DLT_RAW since the kernel does not
+ supply any "link layer" data.
+
+- Change Linux to use SIOCGIFHWADDR ioctl to determine link layer type.
+ Thanks to Thomas Sailer (sailer@ife.ee.ethz.ch)
+
+- Change IRIX PPP to use DLT_RAW since the kernel does not supply any
+ "link layer" data.
+
+- Modified to support the new BSD/OS 2.1 PPP and SLIP link layer header
+ formats.
+
+- Added some new SGI snoop interface types. Thanks to Steve Alexander
+ (sca@refugee.engr.sgi.com)
+
+- Fixes for HP-UX 10.20 (which is similar to HP-UX 9). Thanks to
+ Richard Allen (ra@hp.is) and Steinar Haug (sthaug@nethelp.no)
+
+- Fddi supports broadcast as reported by Jeff Macdonald
+ (jeff@iacnet.com). Also correct ieee802 and arcnet.
+
+- Determine Linux pcap buffer size at run time or else it might not be
+ big enough for some interface types (e.g. FDDI). Thanks to Jes
+ Sorensen (Jes.Sorensen@cern.ch)
+
+- Fix some linux alignment problems.
+
+- Document promisc argument to pcap_open_live(). Reported by Ian Marsh
+ (ianm@sics.se)
+
+- Support Metricom radio packets under Linux. Thanks to Kevin Lai
+ (laik@gunpowder.stanford.edu)
+
+- Bind to interface name under Linux to avoid packets from multiple
+ interfaces on multi-homed hosts. Thanks to Kevin Lai
+ (laik@gunpowder.stanford.edu)
+
+- Change L_SET to SEEK_SET for HP-UX. Thanks to Roland Roberts
+ (rroberts@muller.com)
+
+- Fixed an uninitialized memory reference found by Kent Vander Velden
+ (graphix@iastate.edu)
+
+- Fixed lex pattern for IDs to allow leading digits. As reported by
+ Theo de Raadt (deraadt@cvs.openbsd.org)
+
+- Fixed Linux include file problems when using GNU libc.
+
+- Ifdef ARPHRD_FDDI since not all versions of the Linux kernel have it.
+ Reported reported by Eric Jacksch (jacksch@tenebris.ca)
+
+- Fixed bug in pcap_dispatch() that kept it from returning on packet
+ timeouts.
+
+- Changed ISLOOPBACK() macro when IFF_LOOPBACK isn't available to check
+ for "lo" followed by an eos or digit (newer versions of Linux
+ apparently call the loopback "lo" instead of "lo0").
+
+- Fixed Linux networking include files to use ints instead of longs to
+ avoid problems with 64 bit longs on the alpha. Thanks to Cristian
+ Gafton (gafton@redhat.com)
+
+v0.3 Sat Nov 30 20:56:27 PST 1996
+
+- Added Linux support.
+
+- Fixed savefile bugs.
+
+- Solaris x86 fix from Tim Rylance (t.rylance@elsevier.nl)
+
+- Add support for bpf kernel port filters.
+
+- Remove duplicate atalk protocol table entry. Thanks to Christian
+ Hopps (chopps@water.emich.edu)
+
+- Fixed pcap_lookupdev() to ignore nonexistent devices. This was
+ reported to happen under BSD/OS by David Vincenzetti
+ (vince@cryptonet.it)
+
+- Avoid solaris compiler warnings. Thanks to Bruce Barnett
+ (barnett@grymoire.crd.ge.com)
+
+v0.2.1 Sun Jul 14 03:02:26 PDT 1996
+
+- Fixes for HP-UX 10. Thanks in part to to Thomas Wolfram
+ (wolf@prz.tu-berlin.de) and Rick Jones (raj@hpisrdq.cup.hp.com)
+
+- Added support for SINIX. Thanks to Andrej Borsenkow
+ (borsenkow.msk@sni.de)
+
+- Fixes for AIX (although this system is not yet supported). Thanks to
+ John Hawkinson (jhawk@mit.edu)
+
+- Use autoconf's idea of the top level directory in install targets.
+ Thanks to John Hawkinson.
+
+- Add missing autoconf packet capture result message. Thanks to Bill
+ Fenner (fenner@parc.xerox.com)
+
+- Fixed padding problems in the pf module.
+
+- Fixed some more alignment problems on the alpha.
+
+- Added explicit netmask support. Thanks to Steve Nuchia
+ (steve@research.oknet.com)
+
+- Fixed to handle raw ip addresses such as 0.0.0.1 without "left
+ justifing"
+
+- Add "sca" keyword (for DEC cluster services) as suggested by Terry
+ Kennedy (terry@spcvxa.spc.edu)
+
+- Add "atalk" keyword as suggested by John Hawkinson.
+
+- Add "igrp" keyword.
+
+- Fixed HID definition in grammar.y to be a string, not a value.
+
+- Use $CC when checking gcc version. Thanks to Carl Lindberg
+ (carl_lindberg@blacksmith.com)
+
+- Removed obsolete reference to pcap_immediate() from the man page.
+ Michael Stolarchuk (mts@terminator.rs.itd.umich.edu)
+
+- DLT_NULL has a 4 byte family header. Thanks to Jeffrey Honig
+ (jch@bsdi.com)
v0.2 Sun Jun 23 02:28:42 PDT 1996
diff --git a/lib/libpcap/Makefile b/lib/libpcap/Makefile
index 8a55e5e11c5..86c02a5870a 100644
--- a/lib/libpcap/Makefile
+++ b/lib/libpcap/Makefile
@@ -1,26 +1,33 @@
-# $OpenBSD: Makefile,v 1.9 1998/02/26 13:49:51 niklas Exp $
+# $OpenBSD: Makefile,v 1.10 1999/07/20 04:49:54 deraadt Exp $
# $NetBSD: Makefile,v 1.3 1996/05/10 21:54:24 cgd Exp $
LIB= pcap
MAN= pcap.3
-CFLAGS+=-I. -I${.CURDIR} -Dyylval=pcap_yylval -DHAVE_STRERROR -DHAVE_ETHER_HOSTTON
+DEFS= -DHAVE_SYS_IOCCOM_H -DHAVE_SYS_SOCKIO_H -DHAVE_ETHER_HOSTTON \
+ -DHAVE_STRERROR -DHAVE_SOCKADDR_SA_LEN -DLBL_ALIGN
-HDRS= pcap.h pcap-namedb.h
+CFLAGS+=-I. -I${.CURDIR} -Dyylval=pcap_yylval ${DEFS}
+
+HDRS= pcap.h pcap-int.h pcap-namedb.h
SRCS= pcap.c inet.c gencode.c optimize.c nametoaddr.c etherent.c \
savefile.c bpf_filter.c bpf_image.c grammar.y scanner.l \
- pcap-bpf.c
+ pcap-bpf.c version.c
.PATH: ${.CURDIR}/../../sys/net
-CLEANFILES+= grammar.c scanner.c grammar.tab.h
+CLEANFILES+= grammar.c scanner.c grammar.tab.h version.c
-grammar.c: grammar.y
+grammar.c: grammar.y
${YACC.y} -ppcap_yy -b ${.TARGET:R} ${.IMPSRC}
mv ${.TARGET:R}.tab.c ${.TARGET}
-scanner.c: scanner.l grammar.c
+scanner.c: scanner.l grammar.c
${LEX.l} -Ppcap_yy -o${.TARGET} ${.IMPSRC}
+version.c: ${.CURDIR}/VERSION
+ @rm -f $@
+ sed 's/.*/char pcap_version[] = "&";/' ${.CURDIR}/VERSION > $@
+
includes:
@cd ${.CURDIR}; for i in $(HDRS); do \
j="cmp -s $$i ${DESTDIR}/usr/include/$$i || \
diff --git a/lib/libpcap/README b/lib/libpcap/README
index 53a6447ada8..33ce7b0c654 100644
--- a/lib/libpcap/README
+++ b/lib/libpcap/README
@@ -1,12 +1,12 @@
-$OpenBSD: README,v 1.4 1996/07/12 13:19:06 mickey Exp $
+$OpenBSD: README,v 1.5 1999/07/20 04:49:54 deraadt Exp $
$NetBSD: README,v 1.2 1995/03/06 11:38:07 mycroft Exp $
-@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/README,v 1.4 1996/07/12 13:19:06 mickey Exp $ (LBL)
+@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/README,v 1.5 1999/07/20 04:49:54 deraadt Exp $ (LBL)
-LIBPCAP 0.2
+LIBPCAP 0.4
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
diff --git a/lib/libpcap/VERSION b/lib/libpcap/VERSION
new file mode 100644
index 00000000000..bd73f47072b
--- /dev/null
+++ b/lib/libpcap/VERSION
@@ -0,0 +1 @@
+0.4
diff --git a/lib/libpcap/bpf_image.c b/lib/libpcap/bpf_image.c
index 34aaa7418e3..21803920256 100644
--- a/lib/libpcap/bpf_image.c
+++ b/lib/libpcap/bpf_image.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: bpf_image.c,v 1.6 1999/06/17 15:51:07 brad Exp $ */
+/* $OpenBSD: bpf_image.c,v 1.7 1999/07/20 04:49:54 deraadt Exp $ */
/*
- * Copyright (c) 1990, 1991, 1992, 1994, 1995
+ * 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
@@ -22,25 +22,22 @@
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: bpf_image.c,v 1.19 95/11/26 14:02:36 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/bpf_image.c,v 1.7 1999/07/20 04:49:54 deraadt 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"
+
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-
char *
bpf_image(p, n)
struct bpf_insn *p;
diff --git a/lib/libpcap/etherent.c b/lib/libpcap/etherent.c
index 4e2f4fb8f56..48e3db16cee 100644
--- a/lib/libpcap/etherent.c
+++ b/lib/libpcap/etherent.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: etherent.c,v 1.5 1996/09/16 02:33:04 tholo Exp $ */
+/* $OpenBSD: etherent.c,v 1.6 1999/07/20 04:49:54 deraadt Exp $ */
/*
- * Copyright (c) 1990, 1993, 1994, 1995
+ * 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,26 +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.18 95/10/07 03:08:12 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/etherent.c,v 1.6 1999/07/20 04:49:54 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
#include <ctype.h>
#include <memory.h>
-#include <pcap.h>
-#include <pcap-namedb.h>
#include <stdio.h>
#include <string.h>
+#include "pcap-int.h"
+
+#include <pcap-namedb.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-
static __inline int xdtoi(int);
static __inline int skip_space(FILE *);
static __inline int skip_line(FILE *);
diff --git a/lib/libpcap/ethertype.h b/lib/libpcap/ethertype.h
index f745ab69b18..57a6e1c9c96 100644
--- a/lib/libpcap/ethertype.h
+++ b/lib/libpcap/ethertype.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: ethertype.h,v 1.4 1999/06/17 15:51:08 brad Exp $ */
+/* $OpenBSD: ethertype.h,v 1.5 1999/07/20 04:49:54 deraadt Exp $ */
/* $NetBSD: ethertype.h,v 1.2 1995/03/06 11:38:17 mycroft 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
@@ -21,15 +21,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: /cvs/OpenBSD/src/lib/libpcap/ethertype.h,v 1.5 1999/07/20 04:49:54 deraadt 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
@@ -42,6 +47,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
@@ -57,21 +68,12 @@
#ifndef ETHERTYPE_VPROD
#define ETHERTYPE_VPROD 0x805c
#endif
-#ifndef ETHERTYPE_LOOPBACK
-#define ETHERTYPE_LOOPBACK 0x9000
+#ifndef ETHERTYPE_ATALK
+#define ETHERTYPE_ATALK 0x809b
#endif
-
-#ifndef ETHERTYPE_ATALK
-#define ETHERTYPE_ATALK 0x809b /* XXX */
+#ifndef ETHERTYPE_AARP
+#define ETHERTYPE_AARP 0x80f3
#endif
-#ifndef ETHERTYPE_AARP
-#define ETHERTYPE_AARP 0x80f3
-#endif
-#ifndef ETHERTYPE_NS
-#define ETHERTYPE_NS 0x0600
-#endif
-
-#ifndef ETHERTYPE_REVARP
-#define ETHERTYPE_REVARP 0x8035
+#ifndef ETHERTYPE_LOOPBACK
+#define ETHERTYPE_LOOPBACK 0x9000
#endif
-
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c
index 796515b6f77..56fb18a468a 100644
--- a/lib/libpcap/gencode.c
+++ b/lib/libpcap/gencode.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: gencode.c,v 1.10 1998/08/31 19:53:19 deraadt Exp $ */
+/* $OpenBSD: gencode.c,v 1.11 1999/07/20 04:49:54 deraadt Exp $ */
/*
- * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
+ * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -21,8 +21,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: gencode.c,v 1.81 96/06/19 23:09:09 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/gencode.c,v 1.11 1999/07/20 04:49:54 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -35,15 +35,12 @@ 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>
#ifdef __STDC__
#include <stdarg.h>
@@ -51,28 +48,15 @@ struct rtentry;
#include <varargs.h>
#endif
-#ifdef HAVE_OS_PROTO_H
-#include "os-proto.h"
-#endif
-
#include "pcap-int.h"
+#include "ethertype.h"
#include "gencode.h"
+#include "ppp.h"
+#include <pcap-namedb.h>
-#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
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
#endif
#define JMP(c) ((c)|BPF_JMP|BPF_K)
@@ -147,24 +131,23 @@ static void backpatch(struct block *, struct block *);
static void merge(struct block *, struct block *);
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, u_char *);
+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(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
-static struct block *gen_ehostop(u_char *, int);
-static struct block *gen_fhostop(u_char *, 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(u_char *, 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, 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 bpf_u_int32 net_mask(bpf_u_int32 *);
static struct slist *xfer_to_x(struct arth *);
static struct slist *xfer_to_a(struct arth *);
static struct block *gen_len(int, int);
@@ -213,11 +196,12 @@ freechunks()
*/
char *
sdup(s)
- char *s;
+ register const char *s;
{
int n = strlen(s) + 1;
char *cp = newchunk(n);
- strcpy(cp, s);
+
+ strlcpy(cp, s, n);
return (cp);
}
@@ -425,15 +409,17 @@ 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];
- bpf_int32 w = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+ register const u_char *p = &v[size - 4];
+ bpf_int32 w = ((bpf_int32)p[0] << 24) |
+ ((bpf_int32)p[1] << 16) | ((bpf_int32)p[2] << 8) | p[3];
+
tmp = gen_cmp(offset + size - 4, BPF_W, w);
if (b != NULL)
gen_and(b, tmp);
@@ -441,8 +427,9 @@ gen_bcmp(offset, size, v)
size -= 4;
}
while (size >= 2) {
- u_char *p = &v[size - 2];
- bpf_int32 w = (p[0] << 8) | p[1];
+ register const u_char *p = &v[size - 2];
+ bpf_int32 w = ((bpf_int32)p[0] << 8) | p[1];
+
tmp = gen_cmp(offset + size - 2, BPF_H, w);
if (b != NULL)
gen_and(b, tmp);
@@ -489,26 +476,28 @@ init_linktype(type)
off_nl = 16;
return;
- case DLT_NULL:
+ case DLT_SLIP_BSDOS:
+ /* XXX this may be the same as the DLT_PPP_BSDOS case */
off_linktype = -1;
- off_nl = 0;
+ /* XXX end */
+ off_nl = 24;
return;
- case DLT_LOOP:
- off_linktype = -1;
+ case DLT_NULL:
+ off_linktype = 0;
off_nl = 4;
return;
- case DLT_ENC:
- off_linktype = -1;
- off_nl = 12;
- return;
-
case DLT_PPP:
off_linktype = 2;
off_nl = 4;
return;
+ case DLT_PPP_BSDOS:
+ off_linktype = 5;
+ off_nl = 24;
+ return;
+
case DLT_FDDI:
/*
* FDDI doesn't really have a link-level type field.
@@ -538,6 +527,21 @@ init_linktype(type)
off_linktype = 6;
off_nl = 8;
return;
+
+ case DLT_LOOP:
+ off_linktype = -1;
+ off_nl = 4;
+ return;
+
+ case DLT_ENC:
+ off_linktype = -1;
+ off_nl = 12;
+ return;
+
+ case DLT_RAW:
+ off_linktype = -1;
+ off_nl = 0;
+ return;
}
bpf_error("unknown data link type 0x%x", linktype);
/* NOTREACHED */
@@ -572,32 +576,55 @@ gen_false()
static struct block *
gen_linktype(proto)
- int proto;
+ register int proto;
{
+ struct block *b0, *b1;
+
+ /* If we're not using encapsulation and checking for IP, we're done */
+ if (off_linktype == -1 && proto == ETHERTYPE_IP)
+ return gen_true();
+
switch (linktype) {
+
case DLT_SLIP:
- if (proto == ETHERTYPE_IP)
- return gen_true();
- else
- return gen_false();
+ return gen_false();
case DLT_PPP:
if (proto == ETHERTYPE_IP)
- proto = 0x0021; /* XXX - need ppp.h defs */
+ proto = PPP_IP; /* XXX was 0x21 */
break;
- case DLT_LOOP:
- if (proto == ETHERTYPE_IP)
- return (gen_cmp(0, BPF_W, (bpf_int32) AF_INET));
- else
- return gen_false();
+ case DLT_PPP_BSDOS:
+ switch (proto) {
+
+ case ETHERTYPE_IP:
+ b0 = gen_cmp(off_linktype, BPF_H, PPP_IP);
+ b1 = gen_cmp(off_linktype, BPF_H, PPP_VJC);
+ gen_or(b0, b1);
+ b0 = gen_cmp(off_linktype, BPF_H, PPP_VJNC);
+ gen_or(b1, b0);
+ return b0;
+
+ case ETHERTYPE_DN:
+ proto = PPP_DECNET;
+ break;
+
+ case ETHERTYPE_ATALK:
+ proto = PPP_APPLE;
+ break;
+
+ case ETHERTYPE_NS:
+ proto = PPP_NS;
+ break;
+ }
break;
+ case DLT_LOOP:
case DLT_ENC:
case DLT_NULL:
/* XXX */
if (proto == ETHERTYPE_IP)
- return (gen_cmp(0, BPF_W, htonl((bpf_int32) AF_INET)));
+ return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET)));
else
return gen_false();
}
@@ -648,10 +675,10 @@ gen_hostop(addr, mask, dir, proto, src_off, dst_off)
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:
@@ -682,8 +709,8 @@ gen_ehostop(eaddr, dir)
*/
static struct block *
gen_fhostop(eaddr, dir)
- u_char *eaddr;
- int dir;
+ register const u_char *eaddr;
+ register int dir;
{
struct block *b0, *b1;
@@ -850,9 +877,18 @@ gen_host(addr, mask, proto, dir)
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");
@@ -870,7 +906,7 @@ gen_host(addr, mask, proto, dir)
static struct block *
gen_gateway(eaddr, alist, proto, dir)
- u_char *eaddr;
+ const u_char *eaddr;
bpf_u_int32 **alist;
int proto;
int dir;
@@ -893,9 +929,9 @@ gen_gateway(eaddr, alist, proto, dir)
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;
}
@@ -939,6 +975,15 @@ gen_proto_abbrev(proto)
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;
+
case Q_IP:
b1 = gen_linktype(ETHERTYPE_IP);
break;
@@ -954,10 +999,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;
@@ -1087,12 +1140,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);
@@ -1141,10 +1195,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 */
@@ -1176,6 +1238,10 @@ gen_proto(v, proto, dir)
bpf_error("'igmp proto' is bogus");
/* NOTREACHED */
+ case Q_IGRP:
+ bpf_error("'igrp proto' is bogus");
+ /* NOTREACHED */
+
default:
abort();
/* NOTREACHED */
@@ -1183,29 +1249,14 @@ gen_proto(v, proto, dir)
/* NOTREACHED */
}
-/*
- * Left justify 'addr' and return its resulting network mask.
- */
-static bpf_u_int32
-net_mask(addr)
- bpf_u_int32 *addr;
-{
- register bpf_u_int32 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;
+ int tproto;
u_char *eaddr;
bpf_u_int32 mask, addr, **alist;
struct block *b, *tmp;
@@ -1217,7 +1268,12 @@ 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:
@@ -1255,10 +1311,13 @@ 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);
+ tproto = proto;
+ if (off_linktype == -1 && tproto == Q_DEFAULT)
+ tproto = Q_IP;
+ b = gen_host(**alist++, 0xffffffff, tproto, dir);
while (*alist) {
- tmp = gen_host(**alist++, 0xffffffffL,
- proto, dir);
+ tmp = gen_host(**alist++, 0xffffffff,
+ tproto, dir);
gen_or(b, tmp);
b = tmp;
}
@@ -1312,13 +1371,63 @@ gen_scode(name, q)
}
struct block *
-gen_ncode(v, q)
+gen_mcode(s1, s2, masklen, q)
+ register const char *s1, *s2;
+ register int masklen;
+ struct qual q;
+{
+ 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;
+ if ((n & ~m) != 0)
+ bpf_error("non-network bits set in \"%s mask %s\"",
+ s1, s2);
+ } else {
+ /* Convert mask len to mask */
+ if (masklen > 32)
+ bpf_error("mask length must be <= 32");
+ m = 0xffffffff << (32 - masklen);
+ if ((n & ~m) != 0)
+ bpf_error("non-network bits set in \"%s/%d\"",
+ s1, 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) {
@@ -1330,7 +1439,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);
}
@@ -1366,7 +1486,7 @@ 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) {
@@ -1456,7 +1576,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:
@@ -1477,6 +1599,7 @@ gen_load(proto, index, size)
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));
diff --git a/lib/libpcap/gencode.h b/lib/libpcap/gencode.h
index 68eea820dbb..21c6afeac36 100644
--- a/lib/libpcap/gencode.h
+++ b/lib/libpcap/gencode.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.h,v 1.5 1997/07/25 20:30:18 mickey Exp $ */
+/* $OpenBSD: gencode.h,v 1.6 1999/07/20 04:49:54 deraadt Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -20,7 +20,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) Header: gencode.h,v 1.33 96/06/23 02:21:09 leres Exp (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/gencode.h,v 1.6 1999/07/20 04:49:54 deraadt Exp $ (LBL)
*/
/* Address qualifiers. */
@@ -41,11 +41,15 @@
#define Q_UDP 6
#define Q_ICMP 7
#define Q_IGMP 8
+#define Q_IGRP 9
-#define Q_DECNET 9
-#define Q_LAT 10
-#define Q_MOPRC 11
-#define Q_MOPDL 12
+
+#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. */
@@ -142,9 +146,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(bpf_u_int32, 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);
@@ -161,7 +166,7 @@ __dead void bpf_error(const char *, ...)
#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);
diff --git a/lib/libpcap/grammar.y b/lib/libpcap/grammar.y
index e3874727603..57efdd2ed1a 100644
--- a/lib/libpcap/grammar.y
+++ b/lib/libpcap/grammar.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: grammar.y,v 1.5 1997/07/25 20:30:19 mickey Exp $ */
+/* $OpenBSD: grammar.y,v 1.6 1999/07/20 04:49:54 deraadt Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -23,8 +23,8 @@
*
*/
#ifndef lint
-static char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/grammar.y,v 1.5 1997/07/25 20:30:19 mickey Exp $ (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/grammar.y,v 1.6 1999/07/20 04:49:54 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -37,22 +37,21 @@ 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-int.h"
+
+#include "gencode.h"
#include <pcap-namedb.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-#include "gencode.h"
-
#define QSET(q, p, d, a) (q).proto = (p),\
(q).dir = (d),\
(q).addr = (a)
@@ -65,7 +64,7 @@ static void
yyerror(char *msg)
{
++n_errors;
- bpf_error(msg);
+ bpf_error("%s", msg);
/* NOTREACHED */
}
@@ -83,7 +82,7 @@ pcap_parse()
%union {
int i;
- u_long h;
+ bpf_u_int32 h;
u_char *e;
char *s;
struct stmt *stmt;
@@ -104,9 +103,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 IGMP
-%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
@@ -117,7 +116,7 @@ pcap_parse()
%type <s> ID
%type <e> EID
-%type <h> HID
+%type <s> HID
%type <i> NUM
%left OR AND
@@ -148,24 +147,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;
}
}
@@ -180,7 +179,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
;
@@ -230,8 +229,11 @@ pname: LINK { $$ = Q_LINK; }
| 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; }
;
diff --git a/lib/libpcap/inet.c b/lib/libpcap/inet.c
index 11e6b1b995e..151fb05e61e 100644
--- a/lib/libpcap/inet.c
+++ b/lib/libpcap/inet.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: inet.c,v 1.10 1998/08/27 22:36:33 mickey Exp $ */
+/* $OpenBSD: inet.c,v 1.11 1999/07/20 04:49:55 deraadt Exp $ */
/*
- * Copyright (c) 1994, 1995, 1996
+ * Copyright (c) 1994, 1995, 1996, 1997, 1998
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,8 +34,8 @@
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: inet.c,v 1.16 96/06/23 14:28:22 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/inet.c,v 1.11 1999/07/20 04:49:55 deraadt Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -45,6 +45,7 @@ static char rcsid[] =
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
+#include <sys/time.h> /* concession to AIX */
#ifdef __STDC__
struct mbuf;
@@ -61,19 +62,19 @@ struct rtentry;
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <pcap.h>
+
+#include "pcap-int.h"
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-
/* Not all systems have IFF_LOOPBACK */
#ifdef IFF_LOOPBACK
#define ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
#else
-#define ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
+#define ISLOOPBACK(p) ((p)->ifr_name[0] == 'l' && (p)->ifr_name[1] == 'o' && \
+ (isdigit((p)->ifr_name[2]) || (p)->ifr_name[2] == '\0'))
#endif
/*
@@ -144,8 +145,12 @@ pcap_lookupdev(errbuf)
*/
strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
+ if (errno == ENXIO)
+ continue;
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "SIOCGIFFLAGS: %s", pcap_strerror(errno));
+ "SIOCGIFFLAGS: %.*s: %s",
+ (int)sizeof(ifr.ifr_name), ifr.ifr_name,
+ pcap_strerror(errno));
(void)close(fd);
free(ibuf);
return (NULL);
@@ -165,7 +170,8 @@ pcap_lookupdev(errbuf)
}
(void)close(fd);
if (mp == NULL) {
- (void)strcpy(errbuf, "no suitable device found");
+ (void)strlcpy(errbuf, "no suitable device found",
+ PCAP_ERRBUF_SIZE);
free(ibuf);
return (NULL);
}
diff --git a/lib/libpcap/nametoaddr.c b/lib/libpcap/nametoaddr.c
index 81efe479287..2c04745ab10 100644
--- a/lib/libpcap/nametoaddr.c
+++ b/lib/libpcap/nametoaddr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nametoaddr.c,v 1.6 1997/07/25 20:30:20 mickey Exp $ */
+/* $OpenBSD: nametoaddr.c,v 1.7 1999/07/20 04:49:55 deraadt Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -25,12 +25,14 @@
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: nametoaddr.c,v 1.38 96/06/17 02:42:50 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/nametoaddr.c,v 1.7 1999/07/20 04:49:55 deraadt Exp $ (LBL)";
#endif
#include <sys/param.h>
+#include <sys/types.h> /* concession to AIX */
#include <sys/socket.h>
+#include <sys/time.h>
#ifdef __STDC__
struct mbuf;
@@ -47,17 +49,17 @@ struct rtentry;
#include <stdlib.h>
#include <memory.h>
#include <netdb.h>
-#include <pcap.h>
-#include <pcap-namedb.h>
#include <stdio.h>
+#include "pcap-int.h"
+
+#include "gencode.h"
+#include <pcap-namedb.h>
+
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-#include "gencode.h"
-
#ifndef NTOHL
#define NTOHL(x) (x) = ntohl(x)
#define NTOHS(x) (x) = ntohs(x)
@@ -191,6 +193,7 @@ struct eproto eproto_db[] = {
{ "moprc", ETHERTYPE_MOPRC },
{ "decnet", ETHERTYPE_DN },
{ "lat", ETHERTYPE_LAT },
+ { "sca", ETHERTYPE_SCA },
{ "lanbridge", ETHERTYPE_LANBRIDGE },
{ "vexp", ETHERTYPE_VEXP },
{ "vprod", ETHERTYPE_VPROD },
@@ -228,42 +231,44 @@ xdtoi(c)
return c - 'A' + 10;
}
-bpf_u_int32
-__pcap_atoin(const char *s)
+int
+__pcap_atoin(const char *s, bpf_u_int32 *addr)
{
- bpf_u_int32 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 */
}
-bpf_u_int32
-__pcap_atodn(const char *s)
+int
+__pcap_atodn(const char *s, bpf_u_int32 *addr)
{
#define AREASHIFT 10
#define AREAMASK 0176000
#define NODEMASK 01777
- bpf_u_int32 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);
}
/*
@@ -341,7 +346,7 @@ pcap_ether_hostton(const char *name)
if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) {
ap = (u_char *)malloc(6);
if (ap != NULL)
- memcpy(ap, a, 6);
+ memcpy((char *)ap, (char *)a, 6);
}
return (ap);
}
diff --git a/lib/libpcap/optimize.c b/lib/libpcap/optimize.c
index d3c420b6e45..9309f55a87d 100644
--- a/lib/libpcap/optimize.c
+++ b/lib/libpcap/optimize.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: optimize.c,v 1.5 1996/09/16 02:33:07 tholo Exp $ */
+/* $OpenBSD: optimize.c,v 1.6 1999/07/20 04:49:55 deraadt Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -23,26 +23,25 @@
* Optimization module for tcpdump intermediate representation.
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: optimize.c,v 1.58 96/06/16 22:36:59 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/optimize.c,v 1.6 1999/07/20 04:49:55 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
#include <sys/time.h>
-#include <net/bpf.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
+#include "pcap-int.h"
+
+#include "gencode.h"
+
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-#include "gencode.h"
-
#ifdef BDEBUG
extern int dflag;
#endif
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c
index b0499163992..57e1b2eaf77 100644
--- a/lib/libpcap/pcap-bpf.c
+++ b/lib/libpcap/pcap-bpf.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pcap-bpf.c,v 1.9 1998/07/14 00:14:03 deraadt Exp $ */
+/* $OpenBSD: pcap-bpf.c,v 1.10 1999/07/20 04:49:55 deraadt Exp $ */
/*
- * Copyright (c) 1993, 1994, 1995, 1996
+ * Copyright (c) 1993, 1994, 1995, 1996, 1998
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -21,8 +21,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
-static char rcsid[] =
- "@(#)Header: pcap-bpf.c,v 1.25 96/06/24 02:50:11 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap-bpf.c,v 1.10 1999/07/20 04:49:55 deraadt Exp $ (LBL)";
#endif
#include <sys/param.h> /* optionally get BSD define */
@@ -32,23 +32,22 @@ static char rcsid[] =
#include <sys/file.h>
#include <sys/ioctl.h>
-#include <net/bpf.h>
#include <net/if.h>
#include <ctype.h>
#include <errno.h>
-#include <stdlib.h>
#include <netdb.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "pcap-int.h"
+
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
@@ -200,6 +199,14 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
"kernel bpf filter out of date");
goto bad;
}
+ v = 32768; /* XXX this should be a user-accessible hook */
+ /* Ignore the return value - this is because the call fails on
+ * BPF systems that don't have kernel malloc. And if the call
+ * fails, it's no big deal, we just continue to use the standard
+ * buffer size.
+ */
+ (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v);
+
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s",
@@ -212,6 +219,19 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
pcap_strerror(errno));
goto bad;
}
+#if _BSDI_VERSION - 0 >= 199510
+ /* The SLIP and PPP link layer header changed in BSD/OS 2.1 */
+ switch (v) {
+
+ case DLT_SLIP:
+ v = DLT_SLIP_BSDOS;
+ break;
+
+ case DLT_PPP:
+ v = DLT_PPP_BSDOS;
+ break;
+ }
+#endif
p->linktype = v;
/* set timeout */
diff --git a/lib/libpcap/pcap-int.h b/lib/libpcap/pcap-int.h
index 4b64994c83b..49a416d6030 100644
--- a/lib/libpcap/pcap-int.h
+++ b/lib/libpcap/pcap-int.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: pcap-int.h,v 1.6 1996/08/03 12:38:44 niklas Exp $ */
+/* $OpenBSD: pcap-int.h,v 1.7 1999/07/20 04:49:55 deraadt Exp $ */
/*
- * Copyright (c) 1994, 1995
+ * 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.14 95/10/21 22:04:49 leres Exp (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap-int.h,v 1.7 1999/07/20 04:49:55 deraadt Exp $ (LBL)
*/
#ifndef pcap_int_h
@@ -60,6 +60,11 @@ struct pcap_md {
u_long TotDrops; /* count of dropped packets */
long TotMissed; /* missed by i/f during this run */
long OrigMissed; /* missed by i/f before this run */
+#ifdef linux
+ int pad;
+ int skip;
+ char *device;
+#endif
};
struct pcap {
@@ -67,6 +72,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;
@@ -95,6 +101,10 @@ struct pcap {
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 *);
@@ -103,4 +113,7 @@ int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
#if defined(ultrix) || defined(__alpha)
#define PCAP_FDDIPAD 3
#endif
+
+/* XXX */
+extern int pcap_fddipad;
#endif
diff --git a/lib/libpcap/pcap-namedb.h b/lib/libpcap/pcap-namedb.h
index 1d0fd07d706..60a3288c53c 100644
--- a/lib/libpcap/pcap-namedb.h
+++ b/lib/libpcap/pcap-namedb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap-namedb.h,v 1.4 1996/07/12 13:19:11 mickey Exp $ */
+/* $OpenBSD: pcap-namedb.h,v 1.5 1999/07/20 04:49:55 deraadt Exp $ */
/*
* Copyright (c) 1994, 1996
@@ -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.4 96/06/23 02:21:08 leres Exp (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap-namedb.h,v 1.5 1999/07/20 04:49:55 deraadt Exp $ (LBL)
*/
#ifndef lib_pcap_ethers_h
@@ -71,8 +71,8 @@ int pcap_nametoeproto(const char *);
#define PROTO_UNDEF -1
/* XXX move these to pcap-int.h? */
-bpf_u_int32 __pcap_atodn(const char *);
-bpf_u_int32 __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
diff --git a/lib/libpcap/pcap.3 b/lib/libpcap/pcap.3
index bc5d1ad943f..355d4cdcdb3 100644
--- a/lib/libpcap/pcap.3
+++ b/lib/libpcap/pcap.3
@@ -1,6 +1,6 @@
.\" $NetBSD: pcap.3,v 1.2.6.1 1996/06/05 18:04:43 cgd Exp $
.\"
-.\" Copyright (c) 1994
+.\" Copyright (c) 1994, 1996, 1997
.\" 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.
.\"
-.Dd June 4, 1999
+.Dd July 5, 1999
.Dt PCAP 3
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Ft "char *"
.Fn pcap_lookupdev "char *errbuf"
.Ft uint
-.Fn pcap_lookupnet "char *device" "u_int32_t *netp" "u_int32_t *maskp" "char *errbuf"
+.Fn pcap_lookupnet "char *device" "bpf_u_int32 *netp" "bpf_u_int32 *maskp" "char *errbuf"
.Ft int
.Fn pcap_dispatch "pcap_t *p" "int cnt" "pcap_handler callback" "u_char *user"
.Ft int
@@ -46,9 +46,7 @@
.Ft int
.Fn pcap_inject "pcap_t *p" "void *, size_t"
.Ft int
-.Fn pcap_immediate "pcap_t *p"
-.Ft int
-.Fn pcap_compile "pcap_t *p" "struct bpf_program *fp" "char *str" "int optimize" "u_int32_t netmask"
+.Fn pcap_compile "pcap_t *p" "struct bpf_program *fp" "char *str" "int optimize" "bpf_u_int32 netmask"
.Ft int
.Fn pcap_setfilter "pcap_t *p" "struct bpf_program *fp"
.Ft "u_char *"
@@ -104,6 +102,10 @@ at packets on the network.
is a string that specifies the network device to open.
.Fa snaplen
specifies the maximum number of bytes to capture.
+.Fa promisc
+specifies if the interface is to be put into promiscuous mode.
+(Note that even if this parameter is false, the interface
+could well be in promiscuous mode for some other reason.)
.Fa to_ms
specifies the read timeout in milliseconds.
.Fa errbuf
@@ -175,7 +177,7 @@ Both
and
.Fa maskp
are
-.Fa u_int32_t
+.Fa bpf_u_int32
pointers.
A return of \-1 indicates an error in which case
.Fa errbuf
@@ -188,9 +190,10 @@ specifies the maximum number of packets to process before returning. A
.Fa cnt
of \-1 processes all the packets received in one buffer. A
.Fa cnt
-of 0 processes all packets until an error occurs (or
+of 0 processes all packets until an error occurs,
.Tn EOF
-is reached).
+is reached, or the read times out (when doing live reads and a non-zero
+read timeout is specified).
.Fa callback
specifies a routine to be called with three arguments: a
.Fa u_char
@@ -199,7 +202,9 @@ pointer which is passed in from
a pointer to the
.Fa pcap_pkthdr
struct (which precede the actual network headers and data),
-and a length. The number of packets read is returned.
+and a
+.Fa u_char
+pointer to the packet data. The number of packets read is returned.
Zero is returned when
.Tn EOF
is reached in a savefile.
@@ -220,15 +225,6 @@ uses
.Xr write 2
to inject a raw packet through the network interface.
.Pp
-.Fn pcap_immediate
-sets
-.Dq immediate
-mode. If this isn't supported by the underlying packet capture, \-1 is
-returned and the error text can be obtained with
-.Fn pcap_perror
-or
-.Fn pcap_geterr .
-.Pp
.Fn pcap_compile
is used to compile the string
.Fa str
@@ -244,19 +240,33 @@ controls whether optimization on the resulting code is performed.
specifies the netmask of the local net.
.Pp
.Fn pcap_setfilter
-is used to specify the filter program.
+is used to specify a filter program.
.Fa fp
is a pointer to an array of
.Fa bpf_program
struct, usually the result of a call to
.Fn pcap_compile .
+.Fn \-1
+is returned on failure;
+.Fn 0
+is returned on success.
.Pp
.Fn pcap_loop
is similar to
.Fn pcap_dispatch
except it keeps reading packets until
.Fa cnt
-packets are processed or an error occurs. A negative
+packets are processed or an error occurs.
+It does
+.Fn not
+return when live read timeouts occur.
+Rather, specifying a non-zero read timeout to
+.Fn pcap_open_live()
+and then calling
+.Fn pcap_dispatch()
+allows the reception and processing of any packets that arrive when the
+timeout occurs.
+A negative
.Fa cnt
causes
.Fn pcap_loop
@@ -292,7 +302,8 @@ returns the name of the savefile.
.Fn pcap_stats
returns 0 and fills in a
.Fa pcap_stat
-struct with packet statistics. If there is an error or the underlying
+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
.Fn pcap_perror
@@ -326,3 +337,12 @@ closes the savefile.
.Sh SEE ALSO
.Xr tcpdump 8
.\" , tcpslice(1)
+.Sh AUTHORS
+Van Jacobson,
+Craig Leres and
+Steven McCanne, all of the
+Lawrence Berkeley National Laboratory, University of California, Berkeley, CA.
+.Sh BUGS
+Please send bug reports to
+.Xr libpcap@ee.lbl.gov .
+m \ No newline at end of file
diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c
index 05eb2ee4861..3a10e49db91 100644
--- a/lib/libpcap/pcap.c
+++ b/lib/libpcap/pcap.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pcap.c,v 1.5 1998/07/14 00:14:04 deraadt Exp $ */
+/* $OpenBSD: pcap.c,v 1.6 1999/07/20 04:49:55 deraadt Exp $ */
/*
- * Copyright (c) 1993, 1994, 1995, 1996
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,8 +34,8 @@
*/
#ifndef lint
-static char rcsid[] =
- "@(#) Header: pcap.c,v 1.25 96/06/05 21:45:26 leres Exp (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap.c,v 1.6 1999/07/20 04:49:55 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -54,22 +54,29 @@ static char rcsid[] =
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));
- /* XXX keep reading until we get something (or an error occurs) */
- do {
- cc = pcap_read(p, cnt, callback, user);
- } while (cc == 0);
- return (cc);
+ return (pcap_read(p, cnt, callback, user));
}
int
pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
+ register int n;
+
for (;;) {
- int n = pcap_dispatch(p, cnt, callback, user);
+ if (p->sf.rfile != NULL)
+ n = pcap_offline_read(p, cnt, callback, user);
+ else {
+ /*
+ * XXX keep reading until we get something
+ * (or an error occurs)
+ */
+ do {
+ n = pcap_read(p, cnt, callback, user);
+ } while (n == 0);
+ }
if (n <= 0)
return (n);
if (cnt > 0) {
@@ -191,6 +198,10 @@ pcap_close(pcap_t *p)
free(p->sf.base);
} else if (p->buffer != NULL)
free(p->buffer);
-
+#ifdef linux
+ if (p->md.device != NULL)
+ free(p->md.device);
+#endif
+
free(p);
}
diff --git a/lib/libpcap/pcap.h b/lib/libpcap/pcap.h
index d95adc6fec4..487e3dabf79 100644
--- a/lib/libpcap/pcap.h
+++ b/lib/libpcap/pcap.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: pcap.h,v 1.6 1996/07/12 13:19:12 mickey Exp $ */
+/* $OpenBSD: pcap.h,v 1.7 1999/07/20 04:49:55 deraadt Exp $ */
/*
- * Copyright (c) 1993, 1994, 1995, 1996
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -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.19 96/06/16 22:36:28 leres Exp (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap.h,v 1.7 1999/07/20 04:49:55 deraadt Exp $ (LBL)
*/
#ifndef lib_pcap_h
@@ -104,7 +104,7 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
char *pcap_lookupdev(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 *);
+pcap_t *pcap_open_offline(const char *, char *);
void pcap_close(pcap_t *);
int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
@@ -129,15 +129,11 @@ int pcap_minor_version(pcap_t *);
FILE *pcap_file(pcap_t *);
int pcap_fileno(pcap_t *);
-pcap_dumper_t *pcap_dump_open(pcap_t *, char *);
+pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
void pcap_dump_close(pcap_dumper_t *);
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);
-
-/* XXX */
-extern int pcap_fddipad;
-
#endif
diff --git a/lib/libpcap/ppp.h b/lib/libpcap/ppp.h
new file mode 100644
index 00000000000..0b666d6e48a
--- /dev/null
+++ b/lib/libpcap/ppp.h
@@ -0,0 +1,52 @@
+/* $OpenBSD: ppp.h,v 1.1 1999/07/20 04:49:56 deraadt Exp $ */
+
+/* @(#) $Header: /cvs/OpenBSD/src/lib/libpcap/ppp.h,v 1.1 1999/07/20 04:49:56 deraadt Exp $ (LBL) */
+/*
+ * Point to Point Protocol (PPP) RFC1331
+ *
+ * Copyright 1989 by Carnegie Mellon.
+ *
+ * Permission to use, copy, modify, and distribute this program for any
+ * purpose and without fee is hereby granted, provided that this copyright
+ * and permission notice appear on all copies and supporting documentation,
+ * the name of Carnegie Mellon not be used in advertising or publicity
+ * pertaining to distribution of the program without specific prior
+ * permission, and notice be given in supporting documentation that copying
+ * and distribution is by permission of Carnegie Mellon and Stanford
+ * University. Carnegie Mellon makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ */
+#define PPP_ADDRESS 0xff /* The address byte value */
+#define PPP_CONTROL 0x03 /* The control byte value */
+
+/* Protocol numbers */
+#define PPP_IP 0x0021 /* Raw IP */
+#define PPP_OSI 0x0023 /* OSI Network Layer */
+#define PPP_NS 0x0025 /* Xerox NS IDP */
+#define PPP_DECNET 0x0027 /* DECnet Phase IV */
+#define PPP_APPLE 0x0029 /* Appletalk */
+#define PPP_IPX 0x002b /* Novell IPX */
+#define PPP_VJC 0x002d /* Van Jacobson Compressed TCP/IP */
+#define PPP_VJNC 0x002f /* Van Jacobson Uncompressed TCP/IP */
+#define PPP_BRPDU 0x0031 /* Bridging PDU */
+#define PPP_STII 0x0033 /* Stream Protocol (ST-II) */
+#define PPP_VINES 0x0035 /* Banyan Vines */
+
+#define PPP_HELLO 0x0201 /* 802.1d Hello Packets */
+#define PPP_LUXCOM 0x0231 /* Luxcom */
+#define PPP_SNS 0x0233 /* Sigma Network Systems */
+
+#define PPP_IPCP 0x8021 /* IP Control Protocol */
+#define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */
+#define PPP_NSCP 0x8025 /* Xerox NS IDP Control Protocol */
+#define PPP_DECNETCP 0x8027 /* DECnet Control Protocol */
+#define PPP_APPLECP 0x8029 /* Appletalk Control Protocol */
+#define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */
+#define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */
+#define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */
+
+#define PPP_LCP 0xc021 /* Link Control Protocol */
+#define PPP_PAP 0xc023 /* Password Authentication Protocol */
+#define PPP_LQM 0xc025 /* Link Quality Monitoring */
+#define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */
diff --git a/lib/libpcap/savefile.c b/lib/libpcap/savefile.c
index 07897d9a593..d47e46130dd 100644
--- a/lib/libpcap/savefile.c
+++ b/lib/libpcap/savefile.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: savefile.c,v 1.6 1999/07/19 23:25:29 deraadt Exp $ */
+/* $OpenBSD: savefile.c,v 1.7 1999/07/20 04:49:56 deraadt Exp $ */
/*
- * Copyright (c) 1993, 1994, 1995
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -19,13 +19,7 @@
* 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: savefile.c,v 1.28 95/10/07 03:09:06 leres Exp (LBL)";
-#endif
-
-/*
+ *
* savefile.c - supports offline use of tcpdump
* Extraction/creation by Jeffrey Mogul, DECWRL
* Modified by Steve McCanne, LBL.
@@ -36,11 +30,14 @@ static char rcsid[] =
* dependent values so we can print the dump file on any architecture.
*/
+#ifndef lint
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/savefile.c,v 1.7 1999/07/20 04:49:56 deraadt Exp $ (LBL)";
+#endif
+
#include <sys/types.h>
#include <sys/time.h>
-#include <net/bpf.h>
-
#include <errno.h>
#include <memory.h>
#include <stdio.h>
@@ -68,7 +65,7 @@ static char rcsid[] =
#define SWAPLONG(y) \
((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
#define SWAPSHORT(y) \
- ( (((y)&0xff)<<8) | (((y)&0xff00)>>8) )
+ ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
#define SFERR_TRUNC 1
#define SFERR_BADVERSION 2
@@ -107,7 +104,7 @@ swap_hdr(struct pcap_file_header *hp)
}
pcap_t *
-pcap_open_offline(char *fname, char *errbuf)
+pcap_open_offline(const char *fname, char *errbuf)
{
register pcap_t *p;
register FILE *fp;
@@ -116,7 +113,7 @@ pcap_open_offline(char *fname, char *errbuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- strcpy(errbuf, "out of swap");
+ strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE);
return (NULL);
}
@@ -182,12 +179,16 @@ pcap_open_offline(char *fname, char *errbuf)
p->bufsize = BPF_MAXBUFSIZE;
p->sf.base = (u_char *)malloc(p->bufsize + BPF_ALIGNMENT);
if (p->sf.base == NULL) {
- strlcpy(errbuf, "out of swap", PCAP_ERRBUFF_SIZE);
+ strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE);
goto bad;
}
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:
@@ -241,12 +242,19 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
static u_char *tp = NULL;
static int tsize = 0;
+ if (hdr->caplen > 65535) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "bogus savefile header");
+ return (-1);
+ }
+
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) {
+ tsize = 0;
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"BUFMOD hack malloc");
return (-1);
@@ -257,6 +265,14 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
"truncated dump file");
return (-1);
}
+ /*
+ * We can only keep up to buflen bytes. Since caplen > buflen
+ * is exactly how we got here, we know we can only keep the
+ * first buflen bytes and must drop the remainder. Adjust
+ * caplen accordingly, so we don't get confused later as
+ * to how many bytes we have to play with.
+ */
+ hdr->caplen = buflen;
memcpy((char *)buf, (char *)tp, buflen);
} else {
@@ -321,7 +337,7 @@ pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
* Initialize so that sf_write() will output to the file named 'fname'.
*/
pcap_dumper_t *
-pcap_dump_open(pcap_t *p, char *fname)
+pcap_dump_open(pcap_t *p, const char *fname)
{
FILE *f;
if (fname[0] == '-' && fname[1] == '\0')
diff --git a/lib/libpcap/scanner.l b/lib/libpcap/scanner.l
index 4741d903d64..ca86de940e4 100644
--- a/lib/libpcap/scanner.l
+++ b/lib/libpcap/scanner.l
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: scanner.l,v 1.7 1998/06/26 21:01:03 deraadt Exp $ */
+/* $OpenBSD: scanner.l,v 1.8 1999/07/20 04:49:56 deraadt Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -23,8 +23,8 @@
*/
#ifndef lint
-static char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/scanner.l,v 1.7 1998/06/26 21:01:03 deraadt Exp $ (LBL)";
+static const char rcsid[] =
+ "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/scanner.l,v 1.8 1999/07/20 04:49:56 deraadt Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -33,21 +33,22 @@ static char rcsid[] =
#include <ctype.h>
#include <unistd.h>
-#include <pcap.h>
+#include "pcap-int.h"
+
+#include "gencode.h"
#include <pcap-namedb.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
-#include "pcap-int.h"
-#include "gencode.h"
#include "grammar.tab.h"
static int stoi(char *);
static inline int xdtoi(int);
#ifdef FLEX_SCANNER
+#define YY_NO_UNPUT
#undef YY_INPUT
#define YY_INPUT(buf, result, max)\
{\
@@ -92,14 +93,18 @@ 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;
@@ -133,7 +138,7 @@ outbound return OUTBOUND;
{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
return EID; }
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
-[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
+[A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
yylval.s = sdup((char *)yytext); return ID; }
"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
diff --git a/lib/libpcap/shlib_version b/lib/libpcap/shlib_version
index dea2b62cafc..1edea46de91 100644
--- a/lib/libpcap/shlib_version
+++ b/lib/libpcap/shlib_version
@@ -1,2 +1,2 @@
-major=0
-minor=2
+major=1
+minor=0