From: hannes Date: Thu, 28 Oct 2004 00:34:29 +0000 (+0000) Subject: -use tok2str() for pkt type printing X-Git-Tag: tcpdump-3.9.1~253 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/728363f6db3565d20aa0c5571f7413783f48cab1 -use tok2str() for pkt type printing -use the strings "In" "Out" when printing directions -make more use of EXTRACT_ macros -use the token table for printing the ethertypes --- diff --git a/print-sll.c b/print-sll.c index 8c3d4b3d..0a65a8bc 100644 --- a/print-sll.c +++ b/print-sll.c @@ -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); } /*