aboutsummaryrefslogtreecommitdiffstats
path: root/capture_opts.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-04-13 23:14:09 -0700
committerGuy Harris <gharris@sonic.net>2021-04-13 23:14:09 -0700
commitfcb56bd1d46eebfa8e7e34cf548fb4718ca5a207 (patch)
tree7dbc7199dbdf5b9e91ecb215cc2f762faa8bb1ff /capture_opts.c
parentd6c3781a7a43404a740f1fcce836c1c93888c719 (diff)
Clean up printing of interface information.
In dumpcap, if we're being run by TShark or Wireshark, if there are no link-layer types, just provide an empty list to our caller; let them construct an empty list of link-layer types when they read our output. In the code that reads that list, don't report an error if the list is empty, rely on the caller to do so. Have capture_opts_print_if_capabilities() do more work, moving some functions from its callers to it.
Diffstat (limited to 'capture_opts.c')
-rw-r--r--capture_opts.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/capture_opts.c b/capture_opts.c
index e48fefa8ed..0c7b7de36d 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -26,6 +26,7 @@
#include <ui/clopts_common.h>
#include <ui/cmdarg_err.h>
+#include <ui/exit_codes.h>
#include <wsutil/file_util.h>
#include <wsutil/ws_pipe.h>
@@ -1002,17 +1003,26 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
return 0;
}
-void
-capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries)
+int
+capture_opts_print_if_capabilities(if_capabilities_t *caps,
+ interface_options *interface_opts,
+ int queries)
{
GList *lt_entry, *ts_entry;
if (queries & CAPS_QUERY_LINK_TYPES) {
+ if (caps->data_link_types == NULL) {
+ cmdarg_err("The capture device \"%s\" has no data link types.",
+ interface_opts->name);
+ return IFACE_HAS_NO_LINK_TYPES;
+ }
if (caps->can_set_rfmon)
printf("Data link types of interface %s when %sin monitor mode (use option -y to set):\n",
- name, (queries & CAPS_MONITOR_MODE) ? "" : "not ");
+ interface_opts->name,
+ (interface_opts->monitor_mode) ? "" : "not ");
else
- printf("Data link types of interface %s (use option -y to set):\n", name);
+ printf("Data link types of interface %s (use option -y to set):\n",
+ interface_opts->name);
for (lt_entry = caps->data_link_types; lt_entry != NULL;
lt_entry = g_list_next(lt_entry)) {
data_link_info_t *data_link_info = (data_link_info_t *)lt_entry->data;
@@ -1026,6 +1036,11 @@ capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int quer
}
if (queries & CAPS_QUERY_TIMESTAMP_TYPES) {
+ if (caps->timestamp_types == NULL) {
+ cmdarg_err("The capture device \"%s\" has no timestamp types.",
+ interface_opts->name);
+ return IFACE_HAS_NO_TIMESTAMP_TYPES;
+ }
printf("Timestamp types of the interface (use option --time-stamp-type to set):\n");
for (ts_entry = caps->timestamp_types; ts_entry != NULL;
ts_entry = g_list_next(ts_entry)) {
@@ -1038,6 +1053,7 @@ capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int quer
printf("\n");
}
}
+ return EXIT_SUCCESS;
}
/* Print an ASCII-formatted list of interfaces. */