Make dissection of AVP: 3GPP-User-Location-Info(22) l=15 f=V-- vnd=TGPP val=303231...
[obnox/wireshark/wip.git] / capture-wpcap.c
index eb7d92382f7792061109920cd043251628ecea46..5492f972ca51ca0448cfaa097e3ddb13a442f386 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"
 
+#include <wsutil/file_util.h>
+
+/* XXX - yes, I know, I should move cppmagic.h to a generic location. */
+#include "tools/lemon/cppmagic.h"
+
 #define MAX_WIN_IF_NAME_LEN 511
 
 
@@ -61,16 +63,15 @@ static int     (*p_pcap_setfilter) (pcap_t *, struct bpf_program *);
 static char*   (*p_pcap_geterr) (pcap_t *);
 static int     (*p_pcap_compile) (pcap_t *, struct bpf_program *, const char *, int,
                        bpf_u_int32);
-#ifdef WPCAP_CONSTIFIED
+static int     (*p_pcap_compile_nopcap) (int, int, struct bpf_program *, const char *, int,
+                       bpf_u_int32);
 static int     (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *,
                        char *);
 static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
-#else
-static int     (*p_pcap_lookupnet) (char *, bpf_u_int32 *, bpf_u_int32 *,
-                       char *);
-static pcap_t* (*p_pcap_open_live) (char *, int, int, int, char *);
-#endif
 static int     (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
+#ifdef HAVE_PCAP_OPEN_DEAD
+static pcap_t* (*p_pcap_open_dead) (int, int);
+#endif
 static void    (*p_pcap_freecode) (struct bpf_program *);
 #ifdef HAVE_PCAP_FINDALLDEVS
 static int     (*p_pcap_findalldevs) (pcap_if_t **, char *);
@@ -82,6 +83,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
@@ -108,17 +112,21 @@ 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
 
+#ifdef HAVE_BPF_IMAGE
+static char     *(*p_bpf_image) (const struct bpf_insn *, int);
+#endif
+
 typedef struct {
        const char      *name;
        gpointer        *ptr;
        gboolean        optional;
 } symbol_table_t;
 
-#define SYM(x, y)      { G_STRINGIFY(x) , (gpointer) &G_PASTE(p_,x), y }
+#define SYM(x, y)      { STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
 
 void
 load_wpcap(void)
@@ -135,13 +143,16 @@ load_wpcap(void)
                SYM(pcap_setfilter, FALSE),
                SYM(pcap_geterr, FALSE),
                SYM(pcap_compile, FALSE),
+                SYM(pcap_compile_nopcap, FALSE),
                SYM(pcap_lookupnet, FALSE),
 #ifdef HAVE_PCAP_REMOTE
                SYM(pcap_open, FALSE),
                SYM(pcap_findalldevs_ex, FALSE),
                SYM(pcap_createsrcstr, FALSE),
-#else
+#endif
                SYM(pcap_open_live, FALSE),
+#ifdef HAVE_PCAP_OPEN_DEAD
+               SYM(pcap_open_dead, FALSE),
 #endif
 #ifdef HAVE_PCAP_SETSAMPLING
                SYM(pcap_setsampling, TRUE),
@@ -158,6 +169,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
@@ -177,6 +191,9 @@ load_wpcap(void)
 #endif
 #ifdef HAVE_PCAP_FREE_DATALINKS
                SYM(pcap_free_datalinks, TRUE),
+#endif
+#ifdef HAVE_BPF_IMAGE
+                SYM(bpf_image, FALSE),
 #endif
                { NULL, NULL, FALSE }
        };
@@ -184,7 +201,7 @@ load_wpcap(void)
        GModule         *wh; /* wpcap handle */
        const symbol_table_t    *sym;
 
-       wh = g_module_open("wpcap", 0);
+       wh = ws_module_open("wpcap.dll", 0);
 
        if (!wh) {
                return;
@@ -216,7 +233,9 @@ load_wpcap(void)
 char*
 pcap_lookupdev (char *a)
 {
-       g_assert(has_wpcap);
+       if (!has_wpcap) {
+               return NULL;
+       }
        return p_pcap_lookupdev(a);
 }
 
@@ -287,32 +306,58 @@ pcap_compile(pcap_t *a, struct bpf_program *b, const char *c, int d,
 }
 
 int
-#ifdef WPCAP_CONSTIFIED
+pcap_compile_nopcap(int a, int b, struct bpf_program *c, const char *d, int e,
+            bpf_u_int32 f)
+{
+       g_assert(has_wpcap);
+       return p_pcap_compile_nopcap(a, b, c, d, e, f);
+}
+
+int
 pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
-#else
-pcap_lookupnet(char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
-#endif
 {
        g_assert(has_wpcap);
        return p_pcap_lookupnet(a, b, c, d);
 }
 
 pcap_t*
-#ifdef WPCAP_CONSTIFIED
 pcap_open_live(const char *a, int b, int c, int d, char *e)
-#else
-pcap_open_live(char *a, int b, int c, int d, char *e)
+{
+    if (!has_wpcap) {
+       return NULL;
+    }
+    return p_pcap_open_live(a, b, c, d, e);
+}
+
+#ifdef HAVE_PCAP_OPEN_DEAD
+pcap_t*
+pcap_open_dead(int a, int b)
+{
+    if (!has_wpcap) {
+       return NULL;
+    }
+    return p_pcap_open_dead(a, b);
+}
 #endif
+
+#ifdef HAVE_BPF_IMAGE
+char *
+bpf_image(const struct bpf_insn *a, int b)
 {
-       g_assert(has_wpcap);
-       return p_pcap_open_live(a, b, c, d, e);
+    if (!has_wpcap) {
+       return NULL;
+    }
+    return p_bpf_image(a, b);
 }
+#endif
 
 #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);
 }
 
@@ -376,7 +421,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()"
@@ -469,10 +514,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
@@ -549,6 +597,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)
 {
@@ -802,7 +873,7 @@ get_runtime_pcap_version(GString *str)
         * not and, if we have it and we have "pcap_lib_version()",
         * what version we have.
         */
-       GModule *handle;                /* handle returned by dlopen */
+       GModule *handle;                /* handle returned by ws_module_open */
        static gchar *packetVer;
        gchar *blankp;
 
@@ -826,7 +897,7 @@ get_runtime_pcap_version(GString *str)
                         */
                        if (packetVer == NULL) {
                                packetVer = "version unknown";
-                               handle = g_module_open("Packet.dll", 0);
+                               handle = ws_module_open("packet.dll", 0);
                                if (handle != NULL) {
                                        if (g_module_symbol(handle,
                                            "PacketLibraryVersion",