From b09514f3b3edfc96bceff2c4c11e5ff0a55e4709 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 8 Feb 2021 22:33:18 -0800 Subject: [PATCH] dumpcap: provide more information to put into an Npcap bug. Turn the sequence of details to supply in an Npcap bug into a list, with one element per line, and provide the interface name, Windows version string, and Npcap version string. Put that into a common routine. --- dumpcap.c | 80 ++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/dumpcap.c b/dumpcap.c index 988ceceed2..27ee5662e6 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -3836,6 +3836,40 @@ capture_loop_dequeue_packet(void) { return FALSE; } +/* + * Note: this code will never be run on any OS other than Windows. + */ +static char * +please_report_npcap_bug(char *adapter_name, char *cap_err_str) +{ + GString *windows_info_str = g_string_new(""); + GString *pcap_info_str = g_string_new(""); + char *msg; + + get_os_version_info(windows_info_str); + get_runtime_caplibs_version(pcap_info_str); + msg = g_strdup_printf("If you have not removed that adapter, this " + "may be a bug in Npcap: please report it " + "as an issue at https://github.com/nmap/npcap/issues\n\n" + "Give all details, such as:\n\n" + "The name of the adapter on which the error occurred (\"%s\");\n" + "The error message \"%s\";\n" + "The full version of Windows on which this occurred (\"%s\");\n" + "The version of Npcap with which this occurred (\"%s\");\n" + "Any indication of whether the machine went to sleep " + "during the capture;\n" + "Any indication of whether any other interfaces " + "were added to or removed from the machine while " + "the capture was taking place.", + adapter_name, + cap_err_str, + windows_info_str->str, + pcap_info_str->str); + g_string_free(windows_info_str, TRUE); + g_string_free(pcap_info_str, TRUE); + return msg; +} + /* Do the low-level work of a capture. Returns TRUE if it succeeds, FALSE otherwise. */ static gboolean @@ -4200,27 +4234,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct "is no longer attached; the " "capture has stopped.", interface_opts->display_name); - secondary_msg = g_strdup_printf("If you have not removed that " - "adapter, this may be a bug " - "in Npcap: please report it " - "as an issue at https://github.com/nmap/npcap/issues\n\n" - "Give all details, such as " - "the name of the adapter on " - "which the error occurred, " - "the error message \"%s\", " - "the full version of Windows " - "on which this occurred, " - "the version of Npcap with " - "which this occurred, any " - "indication of whether the " - "machine went to sleep " - "during the capture, " - "and any indication of " - "whether any other interfaces " - "were added to or removed " - "from the machine while the " - "capture was taking place.", - cap_err_str); + secondary_msg = please_report_npcap_bug(interface_opts->display_name, + cap_err_str); } else if (g_str_has_prefix(cap_err_str, "PacketReceivePacket error:") && g_str_has_suffix(cap_err_str, "(1617)")) { /* @@ -4244,27 +4259,8 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct "is no longer attached; the " "capture has stopped.", interface_opts->display_name); - secondary_msg = g_strdup_printf("If you have not removed that " - "adapter, this may be a bug " - "in Npcap: please report it " - "as an issue at https://github.com/nmap/npcap/issues\n\n" - "Give all details, such as " - "the name of the adapter on " - "which the error occurred, " - "the error message \"%s\", " - "the full version of Windows " - "on which this occurred, " - "the version of Npcap with " - "which this occurred, any " - "indication of whether the " - "machine went to sleep " - "during the capture, " - "and any indication of " - "whether any other interfaces " - "were added to or removed " - "from the machine while the " - "capture was taking place.", - "(ERROR_DEVICE_REMOVED/STATUS_DEVICE_REMOVED)"); + secondary_msg = please_report_npcap_bug(interface_opts->display_name, + "The interface disappeared (error code ERROR_DEVICE_REMOVED/STATUS_DEVICE_REMOVED)"); } else if (strcmp(cap_err_str, "The other host terminated the connection") == 0) { primary_msg = g_strdup(cap_err_str); secondary_msg = g_strdup("This may be a problem with the "