aboutsummaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-12-20 01:47:18 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-12-20 01:47:18 +0000
commitffccf6eb5de311a3db8c3d7f7496e2f0cad69a23 (patch)
tree859f5849c30de6cb69bf6336af6d2228402f2395 /networking/wget.c
parent03d8091859f45a6bb5e3aadc110b279e789399f2 (diff)
downloadbusybox-w32-ffccf6eb5de311a3db8c3d7f7496e2f0cad69a23.tar.gz
busybox-w32-ffccf6eb5de311a3db8c3d7f7496e2f0cad69a23.tar.bz2
busybox-w32-ffccf6eb5de311a3db8c3d7f7496e2f0cad69a23.zip
Change interface to bb_lookup_host, dont try and set port inside this
function as there is no gracefull way of handling failures. Rename bb_getport to bb_lookup_port, allow a default port to be specified so it always returns a correct value. Modify ftpgetput/rdate/wget to use the new interface. wget/rdate now use etc/services with a falback default value.
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 3e74ed357..9f5dbaf21 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -40,7 +40,7 @@ struct host_info {
40}; 40};
41 41
42static void parse_url(char *url, struct host_info *h); 42static void parse_url(char *url, struct host_info *h);
43static FILE *open_socket(struct sockaddr_in *s_in, int port); 43static FILE *open_socket(struct sockaddr_in *s_in);
44static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); 44static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
45static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); 45static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
46 46
@@ -286,10 +286,11 @@ int wget_main(int argc, char **argv)
286 /* We want to do exactly _one_ DNS lookup, since some 286 /* We want to do exactly _one_ DNS lookup, since some
287 * sites (i.e. ftp.us.debian.org) use round-robin DNS 287 * sites (i.e. ftp.us.debian.org) use round-robin DNS
288 * and we want to connect to only one IP... */ 288 * and we want to connect to only one IP... */
289 bb_lookup_host(&s_in, server.host, NULL); 289 bb_lookup_host(&s_in, server.host);
290 s_in.sin_port = server.port;
290 if (quiet_flag==FALSE) { 291 if (quiet_flag==FALSE) {
291 fprintf(stdout, "Connecting to %s[%s]:%d\n", 292 fprintf(stdout, "Connecting to %s[%s]:%d\n",
292 server.host, inet_ntoa(s_in.sin_addr), server.port); 293 server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port));
293 } 294 }
294 295
295 if (proxy || !target.is_ftp) { 296 if (proxy || !target.is_ftp) {
@@ -306,7 +307,7 @@ int wget_main(int argc, char **argv)
306 * Open socket to http server 307 * Open socket to http server
307 */ 308 */
308 if (sfp) fclose(sfp); 309 if (sfp) fclose(sfp);
309 sfp = open_socket(&s_in, server.port); 310 sfp = open_socket(&s_in);
310 311
311 /* 312 /*
312 * Send HTTP request. 313 * Send HTTP request.
@@ -418,7 +419,7 @@ read_response:
418 if (! target.user) 419 if (! target.user)
419 target.user = bb_xstrdup("anonymous:busybox@"); 420 target.user = bb_xstrdup("anonymous:busybox@");
420 421
421 sfp = open_socket(&s_in, server.port); 422 sfp = open_socket(&s_in);
422 if (ftpcmd(NULL, NULL, sfp, buf) != 220) 423 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
423 close_delete_and_die("%s", buf+4); 424 close_delete_and_die("%s", buf+4);
424 425
@@ -461,7 +462,8 @@ read_response:
461 port = atoi(s+1); 462 port = atoi(s+1);
462 s = strrchr(buf, ','); 463 s = strrchr(buf, ',');
463 port += atoi(s+1) * 256; 464 port += atoi(s+1) * 256;
464 dfp = open_socket(&s_in, port); 465 s_in.sin_port = htons(port);
466 dfp = open_socket(&s_in);
465 467
466 if (do_continue) { 468 if (do_continue) {
467 sprintf(buf, "REST %ld", beg_range); 469 sprintf(buf, "REST %ld", beg_range);
@@ -535,11 +537,11 @@ void parse_url(char *url, struct host_info *h)
535 char *cp, *sp, *up, *pp; 537 char *cp, *sp, *up, *pp;
536 538
537 if (strncmp(url, "http://", 7) == 0) { 539 if (strncmp(url, "http://", 7) == 0) {
538 h->port = 80; 540 h->port = bb_lookup_port("http", 80);
539 h->host = url + 7; 541 h->host = url + 7;
540 h->is_ftp = 0; 542 h->is_ftp = 0;
541 } else if (strncmp(url, "ftp://", 6) == 0) { 543 } else if (strncmp(url, "ftp://", 6) == 0) {
542 h->port = 21; 544 h->port = bb_lookup_port("ftp", 21);
543 h->host = url + 6; 545 h->host = url + 6;
544 h->is_ftp = 1; 546 h->is_ftp = 1;
545 } else 547 } else
@@ -586,21 +588,12 @@ void parse_url(char *url, struct host_info *h)
586} 588}
587 589
588 590
589FILE *open_socket(struct sockaddr_in *s_in, int port) 591FILE *open_socket(struct sockaddr_in *s_in)
590{ 592{
591 int fd;
592 FILE *fp; 593 FILE *fp;
593 594
594 if (port>0 && port < 65536) { 595 fp = fdopen(xconnect(s_in), "r+");
595 s_in->sin_port=htons(port); 596 if (fp == NULL)
596 }
597
598 fd=xconnect(s_in);
599
600 /*
601 * Get the server onto a stdio stream.
602 */
603 if ((fp = fdopen(fd, "r+")) == NULL)
604 bb_perror_msg_and_die("fdopen()"); 597 bb_perror_msg_and_die("fdopen()");
605 598
606 return fp; 599 return fp;
@@ -842,7 +835,7 @@ progressmeter(int flag)
842 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 835 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
843 * SUCH DAMAGE. 836 * SUCH DAMAGE.
844 * 837 *
845 * $Id: wget.c,v 1.62 2003/12/19 12:08:56 bug1 Exp $ 838 * $Id: wget.c,v 1.63 2003/12/20 01:47:18 bug1 Exp $
846 */ 839 */
847 840
848 841