aboutsummaryrefslogtreecommitdiffstats
path: root/capture-wpcap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-09-27 01:11:23 +0000
committerGuy Harris <guy@alum.mit.edu>2004-09-27 01:11:23 +0000
commit1d400fd77fa807422238c01abb335bbbbe7b978d (patch)
tree1dd53ef92fe21aedf8b16627bedd68cc55bff99f /capture-wpcap.c
parentf62467ec34d401f518fa67bbc702d22bba4f1e3a (diff)
If "HAVE_PCAP_DATALINK_NAME_TO_VAL" is defined - i.e., if we're built
with a version of WinPcap that has "pcap_datalink_name_to_val()" - then, if the version of WinPcap we've loaded doesn't have "pcap_datalink_name_to_val()", supply our own version. Do the equivalent for "pcap_datalink_val_to_name()". We do that so that we can build Ethereal with a recent version of WinPcap, so that it uses the new APIs in newer versions, and still have it work with older versions. svn path=/trunk/; revision=12109
Diffstat (limited to 'capture-wpcap.c')
-rw-r--r--capture-wpcap.c132
1 files changed, 128 insertions, 4 deletions
diff --git a/capture-wpcap.c b/capture-wpcap.c
index da78001fe3..7d88073e69 100644
--- a/capture-wpcap.c
+++ b/capture-wpcap.c
@@ -262,12 +262,122 @@ pcap_freealldevs(pcap_if_t *a)
}
#endif
+#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME)
+/*
+ * Table of DLT_ types, names, and descriptions, for use if the version
+ * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
+ * or "pcap_datalink_val_to_name()".
+ */
+struct dlt_choice {
+ const char *name;
+ const char *description;
+ int dlt;
+};
+
+#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, "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, "BSD/OS SLIP"),
+#endif
+#ifdef DLT_PPP_BSDOS
+ DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
+#endif
+#ifdef DLT_ATM_CLIP
+ DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
+#endif
+#ifdef DLT_PPP_SERIAL
+ DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
+#endif
+#ifdef DLT_PPP_ETHER
+ DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
+#endif
+#ifdef DLT_C_HDLC
+ DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
+#endif
+#ifdef DLT_IEEE802_11
+ DLT_CHOICE(DLT_IEEE802_11, "802.11"),
+#endif
+#ifdef DLT_FRELAY
+ DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
+#endif
+#ifdef DLT_LOOP
+ DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
+#endif
+#ifdef DLT_ENC
+ DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
+#endif
+#ifdef DLT_LINUX_SLL
+ DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
+#endif
+#ifdef 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, "RFC 2625 IP-over-Fibre Channel"),
+#endif
+#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, "Linux 802.3 LANE"),
+#endif
+#ifdef DLT_CIP
+ DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"),
+#endif
+#ifdef DLT_HDLC
+ DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
+#endif
+ DLT_CHOICE_SENTINEL
+};
+#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) */
+
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
int
pcap_datalink_name_to_val(const char *name)
{
- g_assert(has_wpcap && p_pcap_datalink_name_to_val != NULL);
- return p_pcap_datalink_name_to_val(name);
+ int i;
+
+ g_assert(has_wpcap);
+
+ if (p_pcap_datalink_name_to_val != NULL)
+ return p_pcap_datalink_name_to_val(name);
+ else {
+ /*
+ * We don't have it in WinPcap; do it ourselves.
+ */
+ for (i = 0; dlt_choices[i].name != NULL; i++) {
+ if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
+ name) == 0)
+ return dlt_choices[i].dlt;
+ }
+ return -1;
+ }
}
#endif
@@ -275,8 +385,22 @@ pcap_datalink_name_to_val(const char *name)
const char *
pcap_datalink_val_to_name(int dlt)
{
- g_assert(has_wpcap && p_pcap_datalink_val_to_name != NULL);
- return p_pcap_datalink_val_to_name(dlt);
+ int i;
+
+ g_assert(has_wpcap);
+
+ if (p_pcap_datalink_val_to_name != NULL)
+ return p_pcap_datalink_val_to_name(dlt);
+ else {
+ /*
+ * We don't have it in WinPcap; do it ourselves.
+ */
+ for (i = 0; dlt_choices[i].name != NULL; i++) {
+ if (dlt_choices[i].dlt == dlt)
+ return dlt_choices[i].name + sizeof("DLT_") - 1;
+ }
+ return NULL;
+ }
}
#endif