aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CREDITS1
-rw-r--r--FILES2
-rw-r--r--Makefile.in14
-rw-r--r--bpf/net/bpf_filter.c4
-rw-r--r--packaging/pcap.spec8
-rw-r--r--pcap-bpf.c195
-rw-r--r--pcap-bpf.h (renamed from bpf/net/bpf.h)100
-rw-r--r--pcap-enet.c4
-rw-r--r--pcap.h6
9 files changed, 226 insertions, 108 deletions
diff --git a/CREDITS b/CREDITS
index ee26f8c7..1f16f69e 100644
--- a/CREDITS
+++ b/CREDITS
@@ -60,6 +60,7 @@ Additional people who have contributed patches:
Rick Jones <raj@cup.hp.com>
Scott Barron <sb125499@ohiou.edu>
Scott Gifford <sgifford@tir.com>
+ Shaun <delius@progsoc.uts.edu.au>
Solomon Peachy <pizza@shaftnet.org>
Stefan Hudson <hudson@mbay.net>
Tony Li <tli@procket.com>
diff --git a/FILES b/FILES
index 18a14a09..ff0ef989 100644
--- a/FILES
+++ b/FILES
@@ -16,7 +16,6 @@ VERSION
aclocal.m4
arcnet.h
atmuni31.h
-bpf/net/bpf.h
bpf/net/bpf_filter.c
bpf_dump.c
bpf_image.c
@@ -50,6 +49,7 @@ nametoaddr.c
nlpid.h
optimize.c
pcap-bpf.c
+pcap-bpf.h
pcap-dlpi.c
pcap-enet.c
pcap-int.h
diff --git a/Makefile.in b/Makefile.in
index cfd5c4cc..0b94eb1d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -17,7 +17,7 @@
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
-# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.89 2002-07-27 18:45:34 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.90 2003-02-11 01:46:05 guy Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -87,7 +87,7 @@ GENHDR = \
tokdefs.h
TAGHDR = \
- bpf/net/bpf.h
+ pcap-bpf.h
TAGFILES = \
$(SRC) $(HDR) $(TAGHDR)
@@ -144,12 +144,10 @@ install:
[ -d $(DESTDIR)$(includedir) ] || \
(mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
$(INSTALL_DATA) $(srcdir)/pcap.h $(DESTDIR)$(includedir)/pcap.h
+ $(INSTALL_DATA) $(srcdir)/pcap-bpf.h \
+ $(DESTDIR)$(includedir)/pcap-bpf.h
$(INSTALL_DATA) $(srcdir)/pcap-namedb.h \
$(DESTDIR)$(includedir)/pcap-namedb.h
- [ -d $(DESTDIR)$(includedir)/net ] || \
- (mkdir -p $(DESTDIR)$(includedir)/net; chmod 755 $(DESTDIR)$(includedir)/net)
- $(INSTALL_DATA) $(srcdir)/bpf/net/bpf.h \
- $(DESTDIR)$(includedir)/net/bpf.h
[ -d $(DESTDIR)$(mandir)/man3 ] || \
(mkdir -p $(DESTDIR)$(mandir)/man3; chmod 755 $(DESTDIR)$(mandir)/man3)
$(INSTALL_DATA) $(srcdir)/pcap.3 \
@@ -158,8 +156,8 @@ install:
uninstall:
rm -f $(DESTDIR)$(libdir)/libpcap.a
rm -f $(DESTDIR)$(includedir)/pcap.h
+ rm -f $(DESTDIR)$(includedir)/pcap-bpf.h
rm -f $(DESTDIR)$(includedir)/pcap-namedb.h
- rm -f $(DESTDIR)$(includedir)/net/bpf.h
rm -f $(DESTDIR)$(mandir)/man3/pcap.3
clean:
@@ -167,7 +165,7 @@ clean:
distclean:
rm -f $(CLEANFILES) Makefile config.cache config.log config.status \
- config.h gnuc.h os-proto.h net bpf_filter.c stamp-h stamp-h.in
+ config.h gnuc.h os-proto.h bpf_filter.c stamp-h stamp-h.in
tags: $(TAGFILES)
ctags -wtd $(TAGFILES)
diff --git a/bpf/net/bpf_filter.c b/bpf/net/bpf_filter.c
index 5534f623..2de7e528 100644
--- a/bpf/net/bpf_filter.c
+++ b/bpf/net/bpf_filter.c
@@ -40,7 +40,7 @@
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.40 2003-01-10 09:15:18 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.41 2003-02-11 01:46:07 guy Exp $ (LBL)";
#endif
#ifdef WIN32
@@ -67,7 +67,7 @@ static const char rcsid[] =
#endif /* WIN32 */
-#include <net/bpf.h>
+#include <pcap-bpf.h>
#if !defined(KERNEL) && !defined(_KERNEL)
#include <stdlib.h>
diff --git a/packaging/pcap.spec b/packaging/pcap.spec
index e550adce..7ec8516e 100644
--- a/packaging/pcap.spec
+++ b/packaging/pcap.spec
@@ -1,5 +1,5 @@
%define prefix /usr
-%define version 2001.02.22
+%define version 2003.02.10
Summary: packet capture library
Name: libpcap
@@ -12,7 +12,7 @@ BuildRoot: /tmp/%{name}-buildroot
URL: http://www.tcpdump.org
%description
-Packet-capture library LIBPCAP 0.5
+Packet-capture library LIBPCAP 0.8
Now maintained by "The Tcpdump Group"
See http://www.tcpdump.org
Please send inquiries/comments/reports to tcpdump-workers@tcpdump.org
@@ -35,8 +35,8 @@ mkdir -p $RPM_BUILD_ROOT/usr/man/man3
install -m 755 -o root libpcap.a $RPM_BUILD_ROOT/usr/lib
install -m 644 -o root pcap.3 $RPM_BUILD_ROOT/usr/man/man3
install -m 644 -o root pcap.h $RPM_BUILD_ROOT/usr/include
+install -m 644 -o root pcap-bpf.h $RPM_BUILD_ROOT/usr/include/net
install -m 644 -o root pcap-namedb.h $RPM_BUILD_ROOT/usr/include
-install -m 644 -o root net/bpf.h $RPM_BUILD_ROOT/usr/include/net
%clean
rm -rf $RPM_BUILD_ROOT
@@ -46,5 +46,5 @@ rm -rf $RPM_BUILD_ROOT
%doc LICENSE CHANGES INSTALL README.linux TODO VERSION CREDITS pcap.spec
/usr/lib/libpcap.a
/usr/include/pcap.h
+/usr/include/pcap-bpf.h
/usr/include/pcap-namedb.h
-/usr/include/net/bpf.h
diff --git a/pcap-bpf.c b/pcap-bpf.c
index 0a46f04b..b3972815 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.55 2002-12-22 02:36:48 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.56 2003-02-11 01:46:05 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -35,9 +35,53 @@ static const char rcsid[] =
#include <sys/ioctl.h>
#include <net/if.h>
+
#ifdef _AIX
+
+/*
+ * Make "pcap.h" not include "pcap-bpf.h"; we are going to include the
+ * native OS version, as we need "struct bpf_config" from it.
+ */
+#define PCAP_DONT_INCLUDE_PCAP_BPF_H
+
+#include <sys/types.h>
+
+/*
+ * Prevent bpf.h from redefining the DLT_ values to their
+ * IFT_ values, as we're going to return the standard libpcap
+ * values, not IBM's non-standard IFT_ values.
+ */
+#undef _AIX
+#include <net/bpf.h>
+#define _AIX
+
#include <net/if_types.h> /* for IFT_ values */
-#endif
+#include <sys/sysconfig.h>
+#include <sys/device.h>
+#include <odmi.h>
+#include <cf.h>
+
+#ifdef __64BIT__
+#define domakedev makedev64
+#define getmajor major64
+#define bpf_hdr bpf_hdr32
+#else /* __64BIT__ */
+#define domakedev makedev
+#define getmajor major
+#endif /* __64BIT__ */
+
+#define BPF_NAME "bpf"
+#define BPF_MINORS 4
+#define DRIVER_PATH "/usr/lib/drivers"
+#define BPF_NODE "/dev/bpf"
+static int bpfloadedflag = 0;
+static int odmlockid = 0;
+
+#else /* _AIX */
+
+#include <net/bpf.h>
+
+#endif /* _AIX */
#include <ctype.h>
#include <errno.h>
@@ -188,6 +232,143 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
return (n);
}
+#ifdef _AIX
+static int
+bpf_odminit(char *errbuf)
+{
+ if (odm_initialize() == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: odm_initialize failed: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+
+ if ((odmlockid = odm_lock("/etc/objrepos/config_lock", ODM_WAIT)) == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: odm_lock of /etc/objrepos/config_lock failed: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+bpf_odmcleanup(char *errbuf)
+{
+ if (odm_unlock(odmlockid) == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: odm_unlock failed: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+
+ odm_terminate();
+
+ return (0);
+}
+
+static int
+bpf_load(char *errbuf)
+{
+ long major;
+ int *minors;
+ int numminors, i, rc;
+ char buf[1024];
+ struct stat sbuf;
+ struct bpf_config cfg_bpf;
+ struct cfg_load cfg_ld;
+ struct cfg_kmod cfg_km;
+
+ /*
+ * This is very very close to what happens in the real implementation
+ * but I've fixed some (unlikely) bug situations.
+ */
+ if (bpfloadedflag)
+ return (0);
+
+ if (bpf_odminit(errbuf) != 0)
+ return (-1);
+
+ major = genmajor(BPF_NAME);
+ if (major == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: genmajor failed: %s", pcap_strerror(errno));
+ return (-1);
+ }
+
+ minors = getminor(major, &numminors, BPF_NAME);
+ if (!minors) {
+ minors = genminor("bpf", major, 0, BPF_MINORS, 1, 1);
+ if (!minors) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: genminor failed: %s",
+ pcap_strerror(errno));
+ return (-1);
+ }
+
+ }
+
+ if (bpf_odmcleanup(errbuf))
+ return (-1);
+
+ rc = stat(BPF_NODE "0", &sbuf);
+ if (rc == -1 && errno != ENOENT) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: can't stat %s: %s",
+ BPF_NODE "0", pcap_strerror(errno));
+ return (-1);
+ }
+
+ if (rc == -1 || getmajor(sbuf.st_rdev) != major) {
+ for (i = 0; i < BPF_MINORS; i++) {
+ sprintf(buf, "%s%d", BPF_NODE, i);
+ unlink(buf);
+ if (mknod(buf, S_IRUSR | S_IFCHR, domakedev(major, i)) == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: can't mknod %s: %s",
+ buf pcap_strerror(errno));
+ return (-1);
+ }
+ }
+ }
+
+ /* Check if the driver is loaded */
+ memset(&cfg_ld, 0x0, sizeof(cfg_ld));
+ cfg_ld.path = buf;
+ sprintf(cfg_ld.path, "%s/%s", DRIVER_PATH, BPF_NAME);
+ if (sysconfig(SYS_QUERYLOAD, (void *) &cfg_ld, sizeof(cfg_ld) == -1) ||
+ (cfg_ld.kmid == 0)) {
+ /* Driver isn't loaded, load it now */
+ if (sysconfig(SYS_SINGLELOAD, (void *) &cfg_ld, sizeof(cfg_ld)) == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: could not load driver: %s",
+ strerror(errno));
+ return (-1);
+ }
+ }
+
+ /* Configure the driver */
+ cfg_km.cmd = CFG_INIT;
+ cfg_km.kmid = cfg_ld.kmid;
+ cfg_km.mdilen = sizeof(cfg_bpf);
+ cfg_km.mdiptr = (void *) &cfg_bpf;
+ for (i = 0; i < BPF_MINORS; i++) {
+ cfg_bpf.devno = domakedev(major, i);
+ if (sysconfig(SYS_CFGKMOD, (void *) &cfg_km, sizeof(cfg_km)) == -1) {
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bpf_load: could not configure driver: %s",
+ strerror(errno));
+ return (-1);
+ }
+ }
+
+ bpfloadedflag = 1;
+
+ return (0);
+}
+#endif
+
static inline int
bpf_open(pcap_t *p, char *errbuf)
{
@@ -195,6 +376,16 @@ bpf_open(pcap_t *p, char *errbuf)
int n = 0;
char device[sizeof "/dev/bpf0000000000"];
+#ifdef _AIX
+ /*
+ * Load the bpf driver, if it isn't already loaded,
+ * and create the BPF device entries, if they don't
+ * already exist.
+ */
+ if (bpf_load(errbuf) == -1)
+ return (-1);
+#endif
+
/*
* Go through all the minors and find one that isn't in use.
*/
diff --git a/bpf/net/bpf.h b/pcap-bpf.h
index 6d7adcb5..f37f9790 100644
--- a/bpf/net/bpf.h
+++ b/pcap-bpf.h
@@ -37,7 +37,18 @@
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
- * @(#) $Header: /tcpdump/master/libpcap/bpf/net/Attic/bpf.h,v 1.67 2003-01-23 07:24:53 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.1 2003-02-11 01:46:06 guy Exp $ (LBL)
+ */
+
+/*
+ * This is libpcap's cut-down version of bpf.h; it includes only
+ * the stuff needed for the code generator and the userland BPF
+ * interpreter, and the libpcap APIs for setting filters, etc..
+ *
+ * "pcap-bpf.c" will include the native OS version, as it deals with
+ * the OS's BPF implementation.
+ *
+ * XXX - should this all just be moved to "pcap.h"?
*/
#ifndef BPF_MAJOR_VERSION
@@ -68,7 +79,7 @@ typedef u_int bpf_u_int32;
#define BPF_MINBUFSIZE 32
/*
- * Structure for BIOCSETF.
+ * Structure for "pcap_compile()", "pcap_setfilter()", etc..
*/
struct bpf_program {
u_int bf_len;
@@ -76,14 +87,6 @@ struct bpf_program {
};
/*
- * 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 &&
@@ -103,66 +106,6 @@ struct bpf_version {
#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)
-#define BIOCSTCPF _IOW(B,114, struct bpf_program)
-#define BIOCSUDPF _IOW(B,115, struct bpf_program)
-#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)
-#define BIOCSTCPF _IOW('B',114, struct bpf_program)
-#define BIOCSUDPF _IOW('B',115, struct bpf_program)
-#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.
- */
-#if defined(KERNEL) || defined(_KERNEL)
-#define SIZEOF_BPF_HDR 18
-#endif
-
-/*
* Data-link level type codes.
*/
@@ -479,23 +422,6 @@ struct bpf_insn {
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
-#if defined(BSD) && (defined(KERNEL) || defined(_KERNEL))
-/*
- * Systems based on non-BSD kernels don't have ifnet's (or they don't mean
- * anything if it is in <net/if.h>) and won't work like this.
- */
-# if __STDC__
-extern void bpf_tap(struct ifnet *, u_char *, u_int);
-extern void bpf_mtap(struct ifnet *, struct mbuf *);
-extern void bpfattach(struct ifnet *, u_int, u_int);
-extern void bpfilterattach(int);
-# else
-extern void bpf_tap();
-extern void bpf_mtap();
-extern void bpfattach();
-extern void bpfilterattach();
-# endif /* __STDC__ */
-#endif /* BSD && (_KERNEL || KERNEL) */
#if __STDC__ || defined(__cplusplus)
extern int bpf_validate(struct bpf_insn *, int);
extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
diff --git a/pcap-enet.c b/pcap-enet.c
index 2e478c45..4458d6ca 100644
--- a/pcap-enet.c
+++ b/pcap-enet.c
@@ -8,7 +8,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-enet.c,v 1.6 2002-06-11 17:04:46 itojun Exp $";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-enet.c,v 1.7 2003-02-11 01:46:06 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
@@ -22,7 +22,7 @@ static const char rcsid[] =
#include <sys/socket.h>
#include <net/if.h>
-#include <net/bpf.h>
+#include <pcap-bpf.h>
#include <net/enet.h>
#include <netinet/in.h>
diff --git a/pcap.h b/pcap.h
index 7d4e0ad1..fbd3907f 100644
--- a/pcap.h
+++ b/pcap.h
@@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.41 2002-12-22 23:05:53 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.42 2003-02-11 01:46:06 guy Exp $ (LBL)
*/
#ifndef lib_pcap_h
@@ -44,7 +44,9 @@
#include <sys/time.h>
#endif /* WIN32 */
-#include <net/bpf.h>
+#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
+#include <pcap-bpf.h>
+#endif
#include <stdio.h>