Do not use functions for remote capture on local interfaces.
authorstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 3 Nov 2008 20:04:01 +0000 (20:04 +0000)
committerstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 3 Nov 2008 20:04:01 +0000 (20:04 +0000)
This makes it possible to compile with remote capture features on unix.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@26681 f5534014-38df-0310-8fa8-9805f1628bb7

capture-pcap-util-int.h
capture-pcap-util-unix.c
capture-pcap-util.c
capture-wpcap.c
gtk/capture_dlg.c

index ccdd54dfdbfc4c6347ff42f4f1f5a9823246503e..80a60764e70a0cb3b8537c24ca5d2401da63f3ed 100644 (file)
@@ -29,9 +29,9 @@
 #ifdef HAVE_PCAP_REMOTE
 #ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
+#endif /* HAVE_CONFIG_H */
 #include <pcap.h>
-#endif
+#endif /* HAVE_PCAP_REMOTE */
 
 extern if_info_t *if_info_new(char *name, char *description);
 extern void if_info_add_address(if_info_t *if_info, struct sockaddr *addr);
@@ -39,10 +39,9 @@ extern void if_info_add_address(if_info_t *if_info, struct sockaddr *addr);
 #ifdef HAVE_PCAP_REMOTE
 extern GList *get_interface_list_findalldevs_ex(const char *source,
         struct pcap_rmtauth *auth, int *err, char **err_str);
-#else
+#endif /* HAVE_PCAP_REMOTE */
 extern GList *get_interface_list_findalldevs(int *err, char **err_str);
-#endif
-#endif
+#endif /* HAVE_PCAP_FINDALLDEVS */
 
 /*
  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
index c1a6720a00c2a5a121c1877374bf3096be54c252..589ac7d74403f112576af48b439a84180cc136e0 100644 (file)
@@ -82,10 +82,7 @@ get_remote_interface_list(const char *hostname, const char *port,
     struct pcap_rmtauth auth;
     char source[PCAP_BUF_SIZE];
     char errbuf[PCAP_ERRBUF_SIZE];
-
-    auth.type = auth_type;
-    auth.username = username;
-    auth.password = passwd;
+    GList *result;
 
     if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
                           NULL, errbuf) == -1) {
@@ -94,7 +91,16 @@ get_remote_interface_list(const char *hostname, const char *port,
             *err_str = cant_get_if_list_error_message(errbuf);
         return NULL;
     }
-    return get_interface_list_findalldevs_ex(source, &auth, err, err_str);
+
+    auth.type = auth_type;
+    auth.username = g_strdup(username);
+    auth.password = g_strdup(passwd);
+
+    result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
+    g_free(auth.username);
+    g_free(auth.password);
+
+    return result;
 }
 #endif
 
@@ -102,21 +108,7 @@ GList *
 get_interface_list(int *err, char **err_str)
 {
 #ifdef HAVE_PCAP_FINDALLDEVS
-#ifdef HAVE_PCAP_REMOTE
-    char source[PCAP_BUF_SIZE];
-    char errbuf[PCAP_ERRBUF_SIZE];
-
-    if (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
        return get_interface_list_findalldevs(err, err_str);
-#endif
 #else
        GList  *il = NULL;
        gint    nonloopback_pos = 0;
index 54c572609a1a1622b267f25459839c6f04f436a5..aeb1153ab459bcbc5df6107f2067454f61cf2689 100644 (file)
@@ -254,21 +254,49 @@ GList *
 get_interface_list_findalldevs_ex(const char *source,
                                   struct pcap_rmtauth *auth,
                                   int *err, char **err_str)
-#else
+{
+       GList  *il = NULL;
+       pcap_if_t *alldevs, *dev;
+       if_info_t *if_info;
+       char errbuf[PCAP_ERRBUF_SIZE];
+
+        if (pcap_findalldevs_ex((char *)source, auth, &alldevs, errbuf) == -1) {
+               *err = CANT_GET_INTERFACE_LIST;
+               if (err_str != NULL)
+                       *err_str = cant_get_if_list_error_message(errbuf);
+               return NULL;
+       }
+
+       if (alldevs == NULL) {
+               /*
+                * No interfaces found.
+                */
+               *err = NO_INTERFACES_FOUND;
+               if (err_str != NULL)
+                       *err_str = NULL;
+               return NULL;
+       }
+
+       for (dev = alldevs; dev != NULL; dev = dev->next) {
+               if_info = if_info_new(dev->name, dev->description);
+               il = g_list_append(il, if_info);
+               if_info_ip(if_info, dev);
+       }
+       pcap_freealldevs(alldevs);
+
+       return il;
+}
+#endif
+
 GList *
 get_interface_list_findalldevs(int *err, char **err_str)
-#endif
 {
        GList  *il = NULL;
        pcap_if_t *alldevs, *dev;
        if_info_t *if_info;
        char errbuf[PCAP_ERRBUF_SIZE];
 
-#ifdef HAVE_PCAP_REMOTE
-    if (pcap_findalldevs_ex((char *)source, auth, &alldevs, errbuf) == -1) {
-#else
        if (pcap_findalldevs(&alldevs, errbuf) == -1) {
-#endif
                *err = CANT_GET_INTERFACE_LIST;
                if (err_str != NULL)
                        *err_str = cant_get_if_list_error_message(errbuf);
index 90baec774bd3012a069afe9e36e3a9a96b256dd6..400b89f08b4e6e4a148359f021db1dc29285a086 100644 (file)
@@ -612,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);
@@ -775,7 +760,6 @@ get_interface_list(int *err, char **err_str)
        }
 
        return il;
-#endif  /* HAVE_PCAP_REMOTE */
 }
 
 /*
index 66b1d0ed10d2e6ce60e2c5841630d2298f0eba89..52bfaa8be87810dffbffe33fa511d6bd0c52a337 100644 (file)
@@ -288,7 +288,19 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
     /*
      * Try to get the list of known interfaces.
      */
+#ifdef HAVE_PCAP_REMOTE
+    if (global_capture_opts.src_type == CAPTURE_IFREMOTE)
+      if_list = get_remote_interface_list(global_capture_opts.remote_host,
+                                         global_capture_opts.remote_port,
+                                         global_capture_opts.auth_type,
+                                         global_capture_opts.auth_username,
+                                         global_capture_opts.auth_password,
+                                         &err, NULL);
+    else
+      if_list = capture_interface_list(&err, NULL);
+#else
     if_list = capture_interface_list(&err, NULL);
+#endif
     if (if_list != NULL) {
       /*
        * We have the list - check it.
@@ -671,7 +683,7 @@ update_interface_list()
                         global_capture_opts.auth_password,
                         &err, &err_str);
     else
-        if_list = get_interface_list(&err, &err_str);
+        if_list = capture_interface_list(&err, &err_str);
 
     if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
@@ -1005,7 +1017,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
                     global_capture_opts.auth_password,
                     &err, &err_str);
   else
-      if_list = get_interface_list(&err, &err_str);
+      if_list = capture_interface_list(&err, &err_str);
 #else
   if_list = capture_interface_list(&err, &err_str);
 #endif