If dumpcap is run with -D, don't select a default interface; it's not
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 17 May 2010 23:13:24 +0000 (23:13 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 17 May 2010 23:13:24 +0000 (23:13 +0000)
necessary.

If it's run with -D and -M, and we found no interfaces, don't treat that
as an error; let the code that reads our output just indicate it as "no
interfaces available", so *its* caller can decide whether to report an
error or not (in some cases in Wireshark, it's obvious that there are no
interfaces, e.g. there aren't any listed on the welcome screen, so
popping up a dialog is pointless).

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

dumpcap.c

index 0a6f5fff10072b30a79b797b8f0d65379c4a7683..c33b16921ea01323b2fb2844117f965cad3167f2 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -3443,15 +3443,6 @@ main(int argc, char *argv[])
     }
   }
 
-  if (capture_opts_trim_iface(&global_capture_opts, NULL) == FALSE) {
-    /* cmdarg_err() already called .... */
-    exit_main(1);
-  }
-
-  /* Let the user know what interface was chosen. */
-  /* get_interface_descriptive_name() is not available! */
-  g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", global_capture_opts.iface);
-
   if (list_interfaces) {
     /* Get the list of interfaces */
     GList       *if_list;
@@ -3464,13 +3455,22 @@ main(int argc, char *argv[])
         case CANT_GET_INTERFACE_LIST:
             cmdarg_err("%s", err_str);
             g_free(err_str);
+            exit_main(2);
             break;
 
         case NO_INTERFACES_FOUND:
-            cmdarg_err("There are no interfaces on which a capture can be done");
+            /*
+            * If we're being run by another program, just give them
+            * an empty list of interfaces, don't report this as
+            * an error; that lets them decide whether to report
+            * this as an error or not.
+            */
+            if (!machine_readable) {
+                cmdarg_err("There are no interfaces on which a capture can be done");
+                exit_main(2);
+            }
             break;
         }
-        exit_main(2);
     }
 
     if (machine_readable)      /* tab-separated values to stdout */
@@ -3479,7 +3479,25 @@ main(int argc, char *argv[])
       capture_opts_print_interfaces(if_list);
     free_interface_list(if_list);
     exit_main(0);
-  } else if (list_link_layer_types) {
+  }
+
+  /*
+   * "-D" requires no interface to be selected; it's supposed to list
+   * all interfaces.
+   *
+   * If -D wasn't specified, we have to have an interface; if none
+   * was specified, pick a default.
+   */
+  if (capture_opts_trim_iface(&global_capture_opts, NULL) == FALSE) {
+    /* cmdarg_err() already called .... */
+    exit_main(1);
+  }
+
+  /* Let the user know what interface was chosen. */
+  /* get_interface_descriptive_name() is not available! */
+  g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", global_capture_opts.iface);
+
+  if (list_link_layer_types) {
     /* Get the list of link-layer types for the capture device. */
     if_capabilities_t *caps;
     gchar *err_str;