tshark: clean u the way the -U option lists available taps.

Allow "-U ?" as well as an empty argument; an empty argument is a bit
counterintuitive.

Simplify the introductory line of output - asking for a list of taps
isn't an error in which the user failed to supply a tap name, it's a
case where the user suplied a request for a list of tap names.

Just use fprintf() to print the list, and indent the elements of the
list, as we do with other lists of valid arguments.

List the valid arguments if the user specified an invalid argument as
well.
This commit is contained in:
Guy Harris 2021-03-13 15:32:14 -08:00
parent b5f2ed34b1
commit 9bd144b8ea
2 changed files with 17 additions and 12 deletions

View File

@ -865,10 +865,11 @@ B<hms> for hours, minutes and seconds
=item -U E<lt>tap nameE<gt>
PDUs export, exports PDUs from infile to outfile according to the tap name given.
Use -Y to filter.
PDUs export, exports PDUs from infile to outfile according to the tap
name given. Use -Y to filter.
Enter an empty tap name "" to get a list of available names.
Enter an empty tap name "" or a tap name of ? to get a list of available
names.
=item -v|--version

View File

@ -334,6 +334,16 @@ list_read_capture_types(void) {
g_free(captypes);
}
static void
list_export_pdu_taps(void) {
fprintf(stderr, "tshark: The available export tap names for the \"-U tap_name\" option are:\n");
for (GSList *export_pdu_tap_name_list = get_export_pdu_tap_list();
export_pdu_tap_name_list != NULL;
export_pdu_tap_name_list = g_slist_next(export_pdu_tap_name_list)) {
fprintf(stderr, " %s\n", (const char*)(export_pdu_tap_name_list->data));
}
}
static void
print_usage(FILE *output)
{
@ -1420,20 +1430,13 @@ main(int argc, char *argv[])
}
break;
case 'U': /* Export PDUs to file */
{
GSList *export_pdu_tap_name_list = NULL;
if (!*optarg) {
cmdarg_err("A tap name is required. Valid names are:");
for (export_pdu_tap_name_list = get_export_pdu_tap_list(); export_pdu_tap_name_list; export_pdu_tap_name_list = g_slist_next(export_pdu_tap_name_list)) {
cmdarg_err("%s\n", (const char*)(export_pdu_tap_name_list->data));
}
if (strcmp(optarg, "") == 0 || strcmp(optarg, "?") == 0) {
list_export_pdu_taps();
exit_status = INVALID_OPTION;
goto clean_exit;
}
pdu_export_arg = g_strdup(optarg);
break;
}
case 'v': /* Show version and exit */
show_version();
/* We don't really have to cleanup here, but it's a convenient way to test
@ -2045,6 +2048,7 @@ main(int argc, char *argv[])
if (exp_pdu_error) {
cmdarg_err("Cannot register tap: %s", exp_pdu_error);
g_free(exp_pdu_error);
list_export_pdu_taps();
exit_status = INVALID_TAP;
goto clean_exit;
}