From Markus Renz:
[obnox/wireshark/wip.git] / capture-wpcap.c
index a70116826d4203e48d011a052f4e37ae1781cbb5..400b89f08b4e6e4a148359f021db1dc29285a086 100644 (file)
@@ -103,6 +103,18 @@ static int     (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
 static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
 #endif
 
+#ifdef HAVE_PCAP_LIST_DATALINKS
+static int     (*p_pcap_list_datalinks)(pcap_t *, int **);
+#endif
+
+#ifdef HAVE_PCAP_SET_DATALINK
+static int     (*p_pcap_set_datalink)(pcap_t *, int);
+#endif
+
+#ifdef HAVE_FREE_DATALINKS
+static int     (*p_pcap_free_datalinks)(int *);
+#endif
+
 typedef struct {
        const char      *name;
        gpointer        *ptr;
@@ -160,6 +172,15 @@ load_wpcap(void)
                SYM(pcap_lib_version, TRUE),
                SYM(pcap_setbuff, TRUE),
                SYM(pcap_next_ex, TRUE),
+#ifdef HAVE_PCAP_LIST_DATALINKS
+               SYM(pcap_list_datalinks, FALSE),
+#endif
+#ifdef HAVE_PCAP_SET_DATALINK
+               SYM(pcap_set_datalink, FALSE),
+#endif
+#ifdef HAVE_PCAP_FREE_DATALINKS
+               SYM(pcap_free_datalinks, TRUE),
+#endif
                { NULL, NULL, FALSE }
        };
 
@@ -237,6 +258,15 @@ pcap_datalink(pcap_t *a)
        return p_pcap_datalink(a);
 }
 
+#ifdef HAVE_PCAP_SET_DATALINK
+int
+pcap_set_datalink(pcap_t *p, int dlt)
+{
+       g_assert(has_wpcap);
+       return p_pcap_set_datalink(p, dlt);
+}
+#endif
+
 int
 pcap_setfilter(pcap_t *a, struct bpf_program *b)
 {
@@ -471,6 +501,34 @@ pcap_datalink_name_to_val(const char *name)
 }
 #endif
 
+#ifdef HAVE_PCAP_LIST_DATALINKS
+int
+pcap_list_datalinks(pcap_t *p, int **ddlt)
+{
+       g_assert(has_wpcap);
+       return p_pcap_list_datalinks(p, ddlt);
+}
+#endif
+
+#ifdef HAVE_PCAP_FREE_DATALINKS
+void
+pcap_free_datalinks(int *ddlt)
+{
+       g_assert(has_wpcap);
+
+       /*
+        * If we don't have pcap_free_datalinks() in WinPcap,
+        * we don't free the memory - we can't use free(), as
+        * we might not have been built with the same version
+        * of the C runtime library as WinPcap was, and, if we're
+        * not, free() isn't guaranteed to work on something
+        * allocated by WinPcap.
+        */
+       if (p_pcap_free_datalinks != NULL)
+               p_pcap_free_datalinks(ddlt);
+}
+#endif
+
 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
 const char *
 pcap_datalink_val_to_name(int dlt)
@@ -554,29 +612,14 @@ get_remote_interface_list(const char *hostname, const char *port,
 GList *
 get_interface_list(int *err, char **err_str)
 {
-#ifdef HAVE_PCAP_REMOTE
-       char source[PCAP_BUF_SIZE];
-#else
        GList  *il = NULL;
        wchar_t *names;
        char *win95names;
        char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
        char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
        int i, j;
-#endif
        char errbuf[PCAP_ERRBUF_SIZE];
 
-#ifdef HAVE_PCAP_REMOTE
-    if (p_pcap_createsrcstr(source, PCAP_SRC_IFLOCAL, NULL, NULL,
-                            NULL, errbuf) == -1) {
-        *err = CANT_GET_INTERFACE_LIST;
-        if (err_str != NULL)
-            *err_str = cant_get_if_list_error_message(errbuf);
-        return NULL;
-    }
-    return get_interface_list_findalldevs_ex(source, NULL, err, err_str);
-#else
-
 #ifdef HAVE_PCAP_FINDALLDEVS
        if (p_pcap_findalldevs != NULL)
                return get_interface_list_findalldevs(err, err_str);
@@ -717,7 +760,6 @@ get_interface_list(int *err, char **err_str)
        }
 
        return il;
-#endif  /* HAVE_PCAP_REMOTE */
 }
 
 /*