Fix a typo
[obnox/wireshark/wip.git] / capture-wpcap.c
index 8f7815488cf4f6f36f036f84320c74b176b79e84..7ffb80c78394d0442a9fd5186cc4c1cb68e2465b 100644 (file)
 #include <glib.h>
 #include <gmodule.h>
 
-#ifdef HAVE_LIBPCAP
-#include <pcap.h>
-#endif
-
+#include "capture_ifinfo.h"
 #include "capture-pcap-util.h"
 #include "capture-pcap-util-int.h"
 
@@ -79,6 +76,9 @@ static int (*p_pcap_datalink_name_to_val) (const char *);
 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
 static const char *(*p_pcap_datalink_val_to_name) (int);
 #endif
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
+static const char *(*p_pcap_datalink_val_to_description) (int);
+#endif
 #ifdef HAVE_PCAP_BREAKLOOP
 static void    (*p_pcap_breakloop) (pcap_t *);
 #endif
@@ -105,7 +105,7 @@ static int  (*p_pcap_list_datalinks)(pcap_t *, int **);
 static int     (*p_pcap_set_datalink)(pcap_t *, int);
 #endif
 
-#ifdef HAVE_FREE_DATALINKS
+#ifdef HAVE_PCAP_FREE_DATALINKS
 static int     (*p_pcap_free_datalinks)(int *);
 #endif
 
@@ -155,6 +155,9 @@ load_wpcap(void)
 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
                SYM(pcap_datalink_val_to_name, TRUE),
 #endif
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
+               SYM(pcap_datalink_val_to_description, TRUE),
+#endif
 #ifdef HAVE_PCAP_BREAKLOOP
                /*
                 * We don't try to work around the lack of this at
@@ -213,7 +216,9 @@ load_wpcap(void)
 char*
 pcap_lookupdev (char *a)
 {
-       g_assert(has_wpcap);
+       if (!has_wpcap) {
+               return NULL;
+       }
        return p_pcap_lookupdev(a);
 }
 
@@ -293,15 +298,19 @@ pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
 pcap_t*
 pcap_open_live(const char *a, int b, int c, int d, char *e)
 {
-       g_assert(has_wpcap);
-       return p_pcap_open_live(a, b, c, d, e);
+    if (!has_wpcap) {
+       return NULL;
+    }
+    return p_pcap_open_live(a, b, c, d, e);
 }
 
 #ifdef HAVE_PCAP_REMOTE
 pcap_t*
 pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
 {
-    g_assert(has_wpcap);
+    if (!has_wpcap) {
+       return NULL;
+    }
     return p_pcap_open(a, b, c, d, e, f);
 }
 
@@ -365,7 +374,7 @@ pcap_freealldevs(pcap_if_t *a)
 }
 #endif
 
-#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME)
+#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
 /*
  * Table of DLT_ types, names, and descriptions, for use if the version
  * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
@@ -458,10 +467,13 @@ static struct dlt_choice dlt_choices[] = {
 #endif
 #ifdef DLT_HDLC
        DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
+#endif
+#ifdef DLT_PPI
+       DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
 #endif
        DLT_CHOICE_SENTINEL
 };
-#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) */
+#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
 
 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
 int
@@ -538,6 +550,29 @@ pcap_datalink_val_to_name(int dlt)
 }
 #endif
 
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
+const char *
+pcap_datalink_val_to_description(int dlt)
+{
+       int i;
+
+       g_assert(has_wpcap);
+
+       if (p_pcap_datalink_val_to_description != NULL)
+               return p_pcap_datalink_val_to_description(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].description);
+               }
+               return NULL;
+       }
+}
+#endif
+
 #ifdef HAVE_PCAP_BREAKLOOP
 void pcap_breakloop(pcap_t *a)
 {