diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-03-07 14:08:53 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-03-07 22:09:30 +0000 |
commit | 1ac358c99ddcddc29d4e7c9fee1591e71f4a6a6e (patch) | |
tree | 1969c7ba8506e2f1446d7178c2f9af6278e5b76b | |
parent | 25015a00a3d1f877f053940b59d5b96c1b80c744 (diff) |
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 <guy@alum.mit.edu>
-rw-r--r-- | caputils/capture-pcap-util.c | 18 |
1 files changed, 14 insertions, 4 deletions
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; } |