diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-08-12 20:32:01 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-08-13 04:37:00 +0000 |
commit | 149e74b70d207228802a463214271c9e537476c9 (patch) | |
tree | 1deea5228d89492b4950735b99159bde6eba90b2 /dumpcap.c | |
parent | d48262753eecd46a5ba0fc13bbc8c336fa16c207 (diff) |
Put the interface descrptions into the IDB when capturing to pcapng.
capture_opts_add_iface_opt(), when called in a program acting as a
capture child, will fetch the description for the interface, and will
also generate a "display name" for the interface.
In the process, we clean up capture_opts_add_iface_opt() a bit,
combining duplicate code.
We rename console_display_name to just display_name, as it may also be
used in the title bar of Wireshark when capturing.
Change-Id: Ifd18955bb3cb41df4c0ed4362d4854068c825b96
Reviewed-on: https://code.wireshark.org/review/29117
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'dumpcap.c')
-rw-r--r-- | dumpcap.c | 64 |
1 files changed, 49 insertions, 15 deletions
@@ -3310,23 +3310,57 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd, prefix = g_strdup_printf("wireshark_%d_interfaces", global_capture_opts.ifaces->len); } else { /* - * One interface; use its name to generate the temporary file - * name prefix. + * One interface; use its description, if it has one, to generate + * the temporary file name, otherwise use its name. */ gchar *basename; - basename = g_path_get_basename((&g_array_index(global_capture_opts.ifaces, interface_options, 0))->console_display_name); + const interface_options *interface_opts; + + interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, 0); + + /* + * Do we have a description? + */ + if (interface_opts->descr) { + /* + * Yes - use it. + * + * Strip off any stuff we shouldn't use in the file name, + * by getting the last component of what would be a file + * name. + */ + basename = g_path_get_basename(interface_opts->descr); + } else { + /* + * No - use the name. + * + * Strip off any stuff we shouldn't use in the file name, + * by getting the last component of what would be a file + * name. + */ + basename = g_path_get_basename(interface_opts->name); #ifdef _WIN32 - /* use the generic portion of the interface guid to form the basis of the filename */ - if (strncmp("NPF_{", basename, 5)==0) - { - /* we have a windows guid style device name, extract the guid digits as the basis of the filename */ - GString *iface; - iface = isolate_uuid(basename); - g_free(basename); - basename = g_strdup(iface->str); - g_string_free(iface, TRUE); - } + /* + * This is Windows, where we might have an ugly GUID-based + * interface name. + * + * If it's an ugly GUID-based name, use the generic portion + * of the interface GUID to form the basis of the filename. + */ + if (strncmp("NPF_{", basename, 5) == 0) { + /* + * We have a GUID-based name; extract the GUID digits + * as the basis of the filename. + */ + GString *iface; + iface = isolate_uuid(basename); + g_free(basename); + basename = g_strdup(iface->str); + g_string_free(iface, TRUE); + } #endif + } + /* generate the temp file name prefix */ prefix = g_strconcat("wireshark_", basename, NULL); g_free(basename); } @@ -3990,7 +4024,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct report_capture_error(errmsg, please_report); } } - report_packet_drops(received, pcap_dropped, pcap_src->dropped, pcap_src->flushed, stats->ps_ifdrop, interface_opts->console_display_name); + report_packet_drops(received, pcap_dropped, pcap_src->dropped, pcap_src->flushed, stats->ps_ifdrop, interface_opts->display_name); } /* close the input file (pcap or capture pipe) */ @@ -5141,7 +5175,7 @@ main(int argc, char *argv[]) g_string_append_printf(str, "and "); } } - g_string_append_printf(str, "'%s'", interface_opts->console_display_name); + g_string_append_printf(str, "'%s'", interface_opts->display_name); } } else { g_string_append_printf(str, "%u interfaces", global_capture_opts.ifaces->len); |