aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-03-14 19:27:08 -0700
committerGuy Harris <gharris@sonic.net>2022-03-14 19:27:08 -0700
commit431f563011515a2d343ebc9a45873df600bd1ef0 (patch)
treea6232383a9ebb227b661a5291a3d66adf70b6279 /pcap-linux.c
parentb9428e2c4bcb4d8509a65b6fc9a4cb2ab23f3d1e (diff)
Make sure some error message is provided for PCAP_ERROR_NO_SUCH_DEVICE.
If there's no more information to provide, provide an empty string.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index 49fe1026..5c9ac9a2 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -977,6 +977,11 @@ pcap_activate_linux(pcap_t *handle)
* we'll be copying it, that won't fit.
*/
if (strlen(device) >= sizeof(ifr.ifr_name)) {
+ /*
+ * There's nothing more to say, so clear the error
+ * message.
+ */
+ handle->errbuf[0] = '\0';
status = PCAP_ERROR_NO_SUCH_DEVICE;
goto fail;
}
@@ -4567,12 +4572,18 @@ iface_bind(int fd, int ifindex, char *ebuf, int protocol)
*/
return PCAP_ERROR_IFACE_NOT_UP;
}
- if (errno == ENODEV)
+ if (errno == ENODEV) {
+ /*
+ * There's nothing more to say, so clear the
+ * error message.
+ */
+ ebuf[0] = '\0';
ret = PCAP_ERROR_NO_SUCH_DEVICE;
- else
+ } else {
ret = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
- errno, "bind");
+ pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
+ errno, "bind");
+ }
return ret;
}
@@ -5205,12 +5216,17 @@ iface_get_arptype(int fd, const char *device, char *ebuf)
if (errno == ENODEV) {
/*
* No such device.
+ *
+ * There's nothing more to say, so clear
+ * the error message.
*/
ret = PCAP_ERROR_NO_SUCH_DEVICE;
- } else
+ ebuf[0] = '\0';
+ } else {
ret = PCAP_ERROR;
- pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
- errno, "SIOCGIFHWADDR");
+ pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
+ errno, "SIOCGIFHWADDR");
+ }
return ret;
}