1 |
sbriesen 11/01/23 20:19:26 |
2 |
|
3 |
Modified: ez-ipupdate-3.0.11_beta8-linux.diff |
4 |
Added: ez-ipupdate-3.0.11.13.3_beta8-3322.diff |
5 |
ez-ipupdate-3.0.11.13.3_beta8-dnsexit.diff |
6 |
ez-ipupdate-3.0.11.13.3_beta8-linux.diff |
7 |
Log: |
8 |
fixed compile fail with kernel >= 2.6.35 (bug #337324) and update ebuild to use latest debian patchset (bug #288275). |
9 |
|
10 |
(Portage version: 2.2.0_alpha19/cvs/Linux x86_64) |
11 |
|
12 |
Revision Changes Path |
13 |
1.2 net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11_beta8-linux.diff |
14 |
|
15 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11_beta8-linux.diff?rev=1.2&view=markup |
16 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11_beta8-linux.diff?rev=1.2&content-type=text/plain |
17 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11_beta8-linux.diff?r1=1.1&r2=1.2 |
18 |
|
19 |
Index: ez-ipupdate-3.0.11_beta8-linux.diff |
20 |
=================================================================== |
21 |
RCS file: /var/cvsroot/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11_beta8-linux.diff,v |
22 |
retrieving revision 1.1 |
23 |
retrieving revision 1.2 |
24 |
diff -u -r1.1 -r1.2 |
25 |
--- ez-ipupdate-3.0.11_beta8-linux.diff 20 Jul 2010 20:31:31 -0000 1.1 |
26 |
+++ ez-ipupdate-3.0.11_beta8-linux.diff 23 Jan 2011 20:19:26 -0000 1.2 |
27 |
@@ -5,7 +5,7 @@ |
28 |
# include <sys/sockio.h> |
29 |
# endif |
30 |
+# ifdef __linux__ |
31 |
-+# include <linux/if.h> |
32 |
++/*# include <linux/if.h> */ |
33 |
+# include <linux/netlink.h> |
34 |
+# include <linux/rtnetlink.h> |
35 |
+/* Under Linux, we reopen socket in get_if_addr() every time */ |
36 |
|
37 |
|
38 |
|
39 |
1.1 net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-3322.diff |
40 |
|
41 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-3322.diff?rev=1.1&view=markup |
42 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-3322.diff?rev=1.1&content-type=text/plain |
43 |
|
44 |
Index: ez-ipupdate-3.0.11.13.3_beta8-3322.diff |
45 |
=================================================================== |
46 |
diff -Naur ez-ipupdate-3.0.11b8.orig/example-3322.conf ez-ipupdate-3.0.11b8/example-3322.conf |
47 |
--- ez-ipupdate-3.0.11b8.orig/example-3322.conf 1970-01-01 01:00:00.000000000 +0100 |
48 |
+++ ez-ipupdate-3.0.11b8/example-3322.conf 2011-01-23 19:30:43.785652588 +0100 |
49 |
@@ -0,0 +1,19 @@ |
50 |
+#!/usr/local/bin/ez-ipupdate -c |
51 |
+# |
52 |
+# example config file for ez-ipupdate |
53 |
+# |
54 |
+# this file is actually executable! |
55 |
+# |
56 |
+ |
57 |
+service-type=qdns |
58 |
+#service-type=qdns-static |
59 |
+user=myuserid:mypassword |
60 |
+host=mydomain.whatever.com |
61 |
+interface=eth1 |
62 |
+max-interval=2073600 |
63 |
+ |
64 |
+# uncomment this once you have everything working how you want and you are |
65 |
+# ready to have ez-ipupdate running in the background all the time. to stop it |
66 |
+# you can use "killall -QUIT ez-ipupdate" under linux. |
67 |
+#daemon |
68 |
+ |
69 |
diff -Naur ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c ez-ipupdate-3.0.11b8/ez-ipupdate.c |
70 |
--- ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c 2011-01-23 19:29:17.698793394 +0100 |
71 |
+++ ez-ipupdate-3.0.11b8/ez-ipupdate.c 2011-01-23 19:29:17.799792055 +0100 |
72 |
@@ -103,6 +103,11 @@ |
73 |
#define HEIPV6TB_DEFAULT_PORT "80" |
74 |
#define HEIPV6TB_REQUEST "/index.cgi" |
75 |
|
76 |
+#define QDNS_DEFAULT_SERVER "members.3322.org" |
77 |
+#define QDNS_DEFAULT_PORT "80" |
78 |
+#define QDNS_REQUEST "/dyndns/update" |
79 |
+#define QDNS_STAT_REQUEST "/dyndns/update" |
80 |
+ |
81 |
#define DEFAULT_TIMEOUT 120 |
82 |
#define DEFAULT_UPDATE_PERIOD 120 |
83 |
#define DEFAULT_RESOLV_PERIOD 30 |
84 |
@@ -514,6 +519,26 @@ |
85 |
HEIPV6TB_DEFAULT_PORT, |
86 |
HEIPV6TB_REQUEST |
87 |
}, |
88 |
+ { "qdns", |
89 |
+ { "qdns", 0, 0, }, |
90 |
+ DYNDNS_init, |
91 |
+ DYNDNS_update_entry, |
92 |
+ DYNDNS_check_info, |
93 |
+ DYNDNS_fields_used, |
94 |
+ QDNS_DEFAULT_SERVER, |
95 |
+ QDNS_DEFAULT_PORT, |
96 |
+ QDNS_REQUEST |
97 |
+ }, |
98 |
+ { "qdns-static", |
99 |
+ { "qdns-static", "qdns-stat", "statdns", }, |
100 |
+ DYNDNS_init, |
101 |
+ DYNDNS_update_entry, |
102 |
+ DYNDNS_check_info, |
103 |
+ DYNDNS_STAT_fields_used, |
104 |
+ QDNS_DEFAULT_SERVER, |
105 |
+ QDNS_DEFAULT_PORT, |
106 |
+ QDNS_STAT_REQUEST |
107 |
+ }, |
108 |
}; |
109 |
|
110 |
static struct service_t *service = NULL; |
111 |
|
112 |
|
113 |
|
114 |
1.1 net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-dnsexit.diff |
115 |
|
116 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-dnsexit.diff?rev=1.1&view=markup |
117 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-dnsexit.diff?rev=1.1&content-type=text/plain |
118 |
|
119 |
Index: ez-ipupdate-3.0.11.13.3_beta8-dnsexit.diff |
120 |
=================================================================== |
121 |
diff -Naur ez-ipupdate-3.0.11b8.orig/example-dnsexit.conf ez-ipupdate-3.0.11b8/example-dnsexit.conf |
122 |
--- ez-ipupdate-3.0.11b8.orig/example-dnsexit.conf 1970-01-01 01:00:00.000000000 +0100 |
123 |
+++ ez-ipupdate-3.0.11b8/example-dnsexit.conf 2011-01-23 19:32:53.181937517 +0100 |
124 |
@@ -0,0 +1,19 @@ |
125 |
+#!/usr/sbin/ez-ipupdate -c |
126 |
+# |
127 |
+# example config file for ez-ipupdate |
128 |
+# |
129 |
+# this file is actually executable! |
130 |
+# |
131 |
+ |
132 |
+service-type=dnsexit |
133 |
+user=loginname:password |
134 |
+host=www.yourdomain.com |
135 |
+interface=eth1 |
136 |
+ |
137 |
+run-as-user=ez-ipupd |
138 |
+cache-file=/var/cache/ez-ipupdate/default-cache |
139 |
+ |
140 |
+# uncomment this once you have everything working how you want and you are |
141 |
+# ready to have ez-ipupdate running in the background all the time. to stop it |
142 |
+# you can use "killall -QUIT ez-ipupdate" under linux. |
143 |
+#daemon |
144 |
diff -Naur ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c ez-ipupdate-3.0.11b8/ez-ipupdate.c |
145 |
--- ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c 2011-01-23 19:32:53.074938936 +0100 |
146 |
+++ ez-ipupdate-3.0.11b8/ez-ipupdate.c 2011-01-23 19:32:53.182937505 +0100 |
147 |
@@ -103,6 +103,10 @@ |
148 |
#define HEIPV6TB_DEFAULT_PORT "80" |
149 |
#define HEIPV6TB_REQUEST "/index.cgi" |
150 |
|
151 |
+#define DNSEXIT_DEFAULT_SERVER "www.dnsexit.com" |
152 |
+#define DNSEXIT_DEFAULT_PORT "80" |
153 |
+#define DNSEXIT_REQUEST "/RemoteUpdate.sv" |
154 |
+ |
155 |
#define DEFAULT_TIMEOUT 120 |
156 |
#define DEFAULT_UPDATE_PERIOD 120 |
157 |
#define DEFAULT_RESOLV_PERIOD 30 |
158 |
@@ -341,6 +345,11 @@ |
159 |
int HEIPV6TB_check_info(void); |
160 |
static char *HEIPV6TB_fields_used[] = { "server", "user", NULL }; |
161 |
|
162 |
+int DNSEXIT_update_entry(void); |
163 |
+int DNSEXIT_check_info(void); |
164 |
+static char *DNSEXIT_fields_used[] = { "server", "user", "address", "wildcard", "mx", "host", NULL }; |
165 |
+ |
166 |
+ |
167 |
struct service_t services[] = { |
168 |
{ "NULL", |
169 |
{ "null", "NULL", 0, }, |
170 |
@@ -514,6 +523,16 @@ |
171 |
HEIPV6TB_DEFAULT_PORT, |
172 |
HEIPV6TB_REQUEST |
173 |
}, |
174 |
+ { "dnsexit", |
175 |
+ { "dnsexit", 0, 0, }, |
176 |
+ NULL, |
177 |
+ DNSEXIT_update_entry, |
178 |
+ DNSEXIT_check_info, |
179 |
+ DNSEXIT_fields_used, |
180 |
+ DNSEXIT_DEFAULT_SERVER, |
181 |
+ DNSEXIT_DEFAULT_PORT, |
182 |
+ DNSEXIT_REQUEST |
183 |
+ }, |
184 |
}; |
185 |
|
186 |
static struct service_t *service = NULL; |
187 |
@@ -4241,6 +4260,195 @@ |
188 |
} |
189 |
return(UPDATERES_ERROR); |
190 |
break; |
191 |
+ } |
192 |
+ |
193 |
+ return(UPDATERES_OK); |
194 |
+} |
195 |
+ |
196 |
+int DNSEXIT_check_info(void) |
197 |
+{ |
198 |
+ char buf[BUFSIZ+1]; |
199 |
+ |
200 |
+ if((host == NULL) || (*host == '\0')) |
201 |
+ { |
202 |
+ if(options & OPT_DAEMON) |
203 |
+ { |
204 |
+ return(-1); |
205 |
+ } |
206 |
+ if(host) { free(host); } |
207 |
+ printf("host: "); |
208 |
+ *buf = '\0'; |
209 |
+ fgets(buf, BUFSIZ, stdin); |
210 |
+ host = strdup(buf); |
211 |
+ chomp(host); |
212 |
+ } |
213 |
+ |
214 |
+ if(interface == NULL && address == NULL) |
215 |
+ { |
216 |
+ if(options & OPT_DAEMON) |
217 |
+ { |
218 |
+ fprintf(stderr, "you must provide either an interface or an address\n"); |
219 |
+ return(-1); |
220 |
+ } |
221 |
+ if(interface) { free(interface); } |
222 |
+ printf("interface: "); |
223 |
+ *buf = '\0'; |
224 |
+ fgets(buf, BUFSIZ, stdin); |
225 |
+ chomp(buf); |
226 |
+ option_handler(CMD_interface, buf); |
227 |
+ } |
228 |
+ |
229 |
+ warn_fields(service->fields_used); |
230 |
+ |
231 |
+ return 0; |
232 |
+} |
233 |
+ |
234 |
+int DNSEXIT_update_entry(void) |
235 |
+{ |
236 |
+ char buf[BUFFER_SIZE+1]; |
237 |
+ char *bp = buf; |
238 |
+ int bytes; |
239 |
+ int btot; |
240 |
+ int ret; |
241 |
+ |
242 |
+ buf[BUFFER_SIZE] = '\0'; |
243 |
+ |
244 |
+ if(do_connect((int*)&client_sockfd, server, port) != 0) |
245 |
+ { |
246 |
+ if(!(options & OPT_QUIET)) |
247 |
+ { |
248 |
+ show_message("error connecting to %s:%s\n", server, port); |
249 |
+ } |
250 |
+ return(UPDATERES_ERROR); |
251 |
+ } |
252 |
+ |
253 |
+ snprintf(buf, BUFFER_SIZE, "GET %s?action=edit&", request); |
254 |
+ output(buf); |
255 |
+ if(address != NULL && *address != '\0') |
256 |
+ { |
257 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "myip", address); |
258 |
+ output(buf); |
259 |
+ } |
260 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "wildcard", wildcard ? "ON" : "OFF"); |
261 |
+ output(buf); |
262 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "mx", mx); |
263 |
+ output(buf); |
264 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "backmx", *mx == '\0' ? "NO" : "YES"); |
265 |
+ output(buf); |
266 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "host", host); |
267 |
+ output(buf); |
268 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "login", user_name); |
269 |
+ output(buf); |
270 |
+ snprintf(buf, BUFFER_SIZE, "%s=%s&", "password", password); |
271 |
+ output(buf); |
272 |
+ snprintf(buf, BUFFER_SIZE, " HTTP/1.0\015\012"); |
273 |
+ output(buf); |
274 |
+ snprintf(buf, BUFFER_SIZE, "Authorization: Basic %s\015\012", auth); |
275 |
+ output(buf); |
276 |
+ snprintf(buf, BUFFER_SIZE, "User-Agent: %s-%s %s [%s] (%s)\015\012", |
277 |
+ "ez-update", VERSION, OS, (options & OPT_DAEMON) ? "daemon" : "", "by Angus Mackay"); |
278 |
+ output(buf); |
279 |
+ snprintf(buf, BUFFER_SIZE, "Host: %s\015\012", server); |
280 |
+ output(buf); |
281 |
+ snprintf(buf, BUFFER_SIZE, "\015\012"); |
282 |
+ output(buf); |
283 |
+ |
284 |
+ bp = buf; |
285 |
+ bytes = 0; |
286 |
+ btot = 0; |
287 |
+ while((bytes=read_input(bp, BUFFER_SIZE-btot)) > 0) |
288 |
+ { |
289 |
+ bp += bytes; |
290 |
+ btot += bytes; |
291 |
+ dprintf((stderr, "btot: %d\n", btot)); |
292 |
+ } |
293 |
+ close(client_sockfd); |
294 |
+ buf[btot] = '\0'; |
295 |
+ |
296 |
+ dprintf((stderr, "server output: %s\n", buf)); |
297 |
+ |
298 |
+ if(sscanf(buf, " HTTP/1.%*c %3d", &ret) != 1) |
299 |
+ { |
300 |
+ ret = -1; |
301 |
+ } |
302 |
+ |
303 |
+ switch(ret) |
304 |
+ { |
305 |
+ case -1: |
306 |
+ if(!(options & OPT_QUIET)) |
307 |
+ { |
308 |
+ show_message("strange server response, are you connecting to the right server?\n"); |
309 |
+ } |
310 |
+ return(UPDATERES_ERROR); |
311 |
+ break; |
312 |
+ |
313 |
+ case 200: |
314 |
+ |
315 |
+ if(strstr(buf, "0=Success") != NULL) |
316 |
+ { |
317 |
+ if(!(options & OPT_QUIET)) |
318 |
+ { |
319 |
+ printf("Request successful\n"); |
320 |
+ } |
321 |
+ } |
322 |
+ else if(strstr(buf, "1=IP is the same as the IP on the system") != NULL) |
323 |
+ { |
324 |
+ if(!(options & OPT_QUIET)) |
325 |
+ { |
326 |
+ printf("Request successful but the IP is the same as previous update\n"); |
327 |
+ } |
328 |
+ } |
329 |
+ else if(strstr(buf, "2=Invalid passwords") != NULL) |
330 |
+ { |
331 |
+ if(!(options & OPT_QUIET)) |
332 |
+ { |
333 |
+ printf("Invalid Password\n"); |
334 |
+ } |
335 |
+ } |
336 |
+ else if(strstr(buf, "3=User not found") != NULL) |
337 |
+ { |
338 |
+ if(!(options & OPT_QUIET)) |
339 |
+ { |
340 |
+ printf("Username not found\n"); |
341 |
+ } |
342 |
+ } |
343 |
+ else if(strstr(buf, "4=Update too often") != NULL) |
344 |
+ { |
345 |
+ if(!(options & OPT_QUIET)) |
346 |
+ { |
347 |
+ printf("Updatting too often\n"); |
348 |
+ } |
349 |
+ } |
350 |
+ else |
351 |
+ { |
352 |
+ show_message("Errors return from server\n"); |
353 |
+ if(!(options & OPT_QUIET)) |
354 |
+ { |
355 |
+ fprintf(stderr, "server output: %s\n", buf); |
356 |
+ } |
357 |
+ return(UPDATERES_ERROR); |
358 |
+ } |
359 |
+ break; |
360 |
+ |
361 |
+ case 401: |
362 |
+ if(!(options & OPT_QUIET)) |
363 |
+ { |
364 |
+ show_message("authentication failure\n"); |
365 |
+ } |
366 |
+ return(UPDATERES_SHUTDOWN); |
367 |
+ break; |
368 |
+ |
369 |
+ default: |
370 |
+ if(!(options & OPT_QUIET)) |
371 |
+ { |
372 |
+ // reuse the auth buffer |
373 |
+ *auth = '\0'; |
374 |
+ sscanf(buf, " HTTP/1.%*c %*3d %255[^\r\n]", auth); |
375 |
+ show_message("unknown return code: %d\n", ret); |
376 |
+ show_message("server response: %s\n", auth); |
377 |
+ } |
378 |
+ return(UPDATERES_ERROR); |
379 |
+ break; |
380 |
} |
381 |
|
382 |
return(UPDATERES_OK); |
383 |
|
384 |
|
385 |
|
386 |
1.1 net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-linux.diff |
387 |
|
388 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-linux.diff?rev=1.1&view=markup |
389 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/ez-ipupdate/files/ez-ipupdate-3.0.11.13.3_beta8-linux.diff?rev=1.1&content-type=text/plain |
390 |
|
391 |
Index: ez-ipupdate-3.0.11.13.3_beta8-linux.diff |
392 |
=================================================================== |
393 |
diff -Naur ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c ez-ipupdate-3.0.11b8/ez-ipupdate.c |
394 |
--- ez-ipupdate-3.0.11b8.orig/ez-ipupdate.c 2011-01-23 19:35:10.885111914 +0100 |
395 |
+++ ez-ipupdate-3.0.11b8/ez-ipupdate.c 2011-01-23 19:35:10.979110667 +0100 |
396 |
@@ -172,6 +172,17 @@ |
397 |
# ifdef HAVE_SYS_SOCKIO_H |
398 |
# include <sys/sockio.h> |
399 |
# endif |
400 |
+# ifdef __linux__ |
401 |
+/*# include <linux/if.h> */ |
402 |
+# include <linux/netlink.h> |
403 |
+# include <linux/rtnetlink.h> |
404 |
+/* Under Linux, we reopen socket in get_if_addr() every time */ |
405 |
+# define socketopen(sock) |
406 |
+# define socketclose(sock) |
407 |
+# else |
408 |
+# define socketopen(sock) sock = socket(AF_INET, SOCK_STREAM, 0) |
409 |
+# define socketclose(sock) close(sock) |
410 |
+# endif |
411 |
#endif |
412 |
|
413 |
#include <dprintf.h> |
414 |
@@ -1605,6 +1616,114 @@ |
415 |
int get_if_addr(int sock, char *name, struct sockaddr_in *sin) |
416 |
{ |
417 |
#ifdef IF_LOOKUP |
418 |
+#ifdef __linux__ |
419 |
+ struct { |
420 |
+ struct nlmsghdr nlmsg_info; |
421 |
+ struct ifaddrmsg ifaddrmsg_info; |
422 |
+ char buffer[2048]; |
423 |
+ } req; |
424 |
+ struct nlmsghdr *curr; |
425 |
+ int len; |
426 |
+ char buf[8192]; |
427 |
+ |
428 |
+ /* open a socket and bind it. |
429 |
+ Under non-linux, the socket can be kept open, but it seems under |
430 |
+ linux we cannot use the same socket for several requests reliable |
431 |
+ [although sometimes it works...] */ |
432 |
+ static struct sockaddr_nl local; |
433 |
+ sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
434 |
+ if(sock < 0) { |
435 |
+ perror("socket"); |
436 |
+ return -1; |
437 |
+ } |
438 |
+ local.nl_family = AF_NETLINK; |
439 |
+ local.nl_pad = 0; |
440 |
+ local.nl_pid = getpid(); |
441 |
+ local.nl_groups = 0; |
442 |
+ if(bind(sock, (struct sockaddr*) &local, sizeof(local)) < 0) { |
443 |
+ perror("bind"); |
444 |
+ close(sock); |
445 |
+ return -1; |
446 |
+ } |
447 |
+ |
448 |
+ memset(&req, 0, sizeof(req)); |
449 |
+ req.nlmsg_info.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); |
450 |
+ req.nlmsg_info.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; |
451 |
+ req.nlmsg_info.nlmsg_type = RTM_GETADDR; |
452 |
+ req.nlmsg_info.nlmsg_pid = getpid(); |
453 |
+ req.ifaddrmsg_info.ifa_family = AF_INET; |
454 |
+ if(send(sock, &req, req.nlmsg_info.nlmsg_len, 0) < 0) { |
455 |
+ perror("sendmsg(sock)"); |
456 |
+ close(sock); |
457 |
+ return -1; |
458 |
+ } |
459 |
+ |
460 |
+ len = recv(sock, buf, sizeof(buf), 0); |
461 |
+ close(sock); |
462 |
+ if(len < 0) { |
463 |
+ perror("recv"); |
464 |
+ return -1; |
465 |
+ } else if(len == 0) { |
466 |
+ dprintf((stderr, "No interfaces found")); |
467 |
+ return -1; |
468 |
+ } |
469 |
+ |
470 |
+ /* Initialize sin except for address */ |
471 |
+ bzero(sin, sizeof(struct sockaddr_in)); |
472 |
+ sin->sin_family = AF_INET; |
473 |
+ |
474 |
+ /* We take the last non-private IP with matching name */ |
475 |
+ int found = 0; |
476 |
+ curr = (struct nlmsghdr *) buf; |
477 |
+ for(; NLMSG_OK(curr, len); curr = NLMSG_NEXT(curr, len)) { |
478 |
+ struct ifaddrmsg *curraddr = (struct ifaddrmsg *) NLMSG_DATA(curr); |
479 |
+ struct rtattr *datalist = (struct rtattr *) IFA_RTA(curraddr); |
480 |
+ int datalen = IFA_PAYLOAD(curr); |
481 |
+ int mystat = 0; |
482 |
+ struct in_addr sin_addr; |
483 |
+ in_addr_t addr; |
484 |
+ for(; RTA_OK(datalist, datalen); datalist = RTA_NEXT(datalist, datalen)) { |
485 |
+ switch(datalist->rta_type) { |
486 |
+ case IFA_LABEL: |
487 |
+ if(strcmp((char *)RTA_DATA(datalist), name) != 0) |
488 |
+ mystat = -1; |
489 |
+ break; |
490 |
+ case IFA_LOCAL: |
491 |
+ addr = ((struct in_addr *)RTA_DATA(datalist))->s_addr; |
492 |
+ /* addr: 192.168.0.0/16 || 172.16.0.0/12 || 10.0.0.0/8 */ |
493 |
+ if(((addr & 0xFFFF) == 0xA8C0) |
494 |
+ || ((addr & 0xF0FF) == 0x10AC) |
495 |
+ || ((addr & 0xFF) == 0x0A)) { |
496 |
+ mystat = -1; |
497 |
+ } |
498 |
+ else { |
499 |
+ /* We must not store yet sin->sin_addr, since name might not match */ |
500 |
+ sin_addr = *((struct in_addr *)RTA_DATA(datalist)); |
501 |
+ mystat = 1; |
502 |
+ } |
503 |
+ break; |
504 |
+ default: |
505 |
+ break; |
506 |
+ } |
507 |
+ if(mystat < 0) |
508 |
+ break; |
509 |
+ } |
510 |
+ if(mystat > 0) { |
511 |
+ sin->sin_addr = sin_addr; |
512 |
+ found = 1; |
513 |
+ /* If you want to take the first non-private IP with matching name |
514 |
+ uncomment the next break command: |
515 |
+ break; */ |
516 |
+ } |
517 |
+ } |
518 |
+ if(found) { |
519 |
+ dprintf((stderr, "%s: %s\n", name, inet_ntoa(sin->sin_addr))); |
520 |
+ return 0; |
521 |
+ } |
522 |
+ dprintf((stderr, "%s: %s\n", name, "has no non-private address")); |
523 |
+ return -1; |
524 |
+#else |
525 |
+/* ifndef __linux__ */ |
526 |
struct ifreq ifr; |
527 |
|
528 |
memset(&ifr, 0, sizeof(ifr)); |
529 |
@@ -1638,7 +1757,10 @@ |
530 |
return -1; |
531 |
} |
532 |
return -1; |
533 |
+#endif |
534 |
+/* endif __linux__ */ |
535 |
#else |
536 |
+/* ifndef IF_LOOKUP */ |
537 |
return -1; |
538 |
#endif |
539 |
} |
540 |
@@ -4490,7 +4612,7 @@ |
541 |
#ifdef IF_LOOKUP |
542 |
if(options & OPT_DAEMON) |
543 |
{ |
544 |
- sock = socket(AF_INET, SOCK_STREAM, 0); |
545 |
+ socketopen(sock); |
546 |
} |
547 |
#endif |
548 |
|
549 |
@@ -4745,12 +4867,12 @@ |
550 |
struct sockaddr_in sin; |
551 |
int sock; |
552 |
|
553 |
- sock = socket(AF_INET, SOCK_STREAM, 0); |
554 |
+ socketopen(sock); |
555 |
if(get_if_addr(sock, interface, &sin) != 0) |
556 |
{ |
557 |
exit(1); |
558 |
} |
559 |
- close(sock); |
560 |
+ socketclose(sock); |
561 |
snprintf(ipbuf, sizeof(ipbuf), "%s", inet_ntoa(sin.sin_addr)); |
562 |
#else |
563 |
fprintf(stderr, "interface lookup not enabled at compile time\n"); |
564 |
@@ -4791,7 +4913,7 @@ |
565 |
struct sockaddr_in sin; |
566 |
int sock; |
567 |
|
568 |
- sock = socket(AF_INET, SOCK_STREAM, 0); |
569 |
+ socketopen(sock); |
570 |
if(get_if_addr(sock, interface, &sin) == 0) |
571 |
{ |
572 |
if(address) { free(address); } |
573 |
@@ -4802,7 +4924,7 @@ |
574 |
show_message("could not resolve ip address for %s.\n", interface); |
575 |
exit(1); |
576 |
} |
577 |
- close(sock); |
578 |
+ socketclose(sock); |
579 |
} |
580 |
|
581 |
for(i=0; i<ntrys; i++) |
582 |
@@ -4846,12 +4968,12 @@ |
583 |
struct sockaddr_in sin; |
584 |
int sock; |
585 |
|
586 |
- sock = socket(AF_INET, SOCK_STREAM, 0); |
587 |
+ socketopen(sock); |
588 |
if(get_if_addr(sock, interface, &sin) != 0) |
589 |
{ |
590 |
exit(1); |
591 |
} |
592 |
- close(sock); |
593 |
+ socketclose(sock); |
594 |
snprintf(ipbuf, sizeof(ipbuf), "%s", inet_ntoa(sin.sin_addr)); |
595 |
#else |
596 |
fprintf(stderr, "interface lookup not enabled at compile time\n"); |
597 |
@@ -4878,7 +5000,7 @@ |
598 |
} |
599 |
|
600 |
#ifdef IF_LOOKUP |
601 |
- if(sock > 0) { close(sock); } |
602 |
+ if(sock > 0) { socketclose(sock); } |
603 |
#endif |
604 |
|
605 |
if(address) { free(address); } |