/[pkg-src]/trunk/libpcap/patches/libpcap-1.1.1-Add-support-for-libnl-2.x-adapted-from-a-newer-version.patch |
Annotation of /trunk/libpcap/patches/libpcap-1.1.1-Add-support-for-libnl-2.x-adapted-from-a-newer-version.patch
Parent Directory | Revision Log
Revision 1458 -
(hide annotations)
(download)
Mon Aug 1 08:47:25 2011 UTC (12 years, 10 months ago) by niro
File size: 9036 byte(s)
Mon Aug 1 08:47:25 2011 UTC (12 years, 10 months ago) by niro
File size: 9036 byte(s)
-added buildfixes against newer libnl
1 | niro | 1458 | From bc937fc4ff6715e9bee939041fa02be0755d7d58 Mon Sep 17 00:00:00 2001 |
2 | From: Guy Harris <guy@alum.mit.edu> | ||
3 | Date: Sat, 13 Nov 2010 17:42:47 -0800 | ||
4 | Subject: [PATCH] Add support for libnl 2.x, adapted from a newer version of the iw command. | ||
5 | |||
6 | --- | ||
7 | config.h.in | 3 ++ | ||
8 | configure | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- | ||
9 | configure.in | 40 ++++++++++++++++++---- | ||
10 | pcap-linux.c | 58 ++++++++++++++++++++++++------- | ||
11 | 4 files changed, 184 insertions(+), 25 deletions(-) | ||
12 | |||
13 | diff --git a/config.h.in b/config.h.in | ||
14 | index f988e8f..3b9ce3c 100644 | ||
15 | --- a/config.h.in | ||
16 | +++ b/config.h.in | ||
17 | @@ -52,6 +52,9 @@ | ||
18 | /* if libnl exists */ | ||
19 | #undef HAVE_LIBNL | ||
20 | |||
21 | +/* if libnl exists and is version 2.x */ | ||
22 | +#undef HAVE_LIBNL_2_x | ||
23 | + | ||
24 | /* Define to 1 if you have the <limits.h> header file. */ | ||
25 | #undef HAVE_LIMITS_H | ||
26 | |||
27 | diff --git a/configure b/configure | ||
28 | index c99c1ab..7338dee 100755 | ||
29 | --- a/configure | ||
30 | +++ b/configure | ||
31 | @@ -7340,7 +7340,93 @@ fi | ||
32 | |||
33 | |||
34 | if test x$with_libnl != xno ; then | ||
35 | - { echo "$as_me:$LINENO: checking for nl_handle_alloc in -lnl" >&5 | ||
36 | + # | ||
37 | + # Try libnl 2.x first. | ||
38 | + # | ||
39 | + { echo "$as_me:$LINENO: checking for nl_socket_alloc in -lnl" >&5 | ||
40 | +echo $ECHO_N "checking for nl_socket_alloc in -lnl... $ECHO_C" >&6; } | ||
41 | +if test "${ac_cv_lib_nl_nl_socket_alloc+set}" = set; then | ||
42 | + echo $ECHO_N "(cached) $ECHO_C" >&6 | ||
43 | +else | ||
44 | + ac_check_lib_save_LIBS=$LIBS | ||
45 | +LIBS="-lnl $LIBS" | ||
46 | +cat >conftest.$ac_ext <<_ACEOF | ||
47 | +/* confdefs.h. */ | ||
48 | +_ACEOF | ||
49 | +cat confdefs.h >>conftest.$ac_ext | ||
50 | +cat >>conftest.$ac_ext <<_ACEOF | ||
51 | +/* end confdefs.h. */ | ||
52 | + | ||
53 | +/* Override any GCC internal prototype to avoid an error. | ||
54 | + Use char because int might match the return type of a GCC | ||
55 | + builtin and then its argument prototype would still apply. */ | ||
56 | +#ifdef __cplusplus | ||
57 | +extern "C" | ||
58 | +#endif | ||
59 | +char nl_socket_alloc (); | ||
60 | +int | ||
61 | +main () | ||
62 | +{ | ||
63 | +return nl_socket_alloc (); | ||
64 | + ; | ||
65 | + return 0; | ||
66 | +} | ||
67 | +_ACEOF | ||
68 | +rm -f conftest.$ac_objext conftest$ac_exeext | ||
69 | +if { (ac_try="$ac_link" | ||
70 | +case "(($ac_try" in | ||
71 | + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; | ||
72 | + *) ac_try_echo=$ac_try;; | ||
73 | +esac | ||
74 | +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 | ||
75 | + (eval "$ac_link") 2>conftest.er1 | ||
76 | + ac_status=$? | ||
77 | + grep -v '^ *+' conftest.er1 >conftest.err | ||
78 | + rm -f conftest.er1 | ||
79 | + cat conftest.err >&5 | ||
80 | + echo "$as_me:$LINENO: \$? = $ac_status" >&5 | ||
81 | + (exit $ac_status); } && { | ||
82 | + test -z "$ac_c_werror_flag" || | ||
83 | + test ! -s conftest.err | ||
84 | + } && test -s conftest$ac_exeext && | ||
85 | + $as_test_x conftest$ac_exeext; then | ||
86 | + ac_cv_lib_nl_nl_socket_alloc=yes | ||
87 | +else | ||
88 | + echo "$as_me: failed program was:" >&5 | ||
89 | +sed 's/^/| /' conftest.$ac_ext >&5 | ||
90 | + | ||
91 | + ac_cv_lib_nl_nl_socket_alloc=no | ||
92 | +fi | ||
93 | + | ||
94 | +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ | ||
95 | + conftest$ac_exeext conftest.$ac_ext | ||
96 | +LIBS=$ac_check_lib_save_LIBS | ||
97 | +fi | ||
98 | +{ echo "$as_me:$LINENO: result: $ac_cv_lib_nl_nl_socket_alloc" >&5 | ||
99 | +echo "${ECHO_T}$ac_cv_lib_nl_nl_socket_alloc" >&6; } | ||
100 | +if test $ac_cv_lib_nl_nl_socket_alloc = yes; then | ||
101 | + | ||
102 | + # | ||
103 | + # Yes, we have libnl 2.x. | ||
104 | + # | ||
105 | + LIBS="-lnl-genl -lnl $LIBS" | ||
106 | + | ||
107 | +cat >>confdefs.h <<\_ACEOF | ||
108 | +#define HAVE_LIBNL 1 | ||
109 | +_ACEOF | ||
110 | + | ||
111 | + | ||
112 | +cat >>confdefs.h <<\_ACEOF | ||
113 | +#define HAVE_LIBNL_2_x 1 | ||
114 | +_ACEOF | ||
115 | + | ||
116 | + | ||
117 | +else | ||
118 | + | ||
119 | + # | ||
120 | + # No, we don't; do we have libnl 1.x? | ||
121 | + # | ||
122 | + { echo "$as_me:$LINENO: checking for nl_handle_alloc in -lnl" >&5 | ||
123 | echo $ECHO_N "checking for nl_handle_alloc in -lnl... $ECHO_C" >&6; } | ||
124 | if test "${ac_cv_lib_nl_nl_handle_alloc+set}" = set; then | ||
125 | echo $ECHO_N "(cached) $ECHO_C" >&6 | ||
126 | @@ -7402,18 +7488,30 @@ fi | ||
127 | { echo "$as_me:$LINENO: result: $ac_cv_lib_nl_nl_handle_alloc" >&5 | ||
128 | echo "${ECHO_T}$ac_cv_lib_nl_nl_handle_alloc" >&6; } | ||
129 | if test $ac_cv_lib_nl_nl_handle_alloc = yes; then | ||
130 | - LIBS="-lnl $LIBS" | ||
131 | + | ||
132 | + # | ||
133 | + # Yes. | ||
134 | + # | ||
135 | + LIBS="-lnl $LIBS" | ||
136 | |||
137 | cat >>confdefs.h <<\_ACEOF | ||
138 | #define HAVE_LIBNL 1 | ||
139 | _ACEOF | ||
140 | |||
141 | + | ||
142 | else | ||
143 | - if test x$with_libnl = xyes ; then | ||
144 | - { { echo "$as_me:$LINENO: error: libnl support requested but libnl not found" >&5 | ||
145 | + | ||
146 | + # | ||
147 | + # No, we don't have libnl at all. | ||
148 | + # | ||
149 | + if test x$with_libnl = xyes ; then | ||
150 | + { { echo "$as_me:$LINENO: error: libnl support requested but libnl not found" >&5 | ||
151 | echo "$as_me: error: libnl support requested but libnl not found" >&2;} | ||
152 | { (exit 1); exit 1; }; } | ||
153 | - fi | ||
154 | + fi | ||
155 | + | ||
156 | +fi | ||
157 | + | ||
158 | |||
159 | fi | ||
160 | |||
161 | diff --git a/configure.in b/configure.in | ||
162 | index 16eadf9..ef801ed 100644 | ||
163 | --- a/configure.in | ||
164 | +++ b/configure.in | ||
165 | @@ -445,13 +445,39 @@ linux) | ||
166 | with_libnl=$withval,,) | ||
167 | |||
168 | if test x$with_libnl != xno ; then | ||
169 | - AC_CHECK_LIB(nl, nl_handle_alloc, | ||
170 | - LIBS="-lnl $LIBS" | ||
171 | - AC_DEFINE(HAVE_LIBNL,1,[if libnl exists]), | ||
172 | - if test x$with_libnl = xyes ; then | ||
173 | - AC_MSG_ERROR([libnl support requested but libnl not found]) | ||
174 | - fi | ||
175 | - ) | ||
176 | + # | ||
177 | + # Try libnl 2.x first. | ||
178 | + # | ||
179 | + AC_CHECK_LIB(nl, nl_socket_alloc, | ||
180 | + [ | ||
181 | + # | ||
182 | + # Yes, we have libnl 2.x. | ||
183 | + # | ||
184 | + LIBS="-lnl-genl -lnl $LIBS" | ||
185 | + AC_DEFINE(HAVE_LIBNL,1,[if libnl exists]) | ||
186 | + AC_DEFINE(HAVE_LIBNL_2_x,1,[if libnl exists and is version 2.x]) | ||
187 | + ], | ||
188 | + [ | ||
189 | + # | ||
190 | + # No, we don't; do we have libnl 1.x? | ||
191 | + # | ||
192 | + AC_CHECK_LIB(nl, nl_handle_alloc, | ||
193 | + [ | ||
194 | + # | ||
195 | + # Yes. | ||
196 | + # | ||
197 | + LIBS="-lnl $LIBS" | ||
198 | + AC_DEFINE(HAVE_LIBNL,1,[if libnl exists]) | ||
199 | + ], | ||
200 | + [ | ||
201 | + # | ||
202 | + # No, we don't have libnl at all. | ||
203 | + # | ||
204 | + if test x$with_libnl = xyes ; then | ||
205 | + AC_MSG_ERROR([libnl support requested but libnl not found]) | ||
206 | + fi | ||
207 | + ]) | ||
208 | + ]) | ||
209 | fi | ||
210 | |||
211 | AC_LBL_TPACKET_STATS | ||
212 | diff --git a/pcap-linux.c b/pcap-linux.c | ||
213 | index f8b3f10..deabbc4 100644 | ||
214 | --- a/pcap-linux.c | ||
215 | +++ b/pcap-linux.c | ||
216 | @@ -527,8 +527,37 @@ get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path, | ||
217 | return 1; | ||
218 | } | ||
219 | |||
220 | +#ifndef HAVE_LIBNL_2_x | ||
221 | +/* libnl 2.x compatibility code */ | ||
222 | + | ||
223 | +#define nl_sock nl_handle | ||
224 | + | ||
225 | +static inline struct nl_handle * | ||
226 | +nl_socket_alloc(void) | ||
227 | +{ | ||
228 | + return nl_handle_alloc(); | ||
229 | +} | ||
230 | + | ||
231 | +static inline void | ||
232 | +nl_socket_free(struct nl_handle *h) | ||
233 | +{ | ||
234 | + nl_handle_destroy(h); | ||
235 | +} | ||
236 | + | ||
237 | +static inline int | ||
238 | +__genl_ctrl_alloc_cache(struct nl_handle *h, struct nl_cache **cache) | ||
239 | +{ | ||
240 | + struct nl_cache *tmp = genl_ctrl_alloc_cache(h); | ||
241 | + if (!tmp) | ||
242 | + return -ENOMEM; | ||
243 | + *cache = tmp; | ||
244 | + return 0; | ||
245 | +} | ||
246 | +#define genl_ctrl_alloc_cache __genl_ctrl_alloc_cache | ||
247 | +#endif /* !HAVE_LIBNL_2_x */ | ||
248 | + | ||
249 | struct nl80211_state { | ||
250 | - struct nl_handle *nl_handle; | ||
251 | + struct nl_sock *nl_sock; | ||
252 | struct nl_cache *nl_cache; | ||
253 | struct genl_family *nl80211; | ||
254 | }; | ||
255 | @@ -536,23 +565,26 @@ struct nl80211_state { | ||
256 | static int | ||
257 | nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device) | ||
258 | { | ||
259 | - state->nl_handle = nl_handle_alloc(); | ||
260 | - if (!state->nl_handle) { | ||
261 | + int err; | ||
262 | + | ||
263 | + state->nl_sock = nl_socket_alloc(); | ||
264 | + if (!state->nl_sock) { | ||
265 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, | ||
266 | "%s: failed to allocate netlink handle", device); | ||
267 | return PCAP_ERROR; | ||
268 | } | ||
269 | |||
270 | - if (genl_connect(state->nl_handle)) { | ||
271 | + if (genl_connect(state->nl_sock)) { | ||
272 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, | ||
273 | "%s: failed to connect to generic netlink", device); | ||
274 | goto out_handle_destroy; | ||
275 | } | ||
276 | |||
277 | - state->nl_cache = genl_ctrl_alloc_cache(state->nl_handle); | ||
278 | - if (!state->nl_cache) { | ||
279 | + err = genl_ctrl_alloc_cache(state->nl_sock, &state->nl_cache); | ||
280 | + if (err < 0) { | ||
281 | snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, | ||
282 | - "%s: failed to allocate generic netlink cache", device); | ||
283 | + "%s: failed to allocate generic netlink cache: %s", | ||
284 | + device, strerror(-err)); | ||
285 | goto out_handle_destroy; | ||
286 | } | ||
287 | |||
288 | @@ -568,7 +600,7 @@ nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device) | ||
289 | out_cache_free: | ||
290 | nl_cache_free(state->nl_cache); | ||
291 | out_handle_destroy: | ||
292 | - nl_handle_destroy(state->nl_handle); | ||
293 | + nl_socket_free(state->nl_sock); | ||
294 | return PCAP_ERROR; | ||
295 | } | ||
296 | |||
297 | @@ -577,7 +609,7 @@ nl80211_cleanup(struct nl80211_state *state) | ||
298 | { | ||
299 | genl_family_put(state->nl80211); | ||
300 | nl_cache_free(state->nl_cache); | ||
301 | - nl_handle_destroy(state->nl_handle); | ||
302 | + nl_socket_free(state->nl_sock); | ||
303 | } | ||
304 | |||
305 | static int | ||
306 | @@ -605,7 +637,7 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, | ||
307 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, mondevice); | ||
308 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR); | ||
309 | |||
310 | - err = nl_send_auto_complete(state->nl_handle, msg); | ||
311 | + err = nl_send_auto_complete(state->nl_sock, msg); | ||
312 | if (err < 0) { | ||
313 | if (err == -ENFILE) { | ||
314 | /* | ||
315 | @@ -626,7 +658,7 @@ add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, | ||
316 | return PCAP_ERROR; | ||
317 | } | ||
318 | } | ||
319 | - err = nl_wait_for_ack(state->nl_handle); | ||
320 | + err = nl_wait_for_ack(state->nl_sock); | ||
321 | if (err < 0) { | ||
322 | if (err == -ENFILE) { | ||
323 | /* | ||
324 | @@ -685,7 +717,7 @@ del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, | ||
325 | 0, NL80211_CMD_DEL_INTERFACE, 0); | ||
326 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | ||
327 | |||
328 | - err = nl_send_auto_complete(state->nl_handle, msg); | ||
329 | + err = nl_send_auto_complete(state->nl_sock, msg); | ||
330 | if (err < 0) { | ||
331 | if (err == -ENFILE) { | ||
332 | /* | ||
333 | @@ -706,7 +738,7 @@ del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, | ||
334 | return PCAP_ERROR; | ||
335 | } | ||
336 | } | ||
337 | - err = nl_wait_for_ack(state->nl_handle); | ||
338 | + err = nl_wait_for_ack(state->nl_sock); | ||
339 | if (err < 0) { | ||
340 | if (err == -ENFILE) { | ||
341 | /* | ||
342 | -- | ||
343 | 1.7.3.5 | ||
344 |