summaryrefslogtreecommitdiff
path: root/caputils
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-01-06 22:07:14 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-07 06:07:42 +0000
commitb400b8c50eae4ccae33180035f0942a163a18a5e (patch)
treea65e0a5bbeb0f6956e9e486be5b1d343916b55c4 /caputils
parent51a99ca2b393d5709274822b92c97aebc7934fd0 (diff)
downloadwireshark-b400b8c50eae4ccae33180035f0942a163a18a5e.tar.gz
pcap_list_datalinks() failing is an error.
Return an error string if that happens. If it doesn't fail, it will return a value >= 1; it will never return 0, so don't check for that. Change-Id: I6d7ee2683c1ceae73e9d9d61c0a6e6d30b2c4400 Reviewed-on: https://code.wireshark.org/review/13100 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'caputils')
-rw-r--r--caputils/capture-pcap-util.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c
index f7757ea8a5..c014f83872 100644
--- a/caputils/capture-pcap-util.c
+++ b/caputils/capture-pcap-util.c
@@ -879,10 +879,19 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
deflt = get_pcap_datalink(pch, interface_opts->name);
#ifdef HAVE_PCAP_LIST_DATALINKS
nlt = pcap_list_datalinks(pch, &linktypes);
- if (nlt == 0 || linktypes == NULL) {
+ if (nlt < 0) {
+ /*
+ * This either returns a negative number for an error
+ * or returns a number > 0 and sets linktypes.
+ */
pcap_close(pch);
- if (err_str != NULL)
- *err_str = NULL; /* an empty list doesn't mean an error */
+ if (err_str != NULL) {
+ 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));
+ }
return NULL;
}
data_link_types = NULL;
@@ -932,9 +941,9 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts,
data_link_types = g_list_append(data_link_types, data_link_info);
#endif /* HAVE_PCAP_LIST_DATALINKS */
- if (err_str != NULL)
- *err_str = NULL;
- return data_link_types;
+ if (err_str != NULL)
+ *err_str = NULL;
+ return data_link_types;
}
#ifdef HAVE_PCAP_CREATE
@@ -1057,8 +1066,6 @@ get_if_capabilities_pcap_create(interface_options *interface_opts,
err_str);
if (caps->data_link_types == NULL) {
pcap_close(pch);
- if (err_str != NULL)
- *err_str = NULL; /* an empty list doesn't mean an error */
g_free(caps);
return NULL;
}
@@ -1177,8 +1184,6 @@ get_if_capabilities_pcap_open_live(interface_options *interface_opts,
err_str);
if (caps->data_link_types == NULL) {
pcap_close(pch);
- if (err_str != NULL)
- *err_str = NULL; /* an empty list doesn't mean an error */
g_free(caps);
return NULL;
}