summaryrefslogtreecommitdiff
path: root/lib/libpcap/gencode.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1997-10-03 15:53:00 +0000
committerchristos <christos@NetBSD.org>1997-10-03 15:53:00 +0000
commita520af71e9f35f4e3311e676e25ae737d6126673 (patch)
tree584154311dd6336ddf2b60a795bb8461ea068e4a /lib/libpcap/gencode.c
parent985e82ae380e8cef11e79c26a087251f6ec03656 (diff)
Resolve conflicts
Diffstat (limited to 'lib/libpcap/gencode.c')
-rw-r--r--lib/libpcap/gencode.c87
1 files changed, 72 insertions, 15 deletions
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c
index f7d45163b22..36a47e6b145 100644
--- a/lib/libpcap/gencode.c
+++ b/lib/libpcap/gencode.c
@@ -1,7 +1,7 @@
-/* $NetBSD: gencode.c,v 1.7 1997/03/15 18:34:01 is Exp $ */
+/* $NetBSD: gencode.c,v 1.8 1997/10/03 15:53:05 christos Exp $ */
/*
- * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
+ * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -20,9 +20,14 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char rcsid[] =
- "@(#) Header: gencode.c,v 1.88 96/07/23 01:30:41 leres Exp (LBL)";
+#if 0
+static const char rcsid[] =
+ "@(#) Header: gencode.c,v 1.93 97/06/12 14:22:47 leres Exp (LBL)";
+#else
+__RCSID("$NetBSD: gencode.c,v 1.8 1997/10/03 15:53:05 christos Exp $");
+#endif
#endif
#include <sys/param.h>
@@ -56,6 +61,7 @@ struct rtentry;
#include "ethertype.h"
#include "gencode.h"
+#include "ppp.h"
#include <pcap-namedb.h>
#include "gnuc.h"
@@ -421,7 +427,8 @@ gen_bcmp(offset, size, v)
b = NULL;
while (size >= 4) {
register const u_char *p = &v[size - 4];
- bpf_int32 w = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+ 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)
@@ -431,7 +438,7 @@ gen_bcmp(offset, size, v)
}
while (size >= 2) {
register const u_char *p = &v[size - 2];
- bpf_int32 w = (p[0] << 8) | p[1];
+ bpf_int32 w = ((bpf_int32)p[0] << 8) | p[1];
tmp = gen_cmp(offset + size - 2, BPF_H, w);
if (b != NULL)
@@ -479,6 +486,13 @@ init_linktype(type)
off_nl = 16;
return;
+ case DLT_SLIP_BSDOS:
+ /* XXX this may be the same as the DLT_PPP_BSDOS case */
+ off_linktype = -1;
+ /* XXX end */
+ off_nl = 24;
+ return;
+
case DLT_NULL:
off_linktype = 0;
off_nl = 4;
@@ -489,6 +503,11 @@ init_linktype(type)
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.
@@ -518,6 +537,11 @@ init_linktype(type)
off_linktype = 6;
off_nl = 8;
return;
+
+ case DLT_RAW:
+ off_linktype = -1;
+ off_nl = 0;
+ return;
}
bpf_error("unknown data link type 0x%x", linktype);
/* NOTREACHED */
@@ -552,24 +576,53 @@ 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_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_NULL:
/* XXX */
if (proto == ETHERTYPE_IP)
- return (gen_cmp(0, BPF_W, (bpf_int32)AF_INET));
+ return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET)));
else
return gen_false();
}
@@ -1201,6 +1254,7 @@ gen_scode(name, q)
{
int proto = q.proto;
int dir = q.dir;
+ int tproto;
u_char *eaddr;
bpf_u_int32 mask, addr, **alist;
struct block *b, *tmp;
@@ -1255,10 +1309,13 @@ gen_scode(name, q)
alist = pcap_nametoaddr(name);
if (alist == NULL || *alist == NULL)
bpf_error("unknown host '%s'", name);
- b = gen_host(**alist++, 0xffffffff, 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++, 0xffffffff,
- proto, dir);
+ tproto, dir);
gen_or(b, tmp);
b = tmp;
}