Stack overflow after selecting data when filter is applied that has no results (Wires...
[metze/wireshark/wip.git] / capture-pcap-util-unix.c
index df78f03176c9ff996fa3d029c94ead84897a3915..2e476ab82b67312b4971937dbf74ad0af96c7ffa 100644 (file)
 
 #ifdef HAVE_LIBPCAP
 
+#ifdef HAVE_PCAP_FINDALLDEVS
+
+#include <pcap.h>
+
+#else /* HAVE_PCAP_FINDALLDEVS */
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -56,19 +62,13 @@ struct rtentry;
 # include <sys/sockio.h>
 #endif
 
-#include "capture_ifinfo.h"
 #include "capture-pcap-util.h"
-#include "capture-pcap-util-int.h"
 
-#ifndef HAVE_PCAP_FINDALLDEVS
-struct search_user_data {
-       char    *name;
-       if_info_t *if_info;
-};
+#endif  /* HAVE_PCAP_FINDALLDEVS */
 
-static void
-search_for_if_cb(gpointer data, gpointer user_data);
-#endif
+#include "capture_ifinfo.h"
+#include "capture-pcap-util.h"
+#include "capture-pcap-util-int.h"
 
 #ifdef HAVE_PCAP_REMOTE
 GList *
@@ -101,12 +101,31 @@ get_remote_interface_list(const char *hostname, const char *port,
 }
 #endif
 
+#ifdef HAVE_PCAP_FINDALLDEVS
 GList *
 get_interface_list(int *err, char **err_str)
 {
-#ifdef HAVE_PCAP_FINDALLDEVS
        return get_interface_list_findalldevs(err, err_str);
-#else
+}
+#else /* HAVE_PCAP_FINDALLDEVS */
+struct search_user_data {
+       char    *name;
+       if_info_t *if_info;
+};
+
+static void
+search_for_if_cb(gpointer data, gpointer user_data)
+{
+       struct search_user_data *search_user_data = user_data;
+       if_info_t *if_info = data;
+
+       if (strcmp(if_info->name, search_user_data->name) == 0)
+               search_user_data->if_info = if_info;
+}
+
+GList *
+get_interface_list(int *err, char **err_str)
+{
        GList  *il = NULL;
        gint    nonloopback_pos = 0;
        struct  ifreq *ifr, *last;
@@ -119,6 +138,7 @@ get_interface_list(int *err, char **err_str)
        char *buf;
        if_info_t *if_info;
        char errbuf[PCAP_ERRBUF_SIZE];
+       gboolean loopback;
 
        if (sock < 0) {
                *err = CANT_GET_INTERFACE_LIST;
@@ -234,14 +254,13 @@ get_interface_list(int *err, char **err_str)
                 * don't want a loopback interface to be the default capture
                 * device unless there are no non-loopback devices.
                 */
-               if_info = if_info_new(ifr->ifr_name, NULL);
+               loopback = ((ifrflags.ifr_flags & IFF_LOOPBACK) ||
+                   strncmp(ifr->ifr_name, "lo", 2) == 0);
+               if_info = if_info_new(ifr->ifr_name, NULL, loopback);
                if_info_add_address(if_info, &ifr->ifr_addr);
-               if ((ifrflags.ifr_flags & IFF_LOOPBACK) ||
-                   strncmp(ifr->ifr_name, "lo", 2) == 0) {
-                       if_info->loopback = TRUE;
+               if (loopback)
                        il = g_list_append(il, if_info);
-               } else {
-                       if_info->loopback = FALSE;
+               else {
                        il = g_list_insert(il, if_info, nonloopback_pos);
                        /*
                         * Insert the next non-loopback interface after this
@@ -274,7 +293,7 @@ get_interface_list(int *err, char **err_str)
                 * It worked; we can use the "any" device.
                 */
                if_info = if_info_new("any",
-                   "Pseudo-device that captures on all interfaces");
+                   "Pseudo-device that captures on all interfaces", FALSE);
                il = g_list_insert(il, if_info, -1);
                pcap_close(pch);
        }
@@ -300,18 +319,6 @@ fail:
        close(sock);
        *err = CANT_GET_INTERFACE_LIST;
        return NULL;
-#endif /* HAVE_PCAP_FINDALLDEVS */
-}
-
-#ifndef HAVE_PCAP_FINDALLDEVS
-static void
-search_for_if_cb(gpointer data, gpointer user_data)
-{
-       struct search_user_data *search_user_data = user_data;
-       if_info_t *if_info = data;
-
-       if (strcmp(if_info->name, search_user_data->name) == 0)
-               search_user_data->if_info = if_info;
 }
 #endif /* HAVE_PCAP_FINDALLDEVS */