diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-12 10:35:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-12 10:35:23 +0000 |
commit | 6536a9b5833febe719988526a095a9cacb8a1042 (patch) | |
tree | 07b65c5cf7e1f51909d4e7b516253bae7611fa48 /networking/wget.c | |
parent | f8138d1f91c913166bffb0077a0fe06831a77ecf (diff) | |
download | busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.tar.gz busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.tar.bz2 busybox-w32-6536a9b5833febe719988526a095a9cacb8a1042.zip |
next part of ipv6-ization is here: wget & httpd
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/networking/wget.c b/networking/wget.c index ee5aa63e9..22e610699 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -24,7 +24,7 @@ struct host_info { | |||
24 | }; | 24 | }; |
25 | 25 | ||
26 | static void parse_url(char *url, struct host_info *h); | 26 | static void parse_url(char *url, struct host_info *h); |
27 | static FILE *open_socket(struct sockaddr_in *s_in); | 27 | static FILE *open_socket(len_and_sockaddr *lsa); |
28 | static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); | 28 | static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); |
29 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); | 29 | static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); |
30 | 30 | ||
@@ -90,7 +90,7 @@ int wget_main(int argc, char **argv) | |||
90 | { | 90 | { |
91 | char buf[512]; | 91 | char buf[512]; |
92 | struct host_info server, target; | 92 | struct host_info server, target; |
93 | struct sockaddr_in s_in; | 93 | len_and_sockaddr *lsa; |
94 | int n, status; | 94 | int n, status; |
95 | int port; | 95 | int port; |
96 | int try = 5; | 96 | int try = 5; |
@@ -189,7 +189,7 @@ int wget_main(int argc, char **argv) | |||
189 | if (!fname_out) { | 189 | if (!fname_out) { |
190 | // Dirty hack. Needed because bb_get_last_path_component | 190 | // Dirty hack. Needed because bb_get_last_path_component |
191 | // will destroy trailing / by storing '\0' in last byte! | 191 | // will destroy trailing / by storing '\0' in last byte! |
192 | if (*target.path && target.path[strlen(target.path)-1] != '/') { | 192 | if (!last_char_is(target.path, '/')) { |
193 | fname_out = | 193 | fname_out = |
194 | #if ENABLE_FEATURE_WGET_STATUSBAR | 194 | #if ENABLE_FEATURE_WGET_STATUSBAR |
195 | curfile = | 195 | curfile = |
@@ -233,11 +233,11 @@ int wget_main(int argc, char **argv) | |||
233 | /* We want to do exactly _one_ DNS lookup, since some | 233 | /* We want to do exactly _one_ DNS lookup, since some |
234 | * sites (i.e. ftp.us.debian.org) use round-robin DNS | 234 | * sites (i.e. ftp.us.debian.org) use round-robin DNS |
235 | * and we want to connect to only one IP... */ | 235 | * and we want to connect to only one IP... */ |
236 | bb_lookup_host(&s_in, server.host); | 236 | lsa = host2sockaddr(server.host, server.port); |
237 | s_in.sin_port = server.port; | ||
238 | if (!(opt & WGET_OPT_QUIET)) { | 237 | if (!(opt & WGET_OPT_QUIET)) { |
239 | fprintf(stderr, "Connecting to %s[%s]:%d\n", | 238 | fprintf(stderr, "Connecting to %s [%s]\n", server.host, |
240 | server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port)); | 239 | xmalloc_sockaddr2dotted(&lsa->sa, lsa->len)); |
240 | /* We leak xmalloc_sockaddr2dotted result */ | ||
241 | } | 241 | } |
242 | 242 | ||
243 | if (use_proxy || !target.is_ftp) { | 243 | if (use_proxy || !target.is_ftp) { |
@@ -254,26 +254,29 @@ int wget_main(int argc, char **argv) | |||
254 | * Open socket to http server | 254 | * Open socket to http server |
255 | */ | 255 | */ |
256 | if (sfp) fclose(sfp); | 256 | if (sfp) fclose(sfp); |
257 | sfp = open_socket(&s_in); | 257 | sfp = open_socket(lsa); |
258 | 258 | ||
259 | /* | 259 | /* |
260 | * Send HTTP request. | 260 | * Send HTTP request. |
261 | */ | 261 | */ |
262 | if (use_proxy) { | 262 | if (use_proxy) { |
263 | const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n"; | 263 | // const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n"; |
264 | #if ENABLE_FEATURE_WGET_IP6_LITERAL | 264 | //#if ENABLE_FEATURE_WGET_IP6_LITERAL |
265 | if (strchr(target.host, ':')) | 265 | // if (strchr(target.host, ':')) |
266 | format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n"; | 266 | // format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n"; |
267 | #endif | 267 | //#endif |
268 | fprintf(sfp, format, | 268 | // fprintf(sfp, format, |
269 | // target.is_ftp ? "f" : "ht", target.host, | ||
270 | // ntohs(target.port), target.path); | ||
271 | fprintf(sfp, "GET %stp://%s/%s HTTP/1.1\r\n", | ||
269 | target.is_ftp ? "f" : "ht", target.host, | 272 | target.is_ftp ? "f" : "ht", target.host, |
270 | ntohs(target.port), target.path); | 273 | target.path); |
271 | } else { | 274 | } else { |
272 | fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path); | 275 | fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path); |
273 | } | 276 | } |
274 | 277 | ||
275 | fprintf(sfp, "Host: %s:%u\r\nUser-Agent: %s\r\n", | 278 | fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", |
276 | target.host, target.port, user_agent); | 279 | target.host, user_agent); |
277 | 280 | ||
278 | #if ENABLE_FEATURE_WGET_AUTHENTICATION | 281 | #if ENABLE_FEATURE_WGET_AUTHENTICATION |
279 | if (target.user) { | 282 | if (target.user) { |
@@ -357,8 +360,8 @@ int wget_main(int argc, char **argv) | |||
357 | server.host = target.host; | 360 | server.host = target.host; |
358 | server.port = target.port; | 361 | server.port = target.port; |
359 | } | 362 | } |
360 | bb_lookup_host(&s_in, server.host); | 363 | free(lsa); |
361 | s_in.sin_port = server.port; | 364 | lsa = host2sockaddr(server.host, server.port); |
362 | break; | 365 | break; |
363 | } | 366 | } |
364 | } | 367 | } |
@@ -375,7 +378,7 @@ int wget_main(int argc, char **argv) | |||
375 | if (!target.user) | 378 | if (!target.user) |
376 | target.user = xstrdup("anonymous:busybox@"); | 379 | target.user = xstrdup("anonymous:busybox@"); |
377 | 380 | ||
378 | sfp = open_socket(&s_in); | 381 | sfp = open_socket(lsa); |
379 | if (ftpcmd(NULL, NULL, sfp, buf) != 220) | 382 | if (ftpcmd(NULL, NULL, sfp, buf) != 220) |
380 | bb_error_msg_and_die("%s", buf+4); | 383 | bb_error_msg_and_die("%s", buf+4); |
381 | 384 | ||
@@ -429,8 +432,8 @@ int wget_main(int argc, char **argv) | |||
429 | s = strrchr(buf, ','); | 432 | s = strrchr(buf, ','); |
430 | if (!s) goto pasv_error; | 433 | if (!s) goto pasv_error; |
431 | port += xatou_range(s+1, 0, 255) * 256; | 434 | port += xatou_range(s+1, 0, 255) * 256; |
432 | s_in.sin_port = htons(port); | 435 | set_port(lsa, htons(port)); |
433 | dfp = open_socket(&s_in); | 436 | dfp = open_socket(lsa); |
434 | 437 | ||
435 | if (beg_range) { | 438 | if (beg_range) { |
436 | sprintf(buf, "REST %"OFF_FMT"d", beg_range); | 439 | sprintf(buf, "REST %"OFF_FMT"d", beg_range); |
@@ -564,36 +567,37 @@ static void parse_url(char *src_url, struct host_info *h) | |||
564 | 567 | ||
565 | sp = h->host; | 568 | sp = h->host; |
566 | 569 | ||
567 | #if ENABLE_FEATURE_WGET_IP6_LITERAL | 570 | //host2sockaddr does this itself |
568 | if (sp[0] == '[') { | 571 | //#if ENABLE_FEATURE_WGET_IP6_LITERAL |
569 | char *ep; | 572 | // if (sp[0] == '[') { |
570 | 573 | // char *ep; | |
571 | ep = sp + 1; | 574 | // |
572 | while (*ep == ':' || isxdigit(*ep)) | 575 | // ep = sp + 1; |
573 | ep++; | 576 | // while (*ep == ':' || isxdigit(*ep)) |
574 | if (*ep == ']') { | 577 | // ep++; |
575 | h->host++; | 578 | // if (*ep == ']') { |
576 | *ep = '\0'; | 579 | // h->host++; |
577 | sp = ep + 1; | 580 | // *ep = '\0'; |
578 | } | 581 | // sp = ep + 1; |
579 | } | 582 | // } |
580 | #endif | 583 | // } |
581 | 584 | //#endif | |
582 | p = strchr(sp, ':'); | 585 | // |
583 | if (p != NULL) { | 586 | // p = strchr(sp, ':'); |
584 | *p = '\0'; | 587 | // if (p != NULL) { |
585 | h->port = htons(xatou16(p + 1)); | 588 | // *p = '\0'; |
586 | } | 589 | // h->port = htons(xatou16(p + 1)); |
590 | // } | ||
587 | } | 591 | } |
588 | 592 | ||
589 | 593 | ||
590 | static FILE *open_socket(struct sockaddr_in *s_in) | 594 | static FILE *open_socket(len_and_sockaddr *lsa) |
591 | { | 595 | { |
592 | FILE *fp; | 596 | FILE *fp; |
593 | 597 | ||
594 | /* glibc 2.4 seems to try seeking on it - ??! */ | 598 | /* glibc 2.4 seems to try seeking on it - ??! */ |
595 | /* hopefully it understands what ESPIPE means... */ | 599 | /* hopefully it understands what ESPIPE means... */ |
596 | fp = fdopen(xconnect_tcp_v4(s_in), "r+"); | 600 | fp = fdopen(xconnect_stream(lsa), "r+"); |
597 | if (fp == NULL) | 601 | if (fp == NULL) |
598 | bb_perror_msg_and_die("fdopen"); | 602 | bb_perror_msg_and_die("fdopen"); |
599 | 603 | ||