From: guy Date: Thu, 23 Jan 2003 07:24:51 +0000 (+0000) Subject: From Peter Fales : support for Linux ARCNET, X-Git-Tag: libpcap-0.8-bp~93 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/2d1ac3b4d5cb6986a42f0e249aec74989530a559 From Peter Fales : support for Linux ARCNET, which supplies different headers from BSD ARCNET, and fixes to the ARCNET code generator (the protocol ID field is 1 byte, so the values for it shouldn't be byte-swapped). Whitespace cleanups. The "NetBSD-style" ARCNET headers are used in other BSDs as well, so just call them "BSD-style". --- diff --git a/CREDITS b/CREDITS index 2adfeafb..a701f411 100644 --- a/CREDITS +++ b/CREDITS @@ -52,6 +52,7 @@ Additional people who have contributed patches: Olaf Kirch Onno van der Linden Pavel Kankovsky + Peter Fales Peter Jeremy Phil Wood Rafal Maszkowski diff --git a/bpf/net/bpf.h b/bpf/net/bpf.h index 62a53007..6d7adcb5 100644 --- a/bpf/net/bpf.h +++ b/bpf/net/bpf.h @@ -37,7 +37,7 @@ * * @(#)bpf.h 7.1 (Berkeley) 5/7/91 * - * @(#) $Header: /tcpdump/master/libpcap/bpf/net/Attic/bpf.h,v 1.66 2003-01-21 04:39:05 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/libpcap/bpf/net/Attic/bpf.h,v 1.67 2003-01-23 07:24:53 guy Exp $ (LBL) */ #ifndef BPF_MAJOR_VERSION @@ -183,7 +183,7 @@ struct bpf_hdr { #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, with NetBSD-style header */ +#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */ #define DLT_SLIP 8 /* Serial Line IP */ #define DLT_PPP 9 /* Point-to-point Protocol */ #define DLT_FDDI 10 /* FDDI */ @@ -395,7 +395,7 @@ struct bpf_hdr { #define DLT_TZSP 128 /* Tazmen Sniffer Protocol */ /* - * NetBSD's ARCNET headers have the source host, destination host, + * BSD's ARCNET headers have the source host, destination host, * and type at the beginning of the packet; that's what's handed * up to userland via BPF. * diff --git a/gencode.c b/gencode.c index 915e5b48..e8840ef5 100644 --- a/gencode.c +++ b/gencode.c @@ -21,7 +21,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.183 2002-12-12 07:04:17 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.184 2003-01-23 07:24:51 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -695,10 +695,16 @@ init_linktype(type) case DLT_ARCNET: off_linktype = 2; - off_nl = 6; /* XXX in reality, variable! */ + off_nl = 6; /* XXX in reality, variable! */ off_nl_nosnap = 6; /* no 802.2 LLC */ return; + case DLT_ARCNET_LINUX: + off_linktype = 4; + off_nl = 8; /* XXX in reality, variable! */ + off_nl_nosnap = 8; /* no 802.2 LLC */ + return; + case DLT_EN10MB: off_linktype = 12; off_nl = 14; /* Ethernet II */ @@ -1166,15 +1172,19 @@ gen_linktype(proto) return gen_ether_linktype(proto); break; - case DLT_C_HDLC: - switch (proto) { - case LLCSAP_ISONS: - proto = (proto << 8 | LLCSAP_ISONS); - /* fall through */ - default: - return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); - break; - } + case DLT_C_HDLC: + switch (proto) { + + case LLCSAP_ISONS: + proto = (proto << 8 | LLCSAP_ISONS); + /* fall through */ + + default: + return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); + break; + } + break; + case DLT_IEEE802_11: case DLT_PRISM_HEADER: case DLT_IEEE802_11_RADIO: @@ -1567,36 +1577,45 @@ gen_linktype(proto) return (gen_cmp(0, BPF_W, (bpf_int32)proto)); case DLT_ARCNET: + case DLT_ARCNET_LINUX: /* * XXX should we check for first fragment if the protocol * uses PHDS? */ - switch(proto) { + switch (proto) { + default: return gen_false(); + #ifdef INET6 case ETHERTYPE_IPV6: - return(gen_cmp(2, BPF_B, - (bpf_int32)htonl(ARCTYPE_INET6))); + return (gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_INET6)); #endif /* INET6 */ + case ETHERTYPE_IP: - b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_IP)); - b1 = gen_cmp(2, BPF_B, - (bpf_int32)htonl(ARCTYPE_IP_OLD)); + b0 = gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_IP); + b1 = gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_IP_OLD); gen_or(b0, b1); - return(b1); + return (b1); + case ETHERTYPE_ARP: - b0 = gen_cmp(2, BPF_B, (bpf_int32)htonl(ARCTYPE_ARP)); - b1 = gen_cmp(2, BPF_B, - (bpf_int32)htonl(ARCTYPE_ARP_OLD)); + b0 = gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_ARP); + b1 = gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_ARP_OLD); gen_or(b0, b1); - return(b1); + return (b1); + case ETHERTYPE_REVARP: - return(gen_cmp(2, BPF_B, - (bpf_int32)htonl(ARCTYPE_REVARP))); + return (gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_REVARP)); + case ETHERTYPE_ATALK: - return(gen_cmp(2, BPF_B, - (bpf_int32)htonl(ARCTYPE_ATALK))); + return (gen_cmp(off_linktype, BPF_B, + (bpf_int32)ARCTYPE_ATALK)); } break; @@ -4598,7 +4617,7 @@ gen_broadcast(proto) case Q_DEFAULT: case Q_LINK: - if (linktype == DLT_ARCNET) + if (linktype == DLT_ARCNET || linktype == DLT_ARCNET_LINUX) return gen_ahostop(abroadcast, Q_DST); if (linktype == DLT_EN10MB) return gen_ehostop(ebroadcast, Q_DST); @@ -4671,7 +4690,7 @@ gen_multicast(proto) case Q_DEFAULT: case Q_LINK: - if (linktype == DLT_ARCNET) + if (linktype == DLT_ARCNET || linktype == DLT_ARCNET_LINUX) /* all ARCnet multicasts use the same address */ return gen_ahostop(abroadcast, Q_DST); @@ -4910,7 +4929,7 @@ gen_acode(eaddr, q) struct qual q; { if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { - if (linktype == DLT_ARCNET) + if (linktype == DLT_ARCNET || linktype == DLT_ARCNET_LINUX) return gen_ahostop(eaddr, (int)q.dir); } bpf_error("ARCnet address used in non-arc expression"); diff --git a/pcap-linux.c b/pcap-linux.c index ee95513b..deb9ae65 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -26,7 +26,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.87 2002-12-22 02:36:49 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.88 2003-01-23 07:24:52 guy Exp $ (LBL)"; #endif /* @@ -949,7 +949,7 @@ static void map_arphrd_to_dlt(pcap_t *handle, int arptype, int cooked_ok) break; case ARPHRD_ARCNET: - handle->linktype = DLT_ARCNET; + handle->linktype = DLT_ARCNET_LINUX; break; #ifndef ARPHRD_FDDI /* From Linux 2.2.13 */ diff --git a/pcap.c b/pcap.c index 281639cd..cfcccf0c 100644 --- a/pcap.c +++ b/pcap.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.44 2003-01-16 07:44:27 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.45 2003-01-23 07:24:52 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -214,6 +214,7 @@ struct dlt_choice { static struct dlt_choice dlt_choices[] = { DLT_CHOICE(DLT_ARCNET), + DLT_CHOICE(DLT_ARCNET_LINUX), DLT_CHOICE(DLT_EN10MB), DLT_CHOICE(DLT_SLIP), DLT_CHOICE(DLT_SLIP_BSDOS), diff --git a/savefile.c b/savefile.c index 5d7bff70..c703d1e3 100644 --- a/savefile.c +++ b/savefile.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.74 2003-01-21 04:39:05 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.75 2003-01-23 07:24:53 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -123,7 +123,7 @@ static const char rcsid[] = #define LINKTYPE_PRONET DLT_PRONET #define LINKTYPE_CHAOS DLT_CHAOS #define LINKTYPE_TOKEN_RING DLT_IEEE802 /* DLT_IEEE802 is used for Token Ring */ -#define LINKTYPE_ARCNET DLT_ARCNET /* NetBSD-style headers */ +#define LINKTYPE_ARCNET DLT_ARCNET /* BSD-style headers */ #define LINKTYPE_SLIP DLT_SLIP #define LINKTYPE_PPP DLT_PPP #define LINKTYPE_FDDI DLT_FDDI