From Markus Renz:
[obnox/wireshark/wip.git] / capture-wpcap.c
index 04ebe5e3225f2cb2de71d24c8c6355db4bc912b4..400b89f08b4e6e4a148359f021db1dc29285a086 100644 (file)
 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
 #include "tools/lemon/cppmagic.h"
 
-#ifdef NEED_G_ASCII_STRCASECMP_H
-#include "g_ascii_strcasecmp.h"
-#endif
-
-
 #define MAX_WIN_IF_NAME_LEN 511
 
 
@@ -108,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;
@@ -165,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 }
        };
 
@@ -242,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)
 {
@@ -476,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)
@@ -559,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);
@@ -722,7 +760,6 @@ get_interface_list(int *err, char **err_str)
        }
 
        return il;
-#endif  /* HAVE_PCAP_REMOTE */
 }
 
 /*
@@ -773,9 +810,9 @@ get_runtime_pcap_version(GString *str)
        gchar *blankp;
 
        if (has_wpcap) {
-               g_string_sprintfa(str, "with ");
+               g_string_append_printf(str, "with ");
                if (p_pcap_lib_version != NULL)
-                       g_string_sprintfa(str, p_pcap_lib_version());
+                       g_string_append_printf(str, p_pcap_lib_version());
                else {
                        /*
                         * An alternative method of obtaining the version
@@ -807,7 +844,7 @@ get_runtime_pcap_version(GString *str)
                                        g_module_close(handle);
                                }
                        }
-                       g_string_sprintfa(str, "WinPcap (%s)", packetVer);
+                       g_string_append_printf(str, "WinPcap (%s)", packetVer);
                }
        } else
                g_string_append(str, "without WinPcap");