From ba73faeef369e578148764741575c5c7e5b3c37a Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 18 Nov 2003 22:14:24 +0000 Subject: [PATCH] Add "pcap_datalink_val_to_description()", which returns, for a DLT_ type, a short description intended for humans. Fix up some man page typoes. --- pcap.3 | 15 +++++++----- pcap.c | 75 ++++++++++++++++++++++++++++++++++------------------------ pcap.h | 3 ++- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/pcap.3 b/pcap.3 index 1e40973..290a994 100644 --- a/pcap.3 +++ b/pcap.3 @@ -1,4 +1,4 @@ -.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.53 2003-11-18 21:51:11 guy Exp $ +.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.54 2003-11-18 22:14:24 guy Exp $ .\" .\" Copyright (c) 1994, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -93,6 +93,7 @@ int pcap_list_datalinks(pcap_t *p, int **dlt_buf); int pcap_set_datalink(pcap_t *p, int dlt); int pcap_datalink_name_to_val(const char *name); const char *pcap_datalink_val_to_name(int dlt); +const char *pcap_datalink_val_to_description(int dlt); int pcap_snapshot(pcap_t *p) int pcap_is_swapped(pcap_t *p) int pcap_major_version(pcap_t *p) @@ -982,14 +983,16 @@ name with the .B DLT_ removed, to the corresponding data link type value. The translation is case-insensitive. -is used to set the current data link type of the pcap descriptor -NULL is returned on failure. +.B \-1 +is returned on failure. .PP .B pcap_datalink_val_to_name() translates a data link type value to the corresponding data link type -name. -.B \-1 -is returned on failure. +name. NULL is returned on failure. +.PP +.B pcap_datalink_val_to_description() +translates a data link type value to a short description of that data +link type. NULL is returned on failure. .PP .B pcap_snapshot() returns the snapshot length specified when diff --git a/pcap.c b/pcap.c index e01cf82..2c81a76 100644 --- a/pcap.c +++ b/pcap.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.65 2003-11-18 21:06:51 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.66 2003-11-18 22:14:24 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -291,41 +291,42 @@ unsupported: 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_NULL), - DLT_CHOICE(DLT_EN10MB), - DLT_CHOICE(DLT_IEEE802), - DLT_CHOICE(DLT_ARCNET), - DLT_CHOICE(DLT_SLIP), - DLT_CHOICE(DLT_PPP), - DLT_CHOICE(DLT_FDDI), - DLT_CHOICE(DLT_ATM_RFC1483), - DLT_CHOICE(DLT_RAW), - DLT_CHOICE(DLT_SLIP_BSDOS), - DLT_CHOICE(DLT_PPP_BSDOS), - DLT_CHOICE(DLT_ATM_CLIP), - DLT_CHOICE(DLT_PPP_SERIAL), - DLT_CHOICE(DLT_PPP_ETHER), - DLT_CHOICE(DLT_C_HDLC), - DLT_CHOICE(DLT_IEEE802_11), - DLT_CHOICE(DLT_FRELAY), - DLT_CHOICE(DLT_LOOP), - DLT_CHOICE(DLT_ENC), - DLT_CHOICE(DLT_LINUX_SLL), - DLT_CHOICE(DLT_LTALK), - DLT_CHOICE(DLT_PFLOG), - DLT_CHOICE(DLT_PRISM_HEADER), - DLT_CHOICE(DLT_IP_OVER_FC), - DLT_CHOICE(DLT_SUNATM), - DLT_CHOICE(DLT_IEEE802_11_RADIO), - DLT_CHOICE(DLT_ARCNET_LINUX), - DLT_CHOICE(DLT_LINUX_IRDA), + 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"), + DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), + DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), + DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), + DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), + DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), + DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), + DLT_CHOICE(DLT_IEEE802_11, "802.11"), + DLT_CHOICE(DLT_FRELAY, "Frame Relay"), + DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), + DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), + DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), + DLT_CHOICE(DLT_LTALK, "Localtalk"), + DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), + DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), + DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), + DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), + DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), + DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), + DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), DLT_CHOICE_SENTINEL }; @@ -439,6 +440,18 @@ pcap_datalink_val_to_name(int dlt) return (NULL); } +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); +} + int pcap_snapshot(pcap_t *p) { diff --git a/pcap.h b/pcap.h index 2ce11a1..da05938 100644 --- a/pcap.h +++ b/pcap.h @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.46 2003-11-16 10:07:36 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.47 2003-11-18 22:14:25 guy Exp $ (LBL) */ #ifndef lib_pcap_h @@ -196,6 +196,7 @@ int pcap_list_datalinks(pcap_t *, int **); int pcap_set_datalink(pcap_t *, int); int pcap_datalink_name_to_val(const char *); const char *pcap_datalink_val_to_name(int); +const char *pcap_datalink_val_to_description(int); int pcap_snapshot(pcap_t *); int pcap_is_swapped(pcap_t *); int pcap_major_version(pcap_t *);