summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/bpf/net/bpf_filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libpcap/bpf/net/bpf_filter.c')
-rw-r--r--contrib/libpcap/bpf/net/bpf_filter.c65
1 files changed, 43 insertions, 22 deletions
diff --git a/contrib/libpcap/bpf/net/bpf_filter.c b/contrib/libpcap/bpf/net/bpf_filter.c
index d47503f..a2cfbc1 100644
--- a/contrib/libpcap/bpf/net/bpf_filter.c
+++ b/contrib/libpcap/bpf/net/bpf_filter.c
@@ -4,7 +4,7 @@
*
* 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
+ * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,10 +39,20 @@
*/
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.35 2000/10/23 19:32:21 fenner Exp $ (LBL)";
+static const char rcsid[] _U_ =
+ "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.43.2.1 2003/11/15 23:26:49 guy Exp $ (LBL)";
#endif
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef WIN32
+
+#include <pcap-stdinc.h>
+
+#else /* WIN32 */
+
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -59,7 +69,9 @@ static const char rcsid[] =
# define MLEN(m) ((m)->m_len)
#endif
-#include <net/bpf.h>
+#endif /* WIN32 */
+
+#include <pcap-bpf.h>
#if !defined(KERNEL) && !defined(_KERNEL)
#include <stdlib.h>
@@ -69,14 +81,23 @@ static const char rcsid[] =
#define u_int32 bpf_u_int32
#ifndef LBL_ALIGN
-#if defined(sparc) || defined(mips) || defined(ibm032) || \
- defined(__alpha) || defined(__hpux)
+/*
+ * XXX - IA-64? If not, this probably won't work on Win64 IA-64
+ * systems, unless LBL_ALIGN is defined elsewhere for them.
+ * XXX - SuperH? If not, this probably won't work on WinCE SuperH
+ * systems, unless LBL_ALIGN is defined elsewhere for them.
+ */
+#if defined(sparc) || defined(__sparc__) || defined(mips) || \
+ defined(ibm032) || defined(__alpha) || defined(__hpux) || \
+ defined(__arm__)
#define LBL_ALIGN
#endif
#endif
#ifndef LBL_ALIGN
+#ifndef WIN32
#include <netinet/in.h>
+#endif
#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p))
#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p))
@@ -216,7 +237,7 @@ bpf_filter(pc, p, wirelen, buflen)
return 0;
#else
abort();
-#endif
+#endif
case BPF_RET|BPF_K:
return (u_int)pc->k;
@@ -361,7 +382,7 @@ bpf_filter(pc, p, wirelen, buflen)
case BPF_LD|BPF_MEM:
A = mem[pc->k];
continue;
-
+
case BPF_LDX|BPF_MEM:
X = mem[pc->k];
continue;
@@ -413,25 +434,25 @@ bpf_filter(pc, p, wirelen, buflen)
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;
@@ -447,23 +468,23 @@ bpf_filter(pc, p, wirelen, buflen)
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;
@@ -495,9 +516,9 @@ bpf_filter(pc, p, wirelen, buflen)
/*
* 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.
+ * 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).
+ * '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.
@@ -512,7 +533,7 @@ bpf_validate(f, len)
for (i = 0; i < len; ++i) {
/*
- * Check that that jumps are forward, and within
+ * Check that that jumps are forward, and within
* the code block.
*/
p = &f[i];
@@ -530,7 +551,7 @@ bpf_validate(f, len)
* Check that memory operations use valid addresses.
*/
if ((BPF_CLASS(p->code) == BPF_ST ||
- (BPF_CLASS(p->code) == BPF_LD &&
+ (BPF_CLASS(p->code) == BPF_LD &&
(p->code & 0xe0) == BPF_MEM)) &&
(p->k >= BPF_MEMWORDS || p->k < 0))
return 0;
OpenPOWER on IntegriCloud