From 0cf35b497d9abccfd00bc8bf1c669bffe974da17 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 18 Nov 2003 23:09:42 +0000 Subject: Print both the name and the description of a link-layer type (the name isn't always very suggestive - for example, somebody might think "EN10MB" is always 10 MB/s, and might not know that "IEEE802" is Token Ring), using "pcap_datalink_val_to_description()". Supply our own "pcap_datalink_val_to_description()" if libpcap doesn't have it (even if it has "pcap_datalink_name_to_val()"). --- missing/dlnames.c | 109 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 43 deletions(-) (limited to 'missing') diff --git a/missing/dlnames.c b/missing/dlnames.c index e2623b04..32072b78 100644 --- a/missing/dlnames.c +++ b/missing/dlnames.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/missing/dlnames.c,v 1.4 2003-11-16 09:36:47 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/missing/dlnames.c,v 1.5 2003-11-18 23:09:43 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -49,83 +49,93 @@ static const char rcsid[] _U_ = struct dlt_choice { const char *name; + const char *description; int dlt; }; -#define DLT_CHOICE(code) { #code, code } -#define DLT_CHOICE_SENTINEL { NULL, 0 } +#define DLT_CHOICE(code, description) { #code, description, code } +#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } static struct dlt_choice dlt_choices[] = { - DLT_CHOICE(DLT_ARCNET), - DLT_CHOICE(DLT_EN10MB), - DLT_CHOICE(DLT_SLIP), + DLT_CHOICE(DLT_NULL, "BSD loopback"), + DLT_CHOICE(DLT_EN10MB, "Ethernet"), + DLT_CHOICE(DLT_IEEE802, "Token ring"), + DLT_CHOICE(DLT_ARCNET, "ARCNET"), + DLT_CHOICE(DLT_SLIP, "SLIP"), + DLT_CHOICE(DLT_PPP, "PPP"), + DLT_CHOICE(DLT_FDDI, "FDDI"), + DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), + DLT_CHOICE(DLT_RAW, "Raw IP"), #ifdef DLT_SLIP_BSDOS - DLT_CHOICE(DLT_SLIP_BSDOS), + DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), #endif - DLT_CHOICE(DLT_NULL), -#ifdef DLT_LOOP - DLT_CHOICE(DLT_LOOP), +#ifdef DLT_PPP_BSDOS + DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), #endif - DLT_CHOICE(DLT_PPP), -#ifdef DLT_C_HDLC - DLT_CHOICE(DLT_C_HDLC), +#ifdef DLT_ATM_CLIP + DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), #endif #ifdef DLT_PPP_SERIAL - DLT_CHOICE(DLT_PPP_SERIAL), + DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), #endif #ifdef DLT_PPP_ETHER - DLT_CHOICE(DLT_PPP_ETHER), + DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), #endif -#ifdef DLT_PPP_BSDOS - DLT_CHOICE(DLT_PPP_BSDOS), +#ifdef DLT_C_HDLC + DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), #endif - DLT_CHOICE(DLT_FDDI), - DLT_CHOICE(DLT_IEEE802), #ifdef DLT_IEEE802_11 - DLT_CHOICE(DLT_IEEE802_11), -#endif -#ifdef DLT_PRISM_HEADER - DLT_CHOICE(DLT_PRISM_HEADER), + DLT_CHOICE(DLT_IEEE802_11, "802.11"), #endif -#ifdef DLT_IEEE802_11_RADIO - DLT_CHOICE(DLT_IEEE802_11_RADIO), +#ifdef DLT_FRELAY + DLT_CHOICE(DLT_FRELAY, "Frame Relay"), #endif - DLT_CHOICE(DLT_ATM_RFC1483), -#ifdef DLT_ATM_CLIP - DLT_CHOICE(DLT_ATM_CLIP), +#ifdef DLT_LOOP + DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), #endif -#ifdef DLT_SUNATM - DLT_CHOICE(DLT_SUNATM), +#ifdef DLT_ENC + DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), #endif - DLT_CHOICE(DLT_RAW), #ifdef DLT_LINUX_SLL - DLT_CHOICE(DLT_LINUX_SLL), + DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), #endif #ifdef DLT_LTALK - DLT_CHOICE(DLT_LTALK), + DLT_CHOICE(DLT_LTALK, "Localtalk"), +#endif +#ifdef DLT_PFLOG + DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), +#endif +#ifdef DLT_PRISM_HEADER + DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), #endif #ifdef DLT_IP_OVER_FC - DLT_CHOICE(DLT_IP_OVER_FC), + DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), #endif -#ifdef DLT_FRELAY - DLT_CHOICE(DLT_FRELAY), +#ifdef DLT_SUNATM + DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), +#endif +#ifdef DLT_IEEE802_11_RADIO + DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), +#endif +#ifdef DLT_ARCNET_LINUX + DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), +#endif +#ifdef DLT_LINUX_IRDA + DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), #endif - #ifdef DLT_LANE8023 - DLT_CHOICE(DLT_LANE8023), + DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"), #endif #ifdef DLT_CIP - DLT_CHOICE(DLT_CIP), + DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), #endif #ifdef DLT_HDLC - DLT_CHOICE(DLT_HDLC), -#endif -#ifdef DLT_PFLOG - DLT_CHOICE(DLT_PFLOG), + DLT_CHOICE(DLT_HDLC, "Cisco HDLC"), #endif DLT_CHOICE_SENTINEL }; +#ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL int pcap_datalink_name_to_val(const char *name) { @@ -150,3 +160,16 @@ pcap_datalink_val_to_name(int dlt) } return (NULL); } +#endif + +const char * +pcap_datalink_val_to_description(int dlt) +{ + int i; + + for (i = 0; dlt_choices[i].name != NULL; i++) { + if (dlt_choices[i].dlt == dlt) + return (dlt_choices[i].description); + } + return (NULL); +} -- cgit v1.2.1