On error, have capture_opts_trim_iface() return the exit status that
authorGuy Harris <guy@alum.mit.edu>
Wed, 21 Nov 2012 17:14:54 +0000 (17:14 -0000)
committerGuy Harris <guy@alum.mit.edu>
Wed, 21 Nov 2012 17:14:54 +0000 (17:14 -0000)
should be used (on success, have it return 0).  Exit with that exit
status; if the problem is that we couldn't get the interface list or if
there are no interfaces in that list, return 2, as that's not a
command-line syntax error.

svn path=/trunk/; revision=46108

capture_opts.c
capture_opts.h
dumpcap.c
tshark.c
ui/gtk/main.c
ui/qt/main.cpp

index 76fe857efc9c81c3872b767082bfd8585a2ff4d9..939a6437f5929ad5c1294ef8604832c4f5a58e0f 100644 (file)
@@ -446,7 +446,10 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
     gchar       *err_str;
     interface_options interface_opts;
 
-    /* retrieve the interface list to compare the option specfied against */
+    /*
+     * Retrieve the interface list against which to compare the specified
+     * option.
+     */
     if_list = capture_interface_list(&err, &err_str);
     if (if_list == NULL) {
         switch (err) {
@@ -461,10 +464,9 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
             cmdarg_err("There are no interfaces on which a capture can be done");
             break;
         }
-        return 1;
+        return 2;
     }
 
-
     /*
      * If the argument is a number, treat it as an index into the list
      * of adapters, as printed by "tshark -D".
@@ -905,33 +907,27 @@ void capture_opts_trim_ring_num_files(capture_options *capture_opts)
 }
 
 
-gboolean capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device)
+int
+capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device)
 {
     int status;
 
     /* Did the user specify an interface to use? */
     if (capture_opts->num_selected != 0 || capture_opts->ifaces->len != 0) {
-        /* yes they did, exit immediately nothing further to do here */
-        return TRUE;
+        /* yes they did, return immediately - nothing further to do here */
+        return 0;
     }
 
     /* No - is a default specified in the preferences file? */
     if (capture_device != NULL) {
         /* Yes - use it. */
         status = capture_opts_add_iface_opt(capture_opts, capture_device);
-        if (status == 0)
-            return TRUE; /* interface found */
-        return FALSE; /* some kind of error finding interface */
+        return status;
     }
     /* No default in preferences file, just pick the first interface from the list of interfaces. */
-    status = capture_opts_add_iface_opt(capture_opts, "1");
-    if (status == 0)
-        return TRUE; /* success */
-    return FALSE; /* some kind of error finding the first interface */
+    return capture_opts_add_iface_opt(capture_opts, "1");
 }
 
-
-
 #ifndef S_IFIFO
 #define S_IFIFO _S_IFIFO
 #endif
index a962492a1bd7d137751c4415f1cd1c029646c87c..236d371bf5e3b5b3f600537f73b2e7d6b2a28796 100644 (file)
@@ -264,7 +264,7 @@ extern void
 capture_opts_trim_ring_num_files(capture_options *capture_opts);
 
 /* trim the interface entry */
-extern gboolean
+extern int
 capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device);
 
 extern void
index 7f7fc4078833b74c30e0ac3eb5e5efb20ac80595..4602da345e19cc479612d0e2fc6f93b3602c016b 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -4673,9 +4673,10 @@ main(int argc, char *argv[])
      * "-L", "-d", and capturing act on a particular interface, so we have to
      * have an interface; if none was specified, pick a default.
      */
-    if (capture_opts_trim_iface(&global_capture_opts, NULL) == FALSE) {
+    status = capture_opts_trim_iface(&global_capture_opts, NULL);
+    if (status != 0) {
         /* cmdarg_err() already called .... */
-        exit_main(1);
+        exit_main(status);
     }
 
     /* Let the user know what interfaces were chosen. */
index dfc4c62ad11575ffe5575da76f48109855442b85..8709c6fcc456e7e38ecc9bf6f6e53737591f8816 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -1871,10 +1871,10 @@ main(int argc, char *argv[])
        do we have support for live captures? */
 #ifdef HAVE_LIBPCAP
     /* trim the interface name and exit if that failed */
-    if (!capture_opts_trim_iface(&global_capture_opts,
-        ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL)) {
-        return 2;
-    }
+    exit_status = capture_opts_trim_iface(&global_capture_opts,
+        ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
+    if (exit_status != 0)
+        return exit_status;
 
     /* if requested, list the link layer types and exit */
     if (list_link_layer_types) {
index 7ad5d0d61a8cf94459dc5962d4a2e07869607c29..7c60749cb7571e7143db64599b5f76e4b0079fff 100644 (file)
@@ -2880,9 +2880,10 @@ main(int argc, char *argv[])
 
   if (start_capture || list_link_layer_types) {
     /* Did the user specify an interface to use? */
-    if (!capture_opts_trim_iface(&global_capture_opts,
-        ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL)) {
-        exit(2);
+    status = capture_opts_trim_iface(&global_capture_opts,
+        ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
+    if (status != 0) {
+      exit(status);
     }
   }
 
index 2dcf9868bcac9d8c0a685206d33b08d3e9384e47..c5f0ed1ce4bd2538bea089b31f06c4698bc71a2e 100644 (file)
@@ -1010,9 +1010,10 @@ int main(int argc, char *argv[])
 
 //  if (start_capture || list_link_layer_types) {
 //    /* Did the user specify an interface to use? */
-//    if (!capture_opts_trim_iface(&global_capture_opts,
-//        (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL)) {
-//        exit(2);
+//    status = capture_opts_trim_iface(&global_capture_opts,
+//        (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL);
+//    if (status != 0) {
+//      exit(status);
 //    }
 //  }