summaryrefslogtreecommitdiff
path: root/dumpcap.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2012-11-19 20:07:27 +0000
committerAnders Broman <anders.broman@ericsson.com>2012-11-19 20:07:27 +0000
commit28474fe8eff76493ad2b9664b8987fd1c4d52830 (patch)
treee3c70a725d3ce942814125ca2002d92d18821dec /dumpcap.c
parent64c46ea482c28242eaa2b6be6738b5334baae49a (diff)
downloadwireshark-28474fe8eff76493ad2b9664b8987fd1c4d52830.tar.gz
From Mike Garratt:
Friendly Names for interfaces on Windows Notes on the changes the patch covers: * if_info_t struct: addition of friendly_name * Dumpcap Interface list format changes: + Win32: "dumpcap -D" shows friendly_name in place of descript if known + All: machine interface "dumpcap -D -Z none" includes friendly_name in the list in addition to the existing parameters * interface_options struct: addition of console_display_name + When an interface name is displayed in a console, it will typically be the console_display_name (instead of name). + console_display_name is used as the basis of the autogenerated temp filenames + console_display_name is typically set to the friendly_name if known, otherwise it is set to the interface name * Enhancements to capture_opts_add_iface_opt() (the function which process -i options). + Can now specify the interface using its name and friendly_name + Interface name matching is case insenstive + Name matching first attempts exact matching, then falls back to prefix matching (e.g. dumpcap -i local) + Validates interface names, instead of blindly sending them off to winpcap/libpcap + Interface specification by number is still supported. * capture_opts_trim_iface() has been refactored: + Instead of repeating a decent chunk of the cost in capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the interface. * introduction of capture_win_ifnames.[ch] (windows only code) + Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a windows version independant function to convert an interface guid into its friendly name. Uses published api functions on windows vista and higher, but falls back to unpublished API functions on older windows releases. + void get_windows_interface_friendlyname(/* IN */ char *interface_devicename, /* OUT */char **interface_friendlyname); - extracts the GUID from the interface_devicename, then uses GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution * Auto temp filename generation: + Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format + Basis temp filename format on console_display_name + Win32: if console_display_name is a windows interface guid, extracts numbers from GUID here (instead of in interface option processing) GUI CHANGES: * Dialog that displays when you click the "Manage Interfaces" button (within Capture Options dialog) has been renamed from "Add new interfaces" to "Interface Management" * ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to interface_management_w * Win32: Local Interfaces tab on Interface Management dialog, shows includes friendly name as far left column * Interface Management dialog defaults to larger size on win32 - so it fits without resizing local interfaces tab * Interface Management dialog now saves preferences when you click the apply button (local hidden interfaces was not persisting across restarts) * Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces -> Details): + "Friendly Name" renamed to "NDIS Friendly Name" + Added "OS Friendly Name" to the top of the list * Win32: The "Capture Interfaces" dialog now shows the friendly name instead of device guid * Welcome screen: + The height of the interface list scrollbox dynamically adjusts & updates to the number visible interfaces. Up to 10 interfaces can be listed without a scroll bar, the minimum height is for 2 interfaces. + Win32: now shows just the Friendly Name if known - in place of "Interfacename_Guid:(Description)" svn path=/trunk/; revision=46083
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 3a154fcec0..1a25654c06 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1275,6 +1275,11 @@ get_if_capabilities(const char *devname, gboolean monitor_mode
}
#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
+/*
+ * Output a machine readable list of the interfaces
+ * This list is retrieved by the sync_interface_list_open() function
+ * The actual output of this function can be viewed with the command "dumpcap -D -Z none"
+ */
static void
print_machine_readable_interfaces(GList *if_list)
{
@@ -1306,6 +1311,11 @@ print_machine_readable_interfaces(GList *if_list)
printf("\t%s\t", if_info->description);
else
printf("\t\t");
+
+ if (if_info->friendly_name != NULL)
+ printf("%s\t", if_info->friendly_name);
+ else
+ printf("\t");
for(addr = g_slist_nth(if_info->addrs, 0); addr != NULL;
addr = g_slist_next(addr)) {
@@ -3211,15 +3221,27 @@ 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 {
gchar *basename;
+ basename = g_path_get_basename(g_array_index(global_capture_opts.ifaces, interface_options, 0).console_display_name);
#ifdef _WIN32
- GString *iface;
- iface = isolate_uuid(g_array_index(global_capture_opts.ifaces, interface_options, 0).name);
- basename = g_path_get_basename(iface->str);
- g_string_free(iface, TRUE);
-#else
- basename = g_path_get_basename(g_array_index(global_capture_opts.ifaces, interface_options, 0).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 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);
+ }
#endif
- prefix = g_strconcat("wireshark_", basename, NULL);
+ /* generate the temp file name prefix...
+ * It would be nice if we could specify a pcapng/pcap filename suffix,
+ * create_tempfile() however currently uses mkstemp() which doesn't allow this - one day perhaps*/
+ if (capture_opts->use_pcapng) {
+ prefix = g_strconcat("wireshark_pcapng_", basename, NULL);
+ }else{
+ prefix = g_strconcat("wireshark_pcap_", basename, NULL);
+ }
g_free(basename);
}
*save_file_fd = create_tempfile(&tmpname, prefix);
@@ -3815,7 +3837,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
report_capture_error(errmsg, please_report);
}
}
- report_packet_drops(received, dropped, interface_opts.name);
+ report_packet_drops(received, dropped, interface_opts.console_display_name);
}
/* close the input file (pcap or capture pipe) */
@@ -4657,7 +4679,6 @@ main(int argc, char *argv[])
}
/* Let the user know what interfaces were chosen. */
- /* get_interface_descriptive_name() is not available! */
if (capture_child) {
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_options interface_opts;
@@ -4669,10 +4690,11 @@ main(int argc, char *argv[])
} else {
str = g_string_new("");
#ifdef _WIN32
- if (global_capture_opts.ifaces->len < 2) {
+ if (global_capture_opts.ifaces->len < 2)
#else
- if (global_capture_opts.ifaces->len < 4) {
+ if (global_capture_opts.ifaces->len < 4)
#endif
+ {
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_options interface_opts;
@@ -4685,8 +4707,8 @@ main(int argc, char *argv[])
if (j == global_capture_opts.ifaces->len - 1) {
g_string_append_printf(str, "and ");
}
- }
- g_string_append_printf(str, "%s", interface_opts.name);
+ }
+ g_string_append_printf(str, "'%s'", interface_opts.console_display_name);
}
} else {
g_string_append_printf(str, "%u interfaces", global_capture_opts.ifaces->len);
@@ -4744,6 +4766,9 @@ main(int argc, char *argv[])
/* We're supposed to do a capture. Process the ring buffer arguments. */
capture_opts_trim_ring_num_files(&global_capture_opts);
+ /* flush stderr prior to starting the main capture loop */
+ fflush(stderr);
+
/* Now start the capture. */
if(capture_loop_start(&global_capture_opts, &stats_known, &stats) == TRUE) {
@@ -4956,7 +4981,7 @@ report_packet_drops(guint32 received, guint32 drops, gchar *name)
pipe_write_block(2, SP_DROPS, tmp);
} else {
fprintf(stderr,
- "Packets received/dropped on interface %s: %u/%u (%.1f%%)\n",
+ "Packets received/dropped on interface '%s': %u/%u (%.1f%%)\n",
name, received, drops,
received ? 100.0 * received / (received + drops) : 0.0);
/* stderr could be line buffered */