]> The Tcpdump Group git mirrors - tcpdump/commitdiff
-use tok2str() for pkt type printing
authorhannes <hannes>
Thu, 28 Oct 2004 00:34:29 +0000 (00:34 +0000)
committerhannes <hannes>
Thu, 28 Oct 2004 00:34:29 +0000 (00:34 +0000)
-use the strings "In" "Out" when printing directions
-make more use of EXTRACT_ macros
-use the token table for printing the ethertypes

print-sll.c

index 8c3d4b3da491a2084238703e53b8503b34f8a065..0a65a8bc68bde4b22453ba05c19ecb5b1acc8651 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.15 2004-03-17 23:24:38 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.16 2004-10-28 00:34:29 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -36,54 +36,38 @@ static const char rcsid[] _U_ =
 #include "interface.h"
 #include "addrtoname.h"
 #include "ethertype.h"
+#include "extract.h"
 
 #include "ether.h"
 #include "sll.h"
 
+const struct tok sll_pkttype_values[] = {
+    { LINUX_SLL_HOST, "In" },
+    { LINUX_SLL_BROADCAST, "B" },
+    { LINUX_SLL_MULTICAST, "M" },
+    { LINUX_SLL_OTHERHOST, "P" },
+    { LINUX_SLL_OUTGOING, "Out" },
+    { 0, NULL}
+};
+
 static inline void
 sll_print(register const struct sll_header *sllp, u_int length)
 {
-       u_short halen;
-
-       switch (ntohs(sllp->sll_pkttype)) {
-
-       case LINUX_SLL_HOST:
-               (void)printf("< ");
-               break;
-
-       case LINUX_SLL_BROADCAST:
-               (void)printf("B ");
-               break;
-
-       case LINUX_SLL_MULTICAST:
-               (void)printf("M ");
-               break;
-
-       case LINUX_SLL_OTHERHOST:
-               (void)printf("P ");
-               break;
-
-       case LINUX_SLL_OUTGOING:
-               (void)printf("> ");
-               break;
-
-       default:
-               (void)printf("? ");
-               break;
-       }
+        printf("%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_16BITS(&sllp->sll_pkttype)));
 
        /*
         * XXX - check the link-layer address type value?
         * For now, we just assume 6 means Ethernet.
         * XXX - print others as strings of hex?
         */
-       halen = ntohs(sllp->sll_halen);
-       if (halen == 6)
+       if (EXTRACT_16BITS(&sllp->sll_halen) == 6)
                (void)printf("%s ", etheraddr_string(sllp->sll_addr));
 
        if (!qflag)
-               (void)printf("%s ", etherproto_string(sllp->sll_protocol));
-       (void)printf("%d: ", length);
+                (void)printf("ethertype %s (0x%04x), length %u: ",
+                         tok2str(ethertype_values,"Unknown", EXTRACT_16BITS(&sllp->sll_protocol)),
+                         EXTRACT_16BITS(&sllp->sll_protocol),
+                         length);
 }
 
 /*