From 1ac358c99ddcddc29d4e7c9fee1591e71f4a6a6e Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 7 Mar 2017 14:08:53 -0800 Subject: Don't close the pcap_t in get_data_link_types(). 1) Its caller closes it, and closing a closed pcap_t can cause Bad Things to happen. 2) We're trying to get an error string from it after we're closing it, which won't work well, either. While we're at it, don't use pcap_statustostr() if we don't have it (we have it iff we have pcap_create()). Change-Id: Ieded1e3ae78aea4e0970cf582e780c2846fe9dd5 Reviewed-on: https://code.wireshark.org/review/20443 Reviewed-by: Guy Harris --- caputils/capture-pcap-util.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'caputils') diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c index d30d85609b..1499607692 100644 --- a/caputils/capture-pcap-util.c +++ b/caputils/capture-pcap-util.c @@ -885,16 +885,26 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts, nlt = pcap_list_datalinks(pch, &linktypes); if (nlt < 0) { /* - * This either returns a negative number for an error - * or returns a number > 0 and sets linktypes. + * A negative return is an error. */ - pcap_close(pch); if (err_str != NULL) { - if (nlt == -1) +#ifdef HAVE_PCAP_CREATE + /* + * If we have pcap_create(), we have + * pcap_statustostr(), and we can get back errors + * other than PCAP_ERROR (-1), such as + * PCAP_ERROR_NOT_ACTIVATED. and we should report + * them properly. + */ + if (nlt == PCAP_ERROR) *err_str = g_strdup_printf("pcap_list_datalinks() failed: %s", pcap_geterr(pch)); else *err_str = g_strdup(pcap_statustostr(nlt)); +#else /* HAVE_PCAP_CREATE */ + *err_str = g_strdup_printf("pcap_list_datalinks() failed: %s", + pcap_geterr(pch)); +#endif /* HAVE_PCAP_CREATE */ } return NULL; } -- cgit v1.2.1