aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-03-24 23:36:29 -0700
committerGuy Harris <gharris@sonic.net>2021-03-25 07:34:37 +0000
commitd18e1f19e9de19a76647f4df46b83a60be47e785 (patch)
tree66a0b0730c59e3d16eeed4e4f76d74d1c659d3b3 /dumpcap.c
parentecad065809553e77b1c459e377068eba3e336d03 (diff)
Add dumpcap options to set the name and description for a capture source.
Add --ifname and --ifdescr to allow the name and description for an interface or pipe to be set; this overrides the specified name or reported description for an interface, and overrides the pipe path name and provides a description for a pipe. Provide those arguments when capturing from an extcap program. This is mainly for extcaps, so you have something more meaningful than some random path name as the interface name and something descriptive for the description.
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 19cf9f3818..609efa488a 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -367,6 +367,11 @@ print_usage(FILE *output)
" or for remote capturing, use one of these formats:\n"
" rpcap://<host>/<interface>\n"
" TCP@<host>:<port>\n");
+ fprintf(output, " --ifname <name> name to use in the capture file for a pipe from which\n");
+ fprintf(output, " we're capturing\n");
+ fprintf(output, " --ifdescr <description>\n");
+ fprintf(output, " description to use in the capture file for a pipe\n");
+ fprintf(output, " from which we're capturing\n");
fprintf(output, " -f <capture filter> packet filter in libpcap filter syntax\n");
fprintf(output, " -s <snaplen>, --snapshot-length <snaplen>\n");
#ifdef HAVE_PCAP_CREATE
@@ -3146,8 +3151,8 @@ capture_loop_init_pcapng_output(capture_options *capture_opts, loop_data *ld,
pcap_src->snaplen = pcap_snapshot(pcap_src->pcap_h);
}
successful = pcapng_write_interface_description_block(global_ld.pdh,
- NULL, /* OPT_COMMENT 1 */
- interface_opts->name, /* IDB_NAME 2 */
+ NULL, /* OPT_COMMENT 1 */
+ (interface_opts->ifname != NULL) ? interface_opts->ifname : interface_opts->name, /* IDB_NAME 2 */
interface_opts->descr, /* IDB_DESCRIPTION 3 */
interface_opts->cfilter, /* IDB_FILTER 11 */
os_info_str->str, /* IDB_OS 12 */
@@ -4820,6 +4825,9 @@ get_dumpcap_runtime_info(GString *str)
get_runtime_caplibs_version(str);
}
+#define LONGOPT_IFNAME LONGOPT_BASE_APPLICATION+1
+#define LONGOPT_IFDESCR LONGOPT_BASE_APPLICATION+2
+
/* And now our feature presentation... [ fade to music ] */
int
main(int argc, char *argv[])
@@ -4830,6 +4838,8 @@ main(int argc, char *argv[])
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
LONGOPT_CAPTURE_COMMON
+ {"ifname", required_argument, NULL, LONGOPT_IFNAME},
+ {"ifdescr", required_argument, NULL, LONGOPT_IFDESCR},
{0, 0, 0, 0 }
};
@@ -5190,6 +5200,28 @@ main(int argc, char *argv[])
}
break;
/*** hidden option: Wireshark child mode (using binary output messages) ***/
+ case LONGOPT_IFNAME:
+ if (global_capture_opts.ifaces->len > 0) {
+ interface_options *interface_opts;
+
+ interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, global_capture_opts.ifaces->len - 1);
+ interface_opts->ifname = g_strdup(optarg);
+ } else {
+ cmdarg_err("--ifname must be specified after a -i option");
+ exit_main(1);
+ }
+ break;
+ case LONGOPT_IFDESCR:
+ if (global_capture_opts.ifaces->len > 0) {
+ interface_options *interface_opts;
+
+ interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, global_capture_opts.ifaces->len - 1);
+ interface_opts->descr = g_strdup(optarg);
+ } else {
+ cmdarg_err("--ifdescr must be specified after a -i option");
+ exit_main(1);
+ }
+ break;
case 'Z':
capture_child = TRUE;
#ifdef _WIN32
@@ -5530,6 +5562,25 @@ main(int argc, char *argv[])
g_string_append_printf(str, "and ");
}
}
+ if (interface_opts->ifname != NULL) {
+ /*
+ * Re-generate the display name based on the strins
+ * we were handed.
+ */
+ g_free(interface_opts->display_name);
+ if (interface_opts->descr != NULL) {
+#ifdef _WIN32
+ interface_opts->display_name = g_strdup_printf("%s",
+ interface_opts->descr);
+#else
+ interface_opts->display_name = g_strdup_printf("%s: %s",
+ interface_opts->descr, interface_opts->ifname);
+#endif
+ } else {
+ interface_opts->display_name = g_strdup_printf("%s",
+ interface_opts->ifname);
+ }
+ }
g_string_append_printf(str, "'%s'", interface_opts->display_name);
}
} else {