From Ed Beroset via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9330:
[metze/wireshark/wip.git] / capture_ifinfo.c
index 7899b5f7a0dc6d118ba0a97811fbaf5f7cf04acc..87153ad2b35e87c657ee1a35f1e188408df94f6a 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #include <glib.h>
 
 #include "capture_opts.h"
+#include "capture_session.h"
 #include "capture_sync.h"
 #include "log.h"
 
-#include "wsutil/file_util.h"
-
 #include "capture_ifinfo.h"
 
 #ifdef HAVE_PCAP_REMOTE
@@ -105,7 +105,7 @@ static void append_remote_list(GList *iflist)
 /* XXX - We parse simple text output to get our interface list.  Should
  * we use "real" data serialization instead, e.g. via XML? */
 GList *
-capture_interface_list(int *err, char **err_str)
+capture_interface_list(int *err, char **err_str, void (*update_cb)(void))
 {
     int        ret;
     GList     *if_list = NULL;
@@ -119,7 +119,7 @@ capture_interface_list(int *err, char **err_str)
     g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List ...");
 
     /* Try to get our interface list */
-    ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg);
+    ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg, update_cb);
     if (ret != 0) {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List failed!");
         if (err_str) {
@@ -141,9 +141,9 @@ capture_interface_list(int *err, char **err_str)
     g_free(data);
 
     for (i = 0; raw_list[i] != NULL; i++) {
-        if_parts = g_strsplit(raw_list[i], "\t", 5);
+        if_parts = g_strsplit(raw_list[i], "\t", 6);
         if (if_parts[0] == NULL || if_parts[1] == NULL || if_parts[2] == NULL ||
-                if_parts[3] == NULL || if_parts[4] == NULL) {
+                if_parts[3] == NULL || if_parts[4] == NULL || if_parts[5] == NULL) {
             g_strfreev(if_parts);
             continue;
         }
@@ -163,13 +163,14 @@ capture_interface_list(int *err, char **err_str)
             if_info->vendor_description = g_strdup(if_parts[1]);
         if (strlen(if_parts[2]) > 0)
             if_info->friendly_name = g_strdup(if_parts[2]);
-        addr_parts = g_strsplit(if_parts[3], ",", 0);
+        if_info->type = (interface_type)(int)strtol(if_parts[3], NULL, 10);
+        addr_parts = g_strsplit(if_parts[4], ",", 0);
         for (j = 0; addr_parts[j] != NULL; j++) {
             if_addr = g_new0(if_addr_t,1);
-            if (inet_pton(AF_INET, addr_parts[j], &if_addr->addr.ip4_addr)) {
+            if (inet_pton(AF_INET, addr_parts[j], &if_addr->addr.ip4_addr) > 0) {
                 if_addr->ifat_type = IF_AT_IPv4;
             } else if (inet_pton(AF_INET6, addr_parts[j],
-                    &if_addr->addr.ip6_addr)) {
+                    &if_addr->addr.ip6_addr) > 0) {
                 if_addr->ifat_type = IF_AT_IPv6;
             } else {
                 g_free(if_addr);
@@ -179,7 +180,7 @@ capture_interface_list(int *err, char **err_str)
                 if_info->addrs = g_slist_append(if_info->addrs, if_addr);
             }
         }
-        if (strcmp(if_parts[4], "loopback") == 0)
+        if (strcmp(if_parts[5], "loopback") == 0)
             if_info->loopback = TRUE;
         g_strfreev(if_parts);
         g_strfreev(addr_parts);
@@ -205,7 +206,7 @@ capture_interface_list(int *err, char **err_str)
  * we use "real" data serialization instead, e.g. via XML? */
 if_capabilities_t *
 capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
-                            char **err_str)
+                            char **err_str, void (*update_cb)(void))
 {
     if_capabilities_t *caps;
     GList              *linktype_list = NULL;
@@ -218,7 +219,7 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
 
     /* Try to get our interface list */
     err = sync_if_capabilities_open(ifname, monitor_mode, &data,
-                                    &primary_msg, &secondary_msg);
+                                    &primary_msg, &secondary_msg, update_cb);
     if (err != 0) {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed!");
         if (err_str) {
@@ -340,82 +341,4 @@ void add_interface_to_remote_list(if_info_t *if_info)
     remote_interface_list = g_list_append(remote_interface_list, temp);
 }
 #endif
-
-guint
-get_interface_type(gchar *name, gchar *description)
-{
-#if defined(__linux__)
-    ws_statb64 statb;
-    char *wireless_path;
-#endif
-#if defined(_WIN32)
-    /*
-     * Much digging failed to reveal any obvious way to get something such
-     * as the SNMP MIB-II ifType value for an interface:
-     *
-     *    http://www.iana.org/assignments/ianaiftype-mib
-     *
-     * by making some NDIS request.
-     */
-    if (description && (strstr(description,"generic dialup") != NULL ||
-            strstr(description,"PPP/SLIP") != NULL )) {
-        return IF_DIALUP;
-    } else if (description && (strstr(description,"Wireless") != NULL ||
-            strstr(description,"802.11") != NULL)) {
-        return IF_WIRELESS;
-    } else if (description && strstr(description,"AirPcap") != NULL ||
-            strstr(name,"airpcap")) {
-        return IF_AIRPCAP;
-    } else if (description && strstr(description, "Bluetooth") != NULL ) {
-        return IF_BLUETOOTH;
-    }
-#elif defined(__linux__)
-    /*
-     * Look for /sys/class/net/{device}/wireless.
-     */
-    wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", name);
-    if (wireless_path != NULL) {
-        if (ws_stat64(wireless_path, &statb) == 0) {
-            g_free(wireless_path);
-            return IF_WIRELESS;
-        }
-        g_free(wireless_path);
-    }
-    /*
-     * Bluetooth devices.
-     *
-     * XXX - this is for raw Bluetooth capture; what about IP-over-Bluetooth
-     * devices?
-     */
-    if ( strstr(name,"bluetooth") != NULL) {
-        return IF_BLUETOOTH;
-    }
-
-    /*
-     * USB devices.
-     */
-    if ( strstr(name,"usbmon") != NULL ) {
-        return IF_USB;
-    }
-#endif
-    /*
-     * Bridge, NAT, or host-only interfaces on VMWare hosts have the name
-     * vmnet[0-9]+ or VMnet[0-9+ on Windows. Guests might use a native
-     * (LANCE or E1000) driver or the vmxnet driver. These devices have an
-     * IFT_ of IFT_ETHER, so we have to check the name.
-     */
-    if ( g_ascii_strncasecmp(name, "vmnet", 5) == 0) {
-        return IF_VIRTUAL;
-    }
-
-    if ( g_ascii_strncasecmp(name, "vmxnet", 6) == 0) {
-        return IF_VIRTUAL;
-    }
-
-    if (description && strstr(description, "VMware") != NULL ) {
-        return IF_VIRTUAL;
-    }
-
-    return IF_WIRED;
-}
 #endif /* HAVE_LIBPCAP */