forked from osmocom/wireshark
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.
This commit is contained in:
parent
d6c3781a7a
commit
fcb56bd1d4
|
@ -322,15 +322,6 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
|
|||
|
||||
g_strfreev(raw_list);
|
||||
|
||||
/* Check to see if we built a list */
|
||||
if (linktype_list == NULL) {
|
||||
/* No. */
|
||||
if (err_primary_msg)
|
||||
*err_primary_msg = g_strdup("Dumpcap returned no link-layer types");
|
||||
g_free(caps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
caps->data_link_types = linktype_list;
|
||||
/* Might be NULL. Not all systems report timestamp types */
|
||||
caps->timestamp_types = timestamp_list;
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -341,14 +341,15 @@ extern void
|
|||
capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
|
||||
|
||||
enum caps_query {
|
||||
CAPS_MONITOR_MODE = 0x1,
|
||||
CAPS_QUERY_LINK_TYPES = 0x2,
|
||||
CAPS_QUERY_TIMESTAMP_TYPES = 0x4
|
||||
CAPS_QUERY_LINK_TYPES = 0x1,
|
||||
CAPS_QUERY_TIMESTAMP_TYPES = 0x2
|
||||
};
|
||||
|
||||
/* print interface capabilities, including link layer types */
|
||||
extern void
|
||||
capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
|
||||
extern int
|
||||
capture_opts_print_if_capabilities(if_capabilities_t *caps,
|
||||
interface_options *interface_opts,
|
||||
int queries);
|
||||
|
||||
/* print list of interfaces */
|
||||
extern void
|
||||
|
|
23
dumpcap.c
23
dumpcap.c
|
@ -5472,7 +5472,6 @@ main(int argc, char *argv[])
|
|||
guint ii;
|
||||
|
||||
for (ii = 0; ii < global_capture_opts.ifaces->len; ii++) {
|
||||
int if_caps_queries = caps_queries;
|
||||
interface_options *interface_opts;
|
||||
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, ii);
|
||||
|
@ -5496,23 +5495,21 @@ main(int argc, char *argv[])
|
|||
g_free(err_str);
|
||||
exit_main(2);
|
||||
}
|
||||
if ((if_caps_queries & CAPS_QUERY_LINK_TYPES) && caps->data_link_types == NULL) {
|
||||
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts->name);
|
||||
exit_main(2);
|
||||
} /* No timestamp types is no big deal. So we will just ignore it */
|
||||
|
||||
if (interface_opts->monitor_mode)
|
||||
if_caps_queries |= CAPS_MONITOR_MODE;
|
||||
|
||||
if (machine_readable) /* tab-separated values to stdout */
|
||||
if (machine_readable) { /* tab-separated values to stdout */
|
||||
/* XXX: We need to change the format and adapt consumers */
|
||||
print_machine_readable_if_capabilities(caps, if_caps_queries);
|
||||
else
|
||||
print_machine_readable_if_capabilities(caps, caps_queries);
|
||||
status = 0;
|
||||
} else
|
||||
/* XXX: We might want to print also the interface name */
|
||||
capture_opts_print_if_capabilities(caps, interface_opts->name, if_caps_queries);
|
||||
status = capture_opts_print_if_capabilities(caps,
|
||||
interface_opts,
|
||||
caps_queries);
|
||||
free_if_capabilities(caps);
|
||||
if (status != 0)
|
||||
break;
|
||||
}
|
||||
exit_main(0);
|
||||
exit_main(status);
|
||||
}
|
||||
|
||||
#ifdef HAVE_PCAP_SET_TSTAMP_TYPE
|
||||
|
|
18
tshark.c
18
tshark.c
|
@ -2196,7 +2196,6 @@ main(int argc, char *argv[])
|
|||
interface_options *interface_opts;
|
||||
if_capabilities_t *caps;
|
||||
char *auth_str = NULL;
|
||||
int if_caps_queries = caps_queries;
|
||||
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
|
@ -2214,20 +2213,11 @@ main(int argc, char *argv[])
|
|||
exit_status = INVALID_CAPABILITY;
|
||||
goto clean_exit;
|
||||
}
|
||||
if ((if_caps_queries & CAPS_QUERY_LINK_TYPES) && caps->data_link_types == NULL) {
|
||||
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts->name);
|
||||
exit_status = IFACE_HAS_NO_LINK_TYPES;
|
||||
goto clean_exit;
|
||||
}
|
||||
if ((if_caps_queries & CAPS_QUERY_TIMESTAMP_TYPES) && caps->timestamp_types == NULL) {
|
||||
cmdarg_err("The capture device \"%s\" has no timestamp types.", interface_opts->name);
|
||||
exit_status = INVALID_TIMESTAMP_TYPE;
|
||||
goto clean_exit;
|
||||
}
|
||||
if (interface_opts->monitor_mode)
|
||||
if_caps_queries |= CAPS_MONITOR_MODE;
|
||||
capture_opts_print_if_capabilities(caps, interface_opts->name, if_caps_queries);
|
||||
exit_status = capture_opts_print_if_capabilities(caps, interface_opts,
|
||||
caps_queries);
|
||||
free_if_capabilities(caps);
|
||||
if (exit_status != EXIT_SUCCESS)
|
||||
goto clean_exit;
|
||||
}
|
||||
exit_status = EXIT_SUCCESS;
|
||||
goto clean_exit;
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
#define __EXIT_CODES_H__
|
||||
|
||||
/* Exit codes */
|
||||
#define INVALID_OPTION 1
|
||||
#define INVALID_INTERFACE 2
|
||||
#define INVALID_FILE 2
|
||||
#define INVALID_FILTER 2
|
||||
#define INVALID_CAPABILITY 2
|
||||
#define IFACE_HAS_NO_LINK_TYPES 2
|
||||
#define INVALID_TIMESTAMP_TYPE 2
|
||||
#define INIT_FAILED 2
|
||||
#define OPEN_ERROR 2
|
||||
#define INVALID_OPTION 1
|
||||
#define INVALID_INTERFACE 2
|
||||
#define INVALID_FILE 2
|
||||
#define INVALID_FILTER 2
|
||||
#define INVALID_CAPABILITY 2
|
||||
#define IFACE_HAS_NO_LINK_TYPES 2
|
||||
#define IFACE_HAS_NO_TIMESTAMP_TYPES 2
|
||||
#define INIT_FAILED 2
|
||||
#define OPEN_ERROR 2
|
||||
|
||||
#endif /* __EXIT_CODES_H__ */
|
||||
|
||||
|
|
|
@ -896,7 +896,6 @@ int main(int argc, char *qt_argv[])
|
|||
interface_options *interface_opts;
|
||||
if_capabilities_t *caps;
|
||||
char *auth_str = NULL;
|
||||
int if_caps_queries = caps_queries;
|
||||
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
|
@ -914,26 +913,17 @@ int main(int argc, char *qt_argv[])
|
|||
ret_val = INVALID_CAPABILITY;
|
||||
goto clean_exit;
|
||||
}
|
||||
if ((if_caps_queries & CAPS_QUERY_LINK_TYPES) && caps->data_link_types == NULL) {
|
||||
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts->name);
|
||||
ret_val = IFACE_HAS_NO_LINK_TYPES;
|
||||
goto clean_exit;
|
||||
}
|
||||
if ((if_caps_queries & CAPS_QUERY_TIMESTAMP_TYPES) && caps->timestamp_types == NULL) {
|
||||
cmdarg_err("The capture device \"%s\" has no timestamp types.", interface_opts->name);
|
||||
ret_val = INVALID_TIMESTAMP_TYPE;
|
||||
goto clean_exit;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
create_console();
|
||||
#endif /* _WIN32 */
|
||||
if (interface_opts->monitor_mode)
|
||||
if_caps_queries |= CAPS_MONITOR_MODE;
|
||||
capture_opts_print_if_capabilities(caps, interface_opts->name, if_caps_queries);
|
||||
ret_val = capture_opts_print_if_capabilities(caps, interface_opts,
|
||||
caps_queries);
|
||||
#ifdef _WIN32
|
||||
destroy_console();
|
||||
#endif /* _WIN32 */
|
||||
free_if_capabilities(caps);
|
||||
if (ret_val != EXIT_SUCCESS)
|
||||
goto clean_exit;
|
||||
}
|
||||
ret_val = EXIT_SUCCESS;
|
||||
goto clean_exit;
|
||||
|
|
Loading…
Reference in New Issue