]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ARCNet support, from NetBSD.
authorguy <guy>
Tue, 17 Apr 2001 08:39:17 +0000 (08:39 +0000)
committerguy <guy>
Tue, 17 Apr 2001 08:39:17 +0000 (08:39 +0000)
FILES
Makefile.in
arcnet.h [new file with mode: 0644]
interface.h
print-arcnet.c [new file with mode: 0644]
tcpdump.c

diff --git a/FILES b/FILES
index 262d5602e740917231204a5bec47014c3676718b..e0f2663531748a0e3cb3bbbea723872855303ab2 100644 (file)
--- a/FILES
+++ b/FILES
@@ -12,6 +12,7 @@ addrtoname.c
 addrtoname.h
 ah.h
 appletalk.h
+arcnet.h
 atime.awk
 bootp.h
 chdlc.h
@@ -75,6 +76,7 @@ packetdat.awk
 parsenfsfh.c
 ppp.h
 print-ah.c
+print-arcnet.c
 print-arp.c
 print-ascii.c
 print-atalk.c
index b5df24571003f41728d43f65de3341da7be4651e..429ed4964e62e9df628eab42802238c06e153ece 100644 (file)
@@ -17,7 +17,7 @@
 #  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
-# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.247 2001-03-09 05:38:20 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.248 2001-04-17 08:39:18 guy Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -80,7 +80,8 @@ CSRC =        tcpdump.c \
        print-lane.c print-cip.c print-pppoe.c print-lcp.c \
        print-smb.c smbutil.c print-ascii.c print-telnet.c print-cnfp.c \
        print-vrrp.c print-cdp.c print-token.c print-bxxp.c print-timed.c \
-       print-radius.c print-sll.c print-lwres.c print-pptp.c
+       print-radius.c print-sll.c print-lwres.c print-pptp.c \
+       print-arcnet.c
 
 LOCALSRC = @LOCALSRC@
 GENSRC = version.c
diff --git a/arcnet.h b/arcnet.h
new file mode 100644 (file)
index 0000000..8977400
--- /dev/null
+++ b/arcnet.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 1982, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#) $Id: arcnet.h,v 1.1 2001-04-17 08:39:18 guy Exp $ (LBL)
+ *
+ * from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp
+ */
+
+/*
+ * Structure of a 2.5MB/s Arcnet header.
+ * as given to interface code.
+ */
+struct arc_header {
+       u_int8_t  arc_shost;
+       u_int8_t  arc_dhost;
+       u_int8_t  arc_type;
+       /*
+        * only present for newstyle encoding with LL fragmentation.
+        * Don't use sizeof(anything), use ARC_HDR{,NEW}LEN instead.
+        */
+       u_int8_t  arc_flag;
+       u_int16_t arc_seqid;
+
+       /*
+        * only present in exception packets (arc_flag == 0xff)
+        */
+       u_int8_t  arc_type2;    /* same as arc_type */
+       u_int8_t  arc_flag2;    /* real flag value */
+       u_int16_t arc_seqid2;   /* real seqid value */
+} __attribute__((__packed__));
+
+#define        ARC_HDRLEN              3
+#define        ARC_HDRNEWLEN           6
+#define        ARC_HDRNEWLEN_EXC       10
+
+/* RFC 1051 */
+#define        ARCTYPE_IP_OLD          240     /* IP protocol */
+#define        ARCTYPE_ARP_OLD         241     /* address resolution protocol */
+
+/* RFC 1201 */
+#define        ARCTYPE_IP              212     /* IP protocol */
+#define        ARCTYPE_ARP             213     /* address resolution protocol */
+#define        ARCTYPE_REVARP          214     /* reverse addr resolution protocol */
+
+#define        ARCTYPE_ATALK           221     /* Appletalk */
+#define        ARCTYPE_BANIAN          247     /* Banyan Vines */
+#define        ARCTYPE_IPX             250     /* Novell IPX */
+
+#define ARCTYPE_INET6          0xc4    /* IPng */
+#define ARCTYPE_DIAGNOSE       0x80    /* as per ANSI/ATA 878.1 */
index 4c34f075465ef47d2ae1f2cebeaf2dbb131d3d5e..156297b6ceeab20c1a11c4383f7a7aa04576a2e4 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.156 2001-04-12 09:05:07 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.157 2001-04-17 08:39:19 guy Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -198,6 +198,8 @@ extern void default_print(const u_char *, u_int);
 extern void default_print_unaligned(const u_char *, u_int);
 extern void dvmrp_print(const u_char *, u_int);
 extern void egp_print(const u_char *, u_int, const u_char *);
