diff options
Diffstat (limited to 'core/libpcap/Libnl-2.x-returns-its-own-error-codes-not-errnos-han.patch')
-rw-r--r-- | core/libpcap/Libnl-2.x-returns-its-own-error-codes-not-errnos-han.patch | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/core/libpcap/Libnl-2.x-returns-its-own-error-codes-not-errnos-han.patch b/core/libpcap/Libnl-2.x-returns-its-own-error-codes-not-errnos-han.patch new file mode 100644 index 000000000..219494200 --- /dev/null +++ b/core/libpcap/Libnl-2.x-returns-its-own-error-codes-not-errnos-han.patch @@ -0,0 +1,159 @@ +From 9545ff8e2670db02652f9cf781aafdd6bac58ac4 Mon Sep 17 00:00:00 2001 +From: Guy Harris <guy@alum.mit.edu> +Date: Sun, 14 Nov 2010 13:48:19 -0800 +Subject: [PATCH] Libnl 2.x returns its own error codes, not errnos; handle that. + +While we're at it, don't special-case ENFILE for "delete monitor device" +operations; that's not like "add monitor device", where we want to drive +on if a device with that name already exists. +--- + pcap-linux.c | 76 ++++++++++++++++++++++++++-------------------------------- + 1 files changed, 34 insertions(+), 42 deletions(-) + +diff --git a/pcap-linux.c b/pcap-linux.c +index deabbc4..5d291e9 100644 +--- a/pcap-linux.c ++++ b/pcap-linux.c +@@ -527,7 +527,9 @@ get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path, + return 1; + } + +-#ifndef HAVE_LIBNL_2_x ++#ifdef HAVE_LIBNL_2_x ++#define get_nl_errmsg nl_geterror ++#else + /* libnl 2.x compatibility code */ + + #define nl_sock nl_handle +@@ -544,6 +546,8 @@ nl_socket_free(struct nl_handle *h) + nl_handle_destroy(h); + } + ++#define get_nl_errmsg strerror ++ + static inline int + __genl_ctrl_alloc_cache(struct nl_handle *h, struct nl_cache **cache) + { +@@ -584,7 +588,7 @@ nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device) + if (err < 0) { + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "%s: failed to allocate generic netlink cache: %s", +- device, strerror(-err)); ++ device, get_nl_errmsg(-err)); + goto out_handle_destroy; + } + +@@ -639,10 +643,17 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, + + err = nl_send_auto_complete(state->nl_sock, msg); + if (err < 0) { ++#ifdef HAVE_LIBNL_2_x ++ if (err == -NLE_FAILURE) { ++#else + if (err == -ENFILE) { ++#endif + /* + * Device not available; our caller should just +- * keep trying. ++ * keep trying. (libnl 2.x maps ENFILE to ++ * NLE_FAILURE; it can also map other errors ++ * to that, but there's not much we can do ++ * about that.) + */ + nlmsg_free(msg); + return 0; +@@ -653,17 +664,24 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, + */ + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "%s: nl_send_auto_complete failed adding %s interface: %s", +- device, mondevice, strerror(-err)); ++ device, mondevice, get_nl_errmsg(-err)); + nlmsg_free(msg); + return PCAP_ERROR; + } + } + err = nl_wait_for_ack(state->nl_sock); + if (err < 0) { ++#ifdef HAVE_LIBNL_2_x ++ if (err == -NLE_FAILURE) { ++#else + if (err == -ENFILE) { ++#endif + /* + * Device not available; our caller should just +- * keep trying. ++ * keep trying. (libnl 2.x maps ENFILE to ++ * NLE_FAILURE; it can also map other errors ++ * to that, but there's not much we can do ++ * about that.) + */ + nlmsg_free(msg); + return 0; +@@ -674,7 +692,7 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, + */ + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "%s: nl_wait_for_ack failed adding %s interface: %s", +- device, mondevice, strerror(-err)); ++ device, mondevice, get_nl_errmsg(-err)); + nlmsg_free(msg); + return PCAP_ERROR; + } +@@ -719,45 +737,19 @@ del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, + + err = nl_send_auto_complete(state->nl_sock, msg); + if (err < 0) { +- if (err == -ENFILE) { +- /* +- * Device not available; our caller should just +- * keep trying. +- */ +- nlmsg_free(msg); +- return 0; +- } else { +- /* +- * Real failure, not just "that device is not +- * available. +- */ +- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, +- "%s: nl_send_auto_complete failed deleting %s interface: %s", +- device, mondevice, strerror(-err)); +- nlmsg_free(msg); +- return PCAP_ERROR; +- } ++ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, ++ "%s: nl_send_auto_complete failed deleting %s interface: %s", ++ device, mondevice, get_nl_errmsg(-err)); ++ nlmsg_free(msg); ++ return PCAP_ERROR; + } + err = nl_wait_for_ack(state->nl_sock); + if (err < 0) { +- if (err == -ENFILE) { +- /* +- * Device not available; our caller should just +- * keep trying. +- */ +- nlmsg_free(msg); +- return 0; +- } else { +- /* +- * Real failure, not just "that device is not +- * available. +- */ +- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, +- "%s: nl_wait_for_ack failed adding %s interface: %s", +- device, mondevice, strerror(-err)); +- nlmsg_free(msg); +- return PCAP_ERROR; +- } ++ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, ++ "%s: nl_wait_for_ack failed adding %s interface: %s", ++ device, mondevice, get_nl_errmsg(-err)); ++ nlmsg_free(msg); ++ return PCAP_ERROR; + } + + /* +-- +1.7.3.5 + |