diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-10-31 09:31:46 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-10-31 09:31:46 +0000 |
commit | e6dc439b3a3fa2a64f9e938ac4e5810025c04242 (patch) | |
tree | bacb9f48301189de134d9f8edc2f1f45c65086c5 /networking/wget.c | |
parent | 8179cf2b78a508a350c7497c1e234376f20f418f (diff) | |
download | busybox-w32-e6dc439b3a3fa2a64f9e938ac4e5810025c04242.tar.gz busybox-w32-e6dc439b3a3fa2a64f9e938ac4e5810025c04242.tar.bz2 busybox-w32-e6dc439b3a3fa2a64f9e938ac4e5810025c04242.zip |
Rework wget, the xconnect interface, and its various clients
in order to fix the problems with round robin DNS reported
by Andrew Flegg:
http://busybox.net/lists/busybox/2003-October/009579.html
This removes the ipv6 specific xconnect dns lookups. I do
not see why that would need to be special cased for ipv6 as
was done, but that will just have to be tested.
So IPV6 people -- please test this change!
-Erik
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/networking/wget.c b/networking/wget.c index 597d61097..08026915e 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -40,7 +40,7 @@ struct host_info { | |||
40 | }; | 40 | }; |
41 | 41 | ||
42 | static void parse_url(char *url, struct host_info *h); | 42 | static void parse_url(char *url, struct host_info *h); |
43 | static FILE *open_socket(char *host, int port); | 43 | static FILE *open_socket(struct sockaddr_in *s_in, int port); |
44 | static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); | 44 | static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); |
45 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); | 45 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); |
46 | 46 | ||
@@ -155,6 +155,7 @@ int wget_main(int argc, char **argv) | |||
155 | int extra_headers_left = sizeof(extra_headers); | 155 | int extra_headers_left = sizeof(extra_headers); |
156 | int which_long_opt = 0, option_index = -1; | 156 | int which_long_opt = 0, option_index = -1; |
157 | struct host_info server, target; | 157 | struct host_info server, target; |
158 | struct sockaddr_in s_in; | ||
158 | 159 | ||
159 | FILE *sfp = NULL; /* socket to web/ftp server */ | 160 | FILE *sfp = NULL; /* socket to web/ftp server */ |
160 | FILE *dfp = NULL; /* socket to ftp server (data) */ | 161 | FILE *dfp = NULL; /* socket to ftp server (data) */ |
@@ -290,6 +291,15 @@ int wget_main(int argc, char **argv) | |||
290 | do_continue = 0; | 291 | do_continue = 0; |
291 | } | 292 | } |
292 | 293 | ||
294 | /* We want to do exactly _one_ DNS lookup, since some | ||
295 | * sites (i.e. ftp.us.debian.org) use round-robin DNS | ||
296 | * and we want to connect to only one IP... */ | ||
297 | bb_lookup_host(&s_in, server.host, NULL); | ||
298 | if (quiet_flag==FALSE) { | ||
299 | fprintf(stdout, "Connecting to %s[%s]:%d\n", | ||
300 | server.host, inet_ntoa(s_in.sin_addr), server.port); | ||
301 | } | ||
302 | |||
293 | if (proxy || !target.is_ftp) { | 303 | if (proxy || !target.is_ftp) { |
294 | /* | 304 | /* |
295 | * HTTP session | 305 | * HTTP session |
@@ -304,7 +314,7 @@ int wget_main(int argc, char **argv) | |||
304 | * Open socket to http server | 314 | * Open socket to http server |
305 | */ | 315 | */ |
306 | if (sfp) fclose(sfp); | 316 | if (sfp) fclose(sfp); |
307 | sfp = open_socket(server.host, server.port); | 317 | sfp = open_socket(&s_in, server.port); |
308 | 318 | ||
309 | /* | 319 | /* |
310 | * Send HTTP request. | 320 | * Send HTTP request. |
@@ -416,7 +426,7 @@ read_response: | |||
416 | if (! target.user) | 426 | if (! target.user) |
417 | target.user = bb_xstrdup("anonymous:busybox@"); | 427 | target.user = bb_xstrdup("anonymous:busybox@"); |
418 | 428 | ||
419 | sfp = open_socket(server.host, server.port); | 429 | sfp = open_socket(&s_in, server.port); |
420 | if (ftpcmd(NULL, NULL, sfp, buf) != 220) | 430 | if (ftpcmd(NULL, NULL, sfp, buf) != 220) |
421 | close_delete_and_die("%s", buf+4); | 431 | close_delete_and_die("%s", buf+4); |
422 | 432 | ||
@@ -459,7 +469,7 @@ read_response: | |||
459 | port = atoi(s+1); | 469 | port = atoi(s+1); |
460 | s = strrchr(buf, ','); | 470 | s = strrchr(buf, ','); |
461 | port += atoi(s+1) * 256; | 471 | port += atoi(s+1) * 256; |
462 | dfp = open_socket(server.host, port); | 472 | dfp = open_socket(&s_in, port); |
463 | 473 | ||
464 | if (do_continue) { | 474 | if (do_continue) { |
465 | sprintf(buf, "REST %ld", beg_range); | 475 | sprintf(buf, "REST %ld", beg_range); |
@@ -584,14 +594,16 @@ void parse_url(char *url, struct host_info *h) | |||
584 | } | 594 | } |
585 | 595 | ||
586 | 596 | ||
587 | FILE *open_socket(char *host, int port) | 597 | FILE *open_socket(struct sockaddr_in *s_in, int port) |
588 | { | 598 | { |
589 | int fd; | 599 | int fd; |
590 | FILE *fp; | 600 | FILE *fp; |
591 | char port_str[10]; | ||
592 | 601 | ||
593 | snprintf(port_str, sizeof(port_str), "%d", port); | 602 | if (port>0 && port < 65536) { |
594 | fd=xconnect(host, port_str); | 603 | s_in->sin_port=htons(port); |
604 | } | ||
605 | |||
606 | fd=xconnect(s_in); | ||
595 | 607 | ||
596 | /* | 608 | /* |
597 | * Get the server onto a stdio stream. | 609 | * Get the server onto a stdio stream. |
@@ -838,7 +850,7 @@ progressmeter(int flag) | |||
838 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 850 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
839 | * SUCH DAMAGE. | 851 | * SUCH DAMAGE. |
840 | * | 852 | * |
841 | * $Id: wget.c,v 1.60 2003/09/15 08:33:37 andersen Exp $ | 853 | * $Id: wget.c,v 1.61 2003/10/31 09:31:43 andersen Exp $ |
842 | */ | 854 | */ |
843 | 855 | ||
844 | 856 | ||