From d18e1f19e9de19a76647f4df46b83a60be47e785 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 24 Mar 2021 23:36:29 -0700 Subject: 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. --- dumpcap.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'dumpcap.c') 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:///\n" " TCP@:\n"); + fprintf(output, " --ifname name to use in the capture file for a pipe from which\n"); + fprintf(output, " we're capturing\n"); + fprintf(output, " --ifdescr \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 packet filter in libpcap filter syntax\n"); fprintf(output, " -s , --snapshot-length \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 { -- cgit v1.2.3