forked from osmocom/wireshark
On error, have capture_opts_trim_iface() return the exit status that
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
This commit is contained in:
parent
03f4fa5223
commit
d415d3d87c
|
@ -446,7 +446,10 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
|
||||||
gchar *err_str;
|
gchar *err_str;
|
||||||
interface_options interface_opts;
|
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_list = capture_interface_list(&err, &err_str);
|
||||||
if (if_list == NULL) {
|
if (if_list == NULL) {
|
||||||
switch (err) {
|
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");
|
cmdarg_err("There are no interfaces on which a capture can be done");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the argument is a number, treat it as an index into the list
|
* If the argument is a number, treat it as an index into the list
|
||||||
* of adapters, as printed by "tshark -D".
|
* 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;
|
int status;
|
||||||
|
|
||||||
/* Did the user specify an interface to use? */
|
/* Did the user specify an interface to use? */
|
||||||
if (capture_opts->num_selected != 0 || capture_opts->ifaces->len != 0) {
|
if (capture_opts->num_selected != 0 || capture_opts->ifaces->len != 0) {
|
||||||
/* yes they did, exit immediately nothing further to do here */
|
/* yes they did, return immediately - nothing further to do here */
|
||||||
return TRUE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No - is a default specified in the preferences file? */
|
/* No - is a default specified in the preferences file? */
|
||||||
if (capture_device != NULL) {
|
if (capture_device != NULL) {
|
||||||
/* Yes - use it. */
|
/* Yes - use it. */
|
||||||
status = capture_opts_add_iface_opt(capture_opts, capture_device);
|
status = capture_opts_add_iface_opt(capture_opts, capture_device);
|
||||||
if (status == 0)
|
return status;
|
||||||
return TRUE; /* interface found */
|
|
||||||
return FALSE; /* some kind of error finding interface */
|
|
||||||
}
|
}
|
||||||
/* No default in preferences file, just pick the first interface from the list of interfaces. */
|
/* No default in preferences file, just pick the first interface from the list of interfaces. */
|
||||||
status = capture_opts_add_iface_opt(capture_opts, "1");
|
return capture_opts_add_iface_opt(capture_opts, "1");
|
||||||
if (status == 0)
|
|
||||||
return TRUE; /* success */
|
|
||||||
return FALSE; /* some kind of error finding the first interface */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef S_IFIFO
|
#ifndef S_IFIFO
|
||||||
#define S_IFIFO _S_IFIFO
|
#define S_IFIFO _S_IFIFO
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -264,7 +264,7 @@ extern void
|
||||||
capture_opts_trim_ring_num_files(capture_options *capture_opts);
|
capture_opts_trim_ring_num_files(capture_options *capture_opts);
|
||||||
|
|
||||||
/* trim the interface entry */
|
/* trim the interface entry */
|
||||||
extern gboolean
|
extern int
|
||||||
capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device);
|
capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
|
|
|
@ -4673,9 +4673,10 @@ main(int argc, char *argv[])
|
||||||
* "-L", "-d", and capturing act on a particular interface, so we have to
|
* "-L", "-d", and capturing act on a particular interface, so we have to
|
||||||
* have an interface; if none was specified, pick a default.
|
* 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 .... */
|
/* cmdarg_err() already called .... */
|
||||||
exit_main(1);
|
exit_main(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Let the user know what interfaces were chosen. */
|
/* Let the user know what interfaces were chosen. */
|
||||||
|
|
8
tshark.c
8
tshark.c
|
@ -1871,10 +1871,10 @@ main(int argc, char *argv[])
|
||||||
do we have support for live captures? */
|
do we have support for live captures? */
|
||||||
#ifdef HAVE_LIBPCAP
|
#ifdef HAVE_LIBPCAP
|
||||||
/* trim the interface name and exit if that failed */
|
/* trim the interface name and exit if that failed */
|
||||||
if (!capture_opts_trim_iface(&global_capture_opts,
|
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)) {
|
((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
|
||||||
return 2;
|
if (exit_status != 0)
|
||||||
}
|
return exit_status;
|
||||||
|
|
||||||
/* if requested, list the link layer types and exit */
|
/* if requested, list the link layer types and exit */
|
||||||
if (list_link_layer_types) {
|
if (list_link_layer_types) {
|
||||||
|
|
|
@ -2880,9 +2880,10 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (start_capture || list_link_layer_types) {
|
if (start_capture || list_link_layer_types) {
|
||||||
/* Did the user specify an interface to use? */
|
/* Did the user specify an interface to use? */
|
||||||
if (!capture_opts_trim_iface(&global_capture_opts,
|
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)) {
|
((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
|
||||||
exit(2);
|
if (status != 0) {
|
||||||
|
exit(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1010,9 +1010,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// if (start_capture || list_link_layer_types) {
|
// if (start_capture || list_link_layer_types) {
|
||||||
// /* Did the user specify an interface to use? */
|
// /* Did the user specify an interface to use? */
|
||||||
// if (!capture_opts_trim_iface(&global_capture_opts,
|
// status = capture_opts_trim_iface(&global_capture_opts,
|
||||||
// (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL)) {
|
// (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL);
|
||||||
// exit(2);
|
// if (status != 0) {
|
||||||
|
// exit(status);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue