dect
/
libpcap
Archived
13
0
Fork 0

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.
This commit is contained in:
Guy Harris 2010-11-14 13:48:19 -08:00
parent ade794238b
commit 77ed5cdd1f
1 changed files with 34 additions and 42 deletions

View File

@ -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;
}
/*