diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-04 02:39:08 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-04 02:39:08 +0000 |
commit | 344b3a5ca5ea57a89cdcb014778b554139be997c (patch) | |
tree | 848e71f864ad0675e19c8dcdce94c11a5dcc3d7a | |
parent | 99194b9a2c7d803572a47da28a7a22178e036d41 (diff) | |
download | busybox-w32-344b3a5ca5ea57a89cdcb014778b554139be997c.tar.gz busybox-w32-344b3a5ca5ea57a89cdcb014778b554139be997c.tar.bz2 busybox-w32-344b3a5ca5ea57a89cdcb014778b554139be997c.zip |
add x to IPv6 functions which can die
git-svn-id: svn://busybox.net/trunk/busybox@17749 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | include/libbb.h | 8 | ||||
-rw-r--r-- | libbb/xconnect.c | 41 | ||||
-rw-r--r-- | networking/arping.c | 2 | ||||
-rw-r--r-- | networking/dnsd.c | 2 | ||||
-rw-r--r-- | networking/ftpgetput.c | 2 | ||||
-rw-r--r-- | networking/nslookup.c | 2 | ||||
-rw-r--r-- | networking/ping.c | 8 | ||||
-rw-r--r-- | networking/tftp.c | 2 | ||||
-rw-r--r-- | networking/wget.c | 4 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 2 |
10 files changed, 37 insertions, 36 deletions
diff --git a/include/libbb.h b/include/libbb.h index 44bd6e09d..dd23c704d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -317,13 +317,13 @@ int xconnect_stream(const len_and_sockaddr *lsa); | |||
317 | * Currently will return IPv4 or IPv6 sockaddrs only | 317 | * Currently will return IPv4 or IPv6 sockaddrs only |
318 | * (depending on host), but in theory nothing prevents e.g. | 318 | * (depending on host), but in theory nothing prevents e.g. |
319 | * UNIX socket address being returned, IPX sockaddr etc... */ | 319 | * UNIX socket address being returned, IPX sockaddr etc... */ |
320 | len_and_sockaddr* host2sockaddr(const char *host, int port); | 320 | len_and_sockaddr* xhost2sockaddr(const char *host, int port); |
321 | #if ENABLE_FEATURE_IPV6 | 321 | #if ENABLE_FEATURE_IPV6 |
322 | /* Same, useful if you want to force family (e.g. IPv6) */ | 322 | /* Same, useful if you want to force family (e.g. IPv6) */ |
323 | len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af); | 323 | len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af); |
324 | #else | 324 | #else |
325 | /* [we evaluate af: think about "host_and_af2sockaddr(..., af++)"] */ | 325 | /* [we evaluate af: think about "xhost_and_af2sockaddr(..., af++)"] */ |
326 | #define host_and_af2sockaddr(host, port, af) ((void)(af), host2sockaddr((host), (port))) | 326 | #define xhost_and_af2sockaddr(host, port, af) ((void)(af), xhost2sockaddr((host), (port))) |
327 | #endif | 327 | #endif |
328 | /* Assign sin[6]_port member if the socket is of corresponding type, | 328 | /* Assign sin[6]_port member if the socket is of corresponding type, |
329 | * otherwise no-op. Useful for ftp. | 329 | * otherwise no-op. Useful for ftp. |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 2b35baab7..e5bdaac38 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -111,16 +111,19 @@ void set_nport(len_and_sockaddr *lsa, unsigned port) | |||
111 | /* What? UNIX socket? IPX?? :) */ | 111 | /* What? UNIX socket? IPX?? :) */ |
112 | } | 112 | } |
113 | 113 | ||
114 | /* We hijack this constant to mean something else */ | ||
115 | /* It doesn't hurt because we will remove this bit anyway */ | ||
116 | #define DIE_ON_ERROR AI_CANONNAME | ||
117 | |||
114 | /* host: "1.2.3.4[:port]", "www.google.com[:port]" | 118 | /* host: "1.2.3.4[:port]", "www.google.com[:port]" |
115 | * port: if neither of above specifies port # | 119 | * port: if neither of above specifies port # */ |
116 | */ | ||
117 | static len_and_sockaddr* str2sockaddr( | 120 | static len_and_sockaddr* str2sockaddr( |
118 | const char *host, int port, | 121 | const char *host, int port, |
119 | USE_FEATURE_IPV6(sa_family_t af,) | 122 | USE_FEATURE_IPV6(sa_family_t af,) |
120 | int ai_flags) | 123 | int ai_flags) |
121 | { | 124 | { |
122 | int rc; | 125 | int rc; |
123 | len_and_sockaddr *r; // = NULL; | 126 | len_and_sockaddr *r = NULL; |
124 | struct addrinfo *result = NULL; | 127 | struct addrinfo *result = NULL; |
125 | const char *org_host = host; /* only for error msg */ | 128 | const char *org_host = host; /* only for error msg */ |
126 | const char *cp; | 129 | const char *cp; |
@@ -158,14 +161,18 @@ USE_FEATURE_IPV6(sa_family_t af,) | |||
158 | /* Needed. Or else we will get each address thrice (or more) | 161 | /* Needed. Or else we will get each address thrice (or more) |
159 | * for each possible socket type (tcp,udp,raw...): */ | 162 | * for each possible socket type (tcp,udp,raw...): */ |
160 | hint.ai_socktype = SOCK_STREAM; | 163 | hint.ai_socktype = SOCK_STREAM; |
161 | hint.ai_flags = ai_flags; | 164 | hint.ai_flags = ai_flags & ~DIE_ON_ERROR; |
162 | rc = getaddrinfo(host, NULL, &hint, &result); | 165 | rc = getaddrinfo(host, NULL, &hint, &result); |
163 | if (rc || !result) | 166 | if (rc || !result) { |
164 | bb_error_msg_and_die("bad address '%s'", org_host); | 167 | if (ai_flags & DIE_ON_ERROR) |
168 | bb_error_msg_and_die("bad address '%s'", org_host); | ||
169 | goto ret; | ||
170 | } | ||
165 | r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen); | 171 | r = xmalloc(offsetof(len_and_sockaddr, sa) + result->ai_addrlen); |
166 | r->len = result->ai_addrlen; | 172 | r->len = result->ai_addrlen; |
167 | memcpy(&r->sa, result->ai_addr, result->ai_addrlen); | 173 | memcpy(&r->sa, result->ai_addr, result->ai_addrlen); |
168 | set_nport(r, htons(port)); | 174 | set_nport(r, htons(port)); |
175 | ret: | ||
169 | freeaddrinfo(result); | 176 | freeaddrinfo(result); |
170 | return r; | 177 | return r; |
171 | } | 178 | } |
@@ -174,20 +181,20 @@ USE_FEATURE_IPV6(sa_family_t af,) | |||
174 | #endif | 181 | #endif |
175 | 182 | ||
176 | #if ENABLE_FEATURE_IPV6 | 183 | #if ENABLE_FEATURE_IPV6 |
177 | len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af) | 184 | len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af) |
178 | { | 185 | { |
179 | return str2sockaddr(host, port, af, 0); | 186 | return str2sockaddr(host, port, af, DIE_ON_ERROR); |
180 | } | 187 | } |
181 | #endif | 188 | #endif |
182 | 189 | ||
183 | len_and_sockaddr* host2sockaddr(const char *host, int port) | 190 | len_and_sockaddr* xhost2sockaddr(const char *host, int port) |
184 | { | 191 | { |
185 | return str2sockaddr(host, port, AF_UNSPEC, 0); | 192 | return str2sockaddr(host, port, AF_UNSPEC, DIE_ON_ERROR); |
186 | } | 193 | } |
187 | 194 | ||
188 | static len_and_sockaddr* dotted2sockaddr(const char *host, int port) | 195 | static len_and_sockaddr* xdotted2sockaddr(const char *host, int port) |
189 | { | 196 | { |
190 | return str2sockaddr(host, port, AF_UNSPEC, NI_NUMERICHOST); | 197 | return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR); |
191 | } | 198 | } |
192 | 199 | ||
193 | int xsocket_stream(len_and_sockaddr **lsap) | 200 | int xsocket_stream(len_and_sockaddr **lsap) |
@@ -220,10 +227,7 @@ int create_and_bind_stream_or_die(const char *bindaddr, int port) | |||
220 | len_and_sockaddr *lsa; | 227 | len_and_sockaddr *lsa; |
221 | 228 | ||
222 | if (bindaddr && bindaddr[0]) { | 229 | if (bindaddr && bindaddr[0]) { |
223 | lsa = dotted2sockaddr(bindaddr, port); | 230 | lsa = xdotted2sockaddr(bindaddr, port); |
224 | /* currently NULL check is in str2sockaddr */ | ||
225 | //if (!lsa) | ||
226 | // bb_error_msg_and_die("bad address '%s'", bindaddr); | ||
227 | /* user specified bind addr dictates family */ | 231 | /* user specified bind addr dictates family */ |
228 | fd = xsocket(lsa->sa.sa_family, SOCK_STREAM, 0); | 232 | fd = xsocket(lsa->sa.sa_family, SOCK_STREAM, 0); |
229 | } else { | 233 | } else { |
@@ -241,10 +245,7 @@ int create_and_connect_stream_or_die(const char *peer, int port) | |||
241 | int fd; | 245 | int fd; |
242 | len_and_sockaddr *lsa; | 246 | len_and_sockaddr *lsa; |
243 | 247 | ||
244 | lsa = host2sockaddr(peer, port); | 248 | lsa = xhost2sockaddr(peer, port); |
245 | /* currently NULL check is in str2sockaddr */ | ||
246 | //if (!lsa) | ||
247 | // bb_error_msg_and_die("bad address '%s'", peer); | ||
248 | fd = xsocket(lsa->sa.sa_family, SOCK_STREAM, 0); | 249 | fd = xsocket(lsa->sa.sa_family, SOCK_STREAM, 0); |
249 | setsockopt_reuseaddr(fd); | 250 | setsockopt_reuseaddr(fd); |
250 | xconnect(fd, &lsa->sa, lsa->len); | 251 | xconnect(fd, &lsa->sa, lsa->len); |
diff --git a/networking/arping.c b/networking/arping.c index 20c782f55..d71ac4930 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -307,7 +307,7 @@ int arping_main(int argc, char **argv) | |||
307 | 307 | ||
308 | if (!inet_aton(target, &dst)) { | 308 | if (!inet_aton(target, &dst)) { |
309 | len_and_sockaddr *lsa; | 309 | len_and_sockaddr *lsa; |
310 | lsa = host_and_af2sockaddr(target, 0, AF_INET); | 310 | lsa = xhost_and_af2sockaddr(target, 0, AF_INET); |
311 | memcpy(&dst, &lsa->sin.sin_addr.s_addr, 4); | 311 | memcpy(&dst, &lsa->sin.sin_addr.s_addr, 4); |
312 | if (ENABLE_FEATURE_CLEAN_UP) | 312 | if (ENABLE_FEATURE_CLEAN_UP) |
313 | free(lsa); | 313 | free(lsa); |
diff --git a/networking/dnsd.c b/networking/dnsd.c index 6d1335e67..78722d6f6 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -377,7 +377,7 @@ int dnsd_main(int argc, char **argv) | |||
377 | signal(SIGURG, SIG_IGN); | 377 | signal(SIGURG, SIG_IGN); |
378 | #endif | 378 | #endif |
379 | 379 | ||
380 | lsa = host2sockaddr(listen_interface, port); | 380 | lsa = xhost2sockaddr(listen_interface, port); |
381 | udps = xsocket(lsa->sa.sa_family, SOCK_DGRAM, 0); | 381 | udps = xsocket(lsa->sa.sa_family, SOCK_DGRAM, 0); |
382 | xbind(udps, &lsa->sa, lsa->len); | 382 | xbind(udps, &lsa->sa, lsa->len); |
383 | // xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? | 383 | // xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index dad1c9947..9b0510df9 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -346,7 +346,7 @@ int ftpgetput_main(int argc, char **argv) | |||
346 | /* We want to do exactly _one_ DNS lookup, since some | 346 | /* We want to do exactly _one_ DNS lookup, since some |
347 | * sites (i.e. ftp.us.debian.org) use round-robin DNS | 347 | * sites (i.e. ftp.us.debian.org) use round-robin DNS |
348 | * and we want to connect to only one IP... */ | 348 | * and we want to connect to only one IP... */ |
349 | server->lsa = host2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21)); | 349 | server->lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21)); |
350 | if (verbose_flag) { | 350 | if (verbose_flag) { |
351 | printf("Connecting to %s (%s)\n", argv[0], | 351 | printf("Connecting to %s (%s)\n", argv[0], |
352 | xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len)); | 352 | xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len)); |
diff --git a/networking/nslookup.c b/networking/nslookup.c index 14c05b3e6..8076aff98 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c | |||
@@ -49,7 +49,7 @@ | |||
49 | 49 | ||
50 | static int print_host(const char *hostname, const char *header) | 50 | static int print_host(const char *hostname, const char *header) |
51 | { | 51 | { |
52 | /* We can't use host2sockaddr() - we want to get ALL addresses, | 52 | /* We can't use xhost2sockaddr() - we want to get ALL addresses, |
53 | * not just one */ | 53 | * not just one */ |
54 | 54 | ||
55 | struct addrinfo *result = NULL; | 55 | struct addrinfo *result = NULL; |
diff --git a/networking/ping.c b/networking/ping.c index d0e6f3ad1..e76584341 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -211,9 +211,9 @@ int ping_main(int argc, char **argv) | |||
211 | bb_show_usage(); | 211 | bb_show_usage(); |
212 | 212 | ||
213 | #if ENABLE_PING6 | 213 | #if ENABLE_PING6 |
214 | lsa = host_and_af2sockaddr(hostname, 0, af); | 214 | lsa = xhost_and_af2sockaddr(hostname, 0, af); |
215 | #else | 215 | #else |
216 | lsa = host_and_af2sockaddr(hostname, 0, AF_INET); | 216 | lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET); |
217 | #endif | 217 | #endif |
218 | /* Set timer _after_ DNS resolution */ | 218 | /* Set timer _after_ DNS resolution */ |
219 | signal(SIGALRM, noresp); | 219 | signal(SIGALRM, noresp); |
@@ -743,9 +743,9 @@ int ping_main(int argc, char **argv) | |||
743 | af = AF_INET; | 743 | af = AF_INET; |
744 | if (option_mask32 & OPT_IPV6) | 744 | if (option_mask32 & OPT_IPV6) |
745 | af = AF_INET6; | 745 | af = AF_INET6; |
746 | lsa = host_and_af2sockaddr(hostname, 0, af); | 746 | lsa = xhost_and_af2sockaddr(hostname, 0, af); |
747 | #else | 747 | #else |
748 | lsa = host_and_af2sockaddr(hostname, 0, AF_INET); | 748 | lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET); |
749 | #endif | 749 | #endif |
750 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len); | 750 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len); |
751 | #if ENABLE_PING6 | 751 | #if ENABLE_PING6 |
diff --git a/networking/tftp.c b/networking/tftp.c index a6d85a5c4..9083257ab 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -488,7 +488,7 @@ int tftp_main(int argc, char **argv) | |||
488 | } | 488 | } |
489 | 489 | ||
490 | port = bb_lookup_port(argv[optind + 1], "udp", 69); | 490 | port = bb_lookup_port(argv[optind + 1], "udp", 69); |
491 | peer_lsa = host2sockaddr(argv[optind], port); | 491 | peer_lsa = xhost2sockaddr(argv[optind], port); |
492 | 492 | ||
493 | #if ENABLE_DEBUG_TFTP | 493 | #if ENABLE_DEBUG_TFTP |
494 | fprintf(stderr, "using server \"%s\", " | 494 | fprintf(stderr, "using server \"%s\", " |
diff --git a/networking/wget.c b/networking/wget.c index e1a4bab0d..e649ccdda 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -234,7 +234,7 @@ int wget_main(int argc, char **argv) | |||
234 | /* We want to do exactly _one_ DNS lookup, since some | 234 | /* We want to do exactly _one_ DNS lookup, since some |
235 | * sites (i.e. ftp.us.debian.org) use round-robin DNS | 235 | * sites (i.e. ftp.us.debian.org) use round-robin DNS |
236 | * and we want to connect to only one IP... */ | 236 | * and we want to connect to only one IP... */ |
237 | lsa = host2sockaddr(server.host, server.port); | 237 | lsa = xhost2sockaddr(server.host, server.port); |
238 | if (!(opt & WGET_OPT_QUIET)) { | 238 | if (!(opt & WGET_OPT_QUIET)) { |
239 | fprintf(stderr, "Connecting to %s (%s)\n", server.host, | 239 | fprintf(stderr, "Connecting to %s (%s)\n", server.host, |
240 | xmalloc_sockaddr2dotted(&lsa->sa, lsa->len)); | 240 | xmalloc_sockaddr2dotted(&lsa->sa, lsa->len)); |
@@ -354,7 +354,7 @@ int wget_main(int argc, char **argv) | |||
354 | server.port = target.port; | 354 | server.port = target.port; |
355 | } | 355 | } |
356 | free(lsa); | 356 | free(lsa); |
357 | lsa = host2sockaddr(server.host, server.port); | 357 | lsa = xhost2sockaddr(server.host, server.port); |
358 | break; | 358 | break; |
359 | } | 359 | } |
360 | } | 360 | } |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 86bfdc5df..97ddf09b5 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -566,7 +566,7 @@ int syslogd_main(int argc, char **argv) | |||
566 | #endif | 566 | #endif |
567 | #if ENABLE_FEATURE_REMOTE_LOG | 567 | #if ENABLE_FEATURE_REMOTE_LOG |
568 | if (option_mask32 & OPT_remotelog) { // -R | 568 | if (option_mask32 & OPT_remotelog) { // -R |
569 | remoteAddr = host2sockaddr(opt_R, 514); | 569 | remoteAddr = xhost2sockaddr(opt_R, 514); |
570 | } | 570 | } |
571 | //if (option_mask32 & OPT_locallog) // -L | 571 | //if (option_mask32 & OPT_locallog) // -L |
572 | #endif | 572 | #endif |