diff --git a/capture_opts.c b/capture_opts.c index 76fe857efc..939a6437f5 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -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 diff --git a/capture_opts.h b/capture_opts.h index a962492a1b..236d371bf5 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -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 diff --git a/dumpcap.c b/dumpcap.c index 7f7fc40788..4602da345e 100644 --- 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. */ diff --git a/tshark.c b/tshark.c index dfc4c62ad1..8709c6fcc4 100644 --- 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) { diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 7ad5d0d61a..7c60749cb7 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -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); } } diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index 2dcf9868bc..c5f0ed1ce4 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -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); // } // }