/[pkg-src]/trunk/libpcap/patches/libpcap-1.1.1-Libnl-2.x-returns-its-own-error-codes-not-errnos-handle.patch |
Contents of /trunk/libpcap/patches/libpcap-1.1.1-Libnl-2.x-returns-its-own-error-codes-not-errnos-handle.patch
Parent Directory | Revision Log
Revision 1458 -
(show annotations)
(download)
Mon Aug 1 08:47:25 2011 UTC (13 years, 2 months ago) by niro
File size: 4696 byte(s)
Mon Aug 1 08:47:25 2011 UTC (13 years, 2 months ago) by niro
File size: 4696 byte(s)
-added buildfixes against newer libnl
1 | From 9545ff8e2670db02652f9cf781aafdd6bac58ac4 Mon Sep 17 00:00:00 2001 |
2 | From: Guy Harris <guy@alum.mit.edu> |
3 | Date: Sun, 14 Nov 2010 13:48:19 -0800 |
4 | Subject: [PATCH] Libnl 2.x returns its own error codes, not errnos; handle that. |
5 | |
6 | While we're at it, don't special-case ENFILE for "delete monitor device" |
7 | operations; that's not like "add monitor device", where we want to drive |
8 | on if a device with that name already exists. |
9 | --- |
10 | pcap-linux.c | 76 ++++++++++++++++++++++++++-------------------------------- |
11 | 1 files changed, 34 insertions(+), 42 deletions(-) |
12 | |
13 | diff --git a/pcap-linux.c b/pcap-linux.c |
14 | index deabbc4..5d291e9 100644 |
15 | --- a/pcap-linux.c |
16 | +++ b/pcap-linux.c |
17 | @@ -527,7 +527,9 @@ get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path, |
18 | return 1; |
19 | } |
20 | |
21 | -#ifndef HAVE_LIBNL_2_x |
22 | +#ifdef HAVE_LIBNL_2_x |
23 | +#define get_nl_errmsg nl_geterror |
24 | +#else |
25 | /* libnl 2.x compatibility code */ |
26 | |
27 | #define nl_sock nl_handle |
28 | @@ -544,6 +546,8 @@ nl_socket_free(struct nl_handle *h) |
29 | nl_handle_destroy(h); |
30 | } |
31 | |
32 | +#define get_nl_errmsg strerror |
33 | + |
34 | static inline int |
35 | __genl_ctrl_alloc_cache(struct nl_handle *h, struct nl_cache **cache) |
36 | { |
37 | @@ -584,7 +588,7 @@ nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device) |
38 | if (err < 0) { |
39 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
40 | "%s: failed to allocate generic netlink cache: %s", |
41 | - device, strerror(-err)); |
42 | + device, get_nl_errmsg(-err)); |
43 | goto out_handle_destroy; |
44 | } |
45 | |
46 | @@ -639,10 +643,17 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, |
47 | |
48 | err = nl_send_auto_complete(state->nl_sock, msg); |
49 | if (err < 0) { |
50 | +#ifdef HAVE_LIBNL_2_x |
51 | + if (err == -NLE_FAILURE) { |
52 | +#else |
53 | if (err == -ENFILE) { |
54 | +#endif |
55 | /* |
56 | * Device not available; our caller should just |
57 | - * keep trying. |
58 | + * keep trying. (libnl 2.x maps ENFILE to |
59 | + * NLE_FAILURE; it can also map other errors |
60 | + * to that, but there's not much we can do |
61 | + * about that.) |
62 | */ |
63 | nlmsg_free(msg); |
64 | return 0; |
65 | @@ -653,17 +664,24 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, |
66 | */ |
67 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
68 | "%s: nl_send_auto_complete failed adding %s interface: %s", |
69 | - device, mondevice, strerror(-err)); |
70 | + device, mondevice, get_nl_errmsg(-err)); |
71 | nlmsg_free(msg); |
72 | return PCAP_ERROR; |
73 | } |
74 | } |
75 | err = nl_wait_for_ack(state->nl_sock); |
76 | if (err < 0) { |
77 | +#ifdef HAVE_LIBNL_2_x |
78 | + if (err == -NLE_FAILURE) { |
79 | +#else |
80 | if (err == -ENFILE) { |
81 | +#endif |
82 | /* |
83 | * Device not available; our caller should just |
84 | - * keep trying. |
85 | + * keep trying. (libnl 2.x maps ENFILE to |
86 | + * NLE_FAILURE; it can also map other errors |
87 | + * to that, but there's not much we can do |
88 | + * about that.) |
89 | */ |
90 | nlmsg_free(msg); |
91 | return 0; |
92 | @@ -674,7 +692,7 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, |
93 | */ |
94 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
95 | "%s: nl_wait_for_ack failed adding %s interface: %s", |
96 | - device, mondevice, strerror(-err)); |
97 | + device, mondevice, get_nl_errmsg(-err)); |
98 | nlmsg_free(msg); |
99 | return PCAP_ERROR; |
100 | } |
101 | @@ -719,45 +737,19 @@ del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, |
102 | |
103 | err = nl_send_auto_complete(state->nl_sock, msg); |
104 | if (err < 0) { |
105 | - if (err == -ENFILE) { |
106 | - /* |
107 | - * Device not available; our caller should just |
108 | - * keep trying. |
109 | - */ |
110 | - nlmsg_free(msg); |
111 | - return 0; |
112 | - } else { |
113 | - /* |
114 | - * Real failure, not just "that device is not |
115 | - * available. |
116 | - */ |
117 | - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
118 | - "%s: nl_send_auto_complete failed deleting %s interface: %s", |
119 | - device, mondevice, strerror(-err)); |
120 | - nlmsg_free(msg); |
121 | - return PCAP_ERROR; |
122 | - } |
123 | + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
124 | + "%s: nl_send_auto_complete failed deleting %s interface: %s", |
125 | + device, mondevice, get_nl_errmsg(-err)); |
126 | + nlmsg_free(msg); |
127 | + return PCAP_ERROR; |
128 | } |
129 | err = nl_wait_for_ack(state->nl_sock); |
130 | if (err < 0) { |
131 | - if (err == -ENFILE) { |
132 | - /* |
133 | - * Device not available; our caller should just |
134 | - * keep trying. |
135 | - */ |
136 | - nlmsg_free(msg); |
137 | - return 0; |
138 | - } else { |
139 | - /* |
140 | - * Real failure, not just "that device is not |
141 | - * available. |
142 | - */ |
143 | - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
144 | - "%s: nl_wait_for_ack failed adding %s interface: %s", |
145 | - device, mondevice, strerror(-err)); |
146 | - nlmsg_free(msg); |
147 | - return PCAP_ERROR; |
148 | - } |
149 | + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, |
150 | + "%s: nl_wait_for_ack failed adding %s interface: %s", |
151 | + device, mondevice, get_nl_errmsg(-err)); |
152 | + nlmsg_free(msg); |
153 | + return PCAP_ERROR; |
154 | } |
155 | |
156 | /* |
157 | -- |
158 | 1.7.3.5 |
159 |