+extern void arcnet_if_print(u_char *, const struct pcap_pkthdr *,
+       const u_char *);
 extern void ether_if_print(u_char *, const struct pcap_pkthdr *,
        const u_char *);
 extern void token_if_print(u_char *, const struct pcap_pkthdr *,
diff --git a/print-arcnet.c b/print-arcnet.c
new file mode 100644 (file)
index 0000000..1e6b230
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 1988, 1989, 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
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * 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.
+ * 
+ * From: NetBSD: print-arcnet.c,v 1.2 2000/04/24 13:02:28 itojun Exp
+ */
+#ifndef lint
+static const char rcsid[] =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.1 2001-04-17 08:39:19 guy Exp $ (LBL)";
+#endif
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+
+struct mbuf;
+struct rtentry;
+
+#include <netinet/in.h>
+
+#include <stdio.h>
+#include <pcap.h>
+
+#include "interface.h"
+#include "arcnet.h"
+
+const u_char *packetp;
+const u_char *snapend;
+
+int arcnet_encap_print(u_char arctype, const u_char *p,
+    u_int length, u_int caplen);
+
+struct arctype_map {
+       const int arctype;
+       char * const name;
+} arctypemap[] = {
+       { ARCTYPE_IP_OLD,       "oldip" },
+       { ARCTYPE_ARP_OLD,      "oldarp" },
+       { ARCTYPE_IP,           "ip" },
+       { ARCTYPE_ARP,          "arp" },
+       { ARCTYPE_REVARP,       "rarp" },
+       { ARCTYPE_ATALK,        "atalk" },
+       { ARCTYPE_BANIAN,       "banyan" },
+       { ARCTYPE_IPX,          "ipx" },
+       { ARCTYPE_INET6,        "ipv6" },
+       { ARCTYPE_DIAGNOSE,     "diag" },
+       { 0, 0 }
+};
+
+static inline void
+arcnet_print(const u_char *bp, u_int length, int phds, int flag, u_int seqid)
+{
+       const struct arc_header *ap;
+       struct arctype_map *atmp;
+       char *arctypename;
+       char typebuf[3];
+
+
+       ap = (const struct arc_header *)bp;
+
+
+       if (qflag) {
+               (void)printf("%02x %02x %d: ",
+                            ap->arc_shost,
+                            ap->arc_dhost,
+                            length);
+               return;
+       }
+
+       for (arctypename = NULL, atmp = arctypemap; atmp->arctype; atmp++) {
+               if (atmp->arctype == ap->arc_type) {
+                       arctypename = atmp->name;
+                       break;
+               }
+       }
+       if (!arctypename) {
+               arctypename = typebuf;
+               (void)snprintf(typebuf, sizeof(typebuf), "%02x", ap->arc_type);
+       }
+
+       if (!phds) {
+               (void)printf("%02x %02x %s %d: ",
+                            ap->arc_shost, ap->arc_dhost, arctypename,
+                            length);
+                            return;
+       }
+
+       if (flag == 0) {
+               (void)printf("%02x %02x %s seqid %04x %d: ",
+                       ap->arc_shost, ap->arc_dhost, arctypename, seqid,
+                       length);
+                       return;
+       }
+
+       if (flag & 1)
+               (void)printf("%02x %02x %s seqid %04x "
+                       "(first of %d fragments) %d: ",
+                       ap->arc_shost, ap->arc_dhost, arctypename, seqid,
+                       (flag + 3) / 2, length);
+       else
+               (void)printf("%02x %02x %s seqid %04x "
+                       "(fragment %d) %d: ",
+                       ap->arc_shost, ap->arc_dhost, arctypename, seqid,
+                       flag/2 + 1, length);
+}
+
+/*
+ * This is the top level routine of the printer.  'p' is the points
+ * to the ether header of the packet, 'tvp' is the timestamp,
+ * 'length' is the length of the packet off the wire, and 'caplen'
+ * is the number of bytes actually captured.
+ */
+void
+arcnet_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
+{
+       u_int caplen = h->caplen;
+       u_int length = h->len;
+       struct arc_header *ap;
+
+       int phds, flag = 0, archdrlen;
+       u_int seqid = 0;
+       u_char arc_type;
+
+       ts_print(&h->ts);
+
+       if (caplen < ARC_HDRLEN) {
+               printf("[|arcnet]");
+               goto out;
+       }
+
+       ap = (struct arc_header *)p;
+       arc_type = ap->arc_type;
+
+       switch (arc_type) {
+       default:
+               phds = 1;
+               break;
+       case ARCTYPE_IP_OLD:
+       case ARCTYPE_ARP_OLD:
+       case ARCTYPE_DIAGNOSE:
+               phds = 0;
+               archdrlen = ARC_HDRLEN;
+               break;
+       }
+
+       if (phds) {
+               if (caplen < ARC_HDRNEWLEN) {
+                       arcnet_print(p, length, 0, 0, 0);
+                       printf("[|phds]");
+                       goto out;
+               }
+
+               if (ap->arc_flag == 0xff) {
+                       if (caplen < ARC_HDRNEWLEN_EXC) {
+                               arcnet_print(p, length, 0, 0, 0);
+                               printf("[|phds extended]");
+                               goto out;
+                       }
+                       flag = ap->arc_flag2;
+                       seqid = ap->arc_seqid2;
+                       archdrlen = ARC_HDRNEWLEN_EXC;
+               } else {
+                       flag = ap->arc_flag;
+                       seqid = ap->arc_seqid;
+                       archdrlen = ARC_HDRNEWLEN;
+               }
+       }
+
+
+       if (eflag)
+               arcnet_print(p, length, phds, flag, seqid);
+
+       /*
+        * Some printers want to get back at the ethernet addresses,
+        * and/or check that they're not walking off the end of the packet.
+        * Rather than pass them all the way down, we set these globals.
+        */
+       packetp = p;
+       snapend = p + caplen;
+
+       length -= archdrlen;
+       caplen -= archdrlen;
+       p += archdrlen;
+
+       if (phds && flag && (flag & 1) == 0)
+               goto out2;
+
+       if (!arcnet_encap_print(arc_type, p, length, caplen)) {
+               default_print(p, caplen);
+               goto out;
+       }
+
+ out2:
+       if (xflag)
+               default_print(p, caplen);
+
+ out:
+       putchar('\n');
+}
+
+/*
+ * Prints the packet encapsulated in an ARCnet data field,
+ * given the ARCnet system code.
+ *
+ * Returns non-zero if it can do so, zero if the system code is unknown.
+ */
+
+
+int
+arcnet_encap_print(u_char arctype, const u_char *p,
+    u_int length, u_int caplen)
+{
+       switch (arctype) {
+
+       case ARCTYPE_IP_OLD:
+       case ARCTYPE_IP:
+               ip_print(p, length);
+               return (1);
+
+#ifdef INET6
+       case ARCTYPE_INET6:
+               ip6_print(p, length);
+               return (1);
+#endif /*INET6*/
+
+       case ARCTYPE_ARP_OLD:
+       case ARCTYPE_ARP:
+       case ARCTYPE_REVARP:
+               arp_print(p, length, caplen);
+               return (1);
+
+       case ARCTYPE_ATALK:     /* XXX was this ever used? */
+               if (vflag)
+                       fputs("et1 ", stdout);
+               atalk_print(p, length);
+               return (1);
+
+       default:
+               return (0);
+       }
+}
index f44b2f20e7ddb551e40863facf523510828fc500..d5afc671b591c48cbc9ea66594855db418133fdf 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -24,7 +24,7 @@ static const char copyright[] =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.159 2001-03-11 02:45:28 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.160 2001-04-17 08:39:20 guy Exp $ (LBL)";
 #endif
 
 /*
@@ -99,6 +99,7 @@ struct printer {
 };
 
 static struct printer printers[] = {
+       { arcnet_if_print,      DLT_ARCNET },
        { ether_if_print,       DLT_EN10MB },
        { token_if_print,       DLT_IEEE802 },
 #ifdef DLT_LANE8023