forked from osmocom/wireshark
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.pespin/rlcmac
parent
ecad065809
commit
d18e1f19e9
|
@ -342,6 +342,15 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
|
|||
#else
|
||||
argv = sync_pipe_add_arg(argv, &argc, interface_opts->extcap_fifo);
|
||||
#endif
|
||||
/* Add a name for the interface, to put into an IDB. */
|
||||
argv = sync_pipe_add_arg(argv, &argc, "--ifname");
|
||||
argv = sync_pipe_add_arg(argv, &argc, interface_opts->name);
|
||||
if (interface_opts->descr != NULL)
|
||||
{
|
||||
/* Add a description for the interface, to put into an IDB. */
|
||||
argv = sync_pipe_add_arg(argv, &argc, "--ifdescr");
|
||||
argv = sync_pipe_add_arg(argv, &argc, interface_opts->descr);
|
||||
}
|
||||
}
|
||||
else
|
||||
argv = sync_pipe_add_arg(argv, &argc, interface_opts->name);
|
||||
|
|
|
@ -563,6 +563,7 @@ fill_in_interface_opts_from_ifinfo(interface_options *interface_opts,
|
|||
interface_opts->descr = NULL;
|
||||
interface_opts->display_name = g_strdup(if_info->name);
|
||||
}
|
||||
interface_opts->ifname = NULL;
|
||||
interface_opts->if_type = if_info->type;
|
||||
interface_opts->extcap = g_strdup(if_info->extcap);
|
||||
}
|
||||
|
@ -740,6 +741,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
|
|||
interface_opts.descr = NULL;
|
||||
interface_opts.hardware = NULL;
|
||||
interface_opts.display_name = g_strdup(optarg_str_p);
|
||||
interface_opts.ifname = NULL;
|
||||
interface_opts.if_type = capture_opts->default_options.if_type;
|
||||
interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
|
||||
}
|
||||
|
@ -1206,6 +1208,7 @@ capture_opts_del_iface(capture_options *capture_opts, guint if_index)
|
|||
g_free(interface_opts->descr);
|
||||
g_free(interface_opts->hardware);
|
||||
g_free(interface_opts->display_name);
|
||||
g_free(interface_opts->ifname);
|
||||
g_free(interface_opts->cfilter);
|
||||
g_free(interface_opts->timestamp_type);
|
||||
g_free(interface_opts->extcap);
|
||||
|
|
|
@ -197,6 +197,7 @@ typedef struct interface_options_tag {
|
|||
gchar *descr; /* a more user-friendly description of the interface; may be NULL if none */
|
||||
gchar *hardware; /* description of the hardware */
|
||||
gchar *display_name; /* the name displayed in the console and title bar */
|
||||
gchar *ifname; /* if not null, name to use instead of the interface naem in IDBs */
|
||||
gchar *cfilter;
|
||||
gboolean has_snaplen;
|
||||
int snaplen;
|
||||
|
|
|
@ -29,6 +29,8 @@ S<[ B<-M> ]>
|
|||
S<[ B<-n> ]>
|
||||
S<[ B<-N> E<lt>packet limitE<gt> ]>
|
||||
S<[ B<-p>|B<--no-promiscuous-mode> ]>
|
||||
S<[ B<--ifdescr> E<lt>descriptionE<gt> ]>
|
||||
S<[ B<--ifname> E<lt>nameE<gt> ]>
|
||||
S<[ B<-P> ]>
|
||||
S<[ B<-q> ]>
|
||||
S<[ B<-s>|B<--snapshot-length> E<lt>capture snaplenE<gt> ]>
|
||||
|
@ -248,6 +250,16 @@ endianness as the capturing host.
|
|||
This option can occur multiple times. When capturing from multiple
|
||||
interfaces, the capture file will be saved in pcapng format.
|
||||
|
||||
=item --ifdescr> E<lt>descriptionE<gt>
|
||||
|
||||
Use I<description> as the description in the capture file for the
|
||||
interface or pipe specified before it with B<-i>.
|
||||
|
||||
=item --ifname> E<lt>nameE<gt>
|
||||
|
||||
Use I<name> as the name in the capture file for the the interface or
|
||||
pipe specified before it with B<-i>.
|
||||
|
||||
=item -I|--monitor-mode
|
||||
|
||||
Put the interface in "monitor mode"; this is supported only on IEEE
|
||||
|
|
55
dumpcap.c
55
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 {
|
||||
|
|
Loading…
Reference in New Issue