[BusyBox-cvs] busybox/networking wget.c, 1.60, 1.61 telnet.c, 1.38, 1.39
Erik Andersen
andersen at busybox.net
Fri Oct 31 09:31:47 UTC 2003
Update of /var/cvs/busybox/networking
In directory winder:/tmp/cvs-serv32160/networking
Modified Files:
wget.c telnet.c
Log Message:
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
Index: telnet.c
===================================================================
RCS file: /var/cvs/busybox/networking/telnet.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- telnet.c 15 Sep 2003 08:33:37 -0000 1.38
+++ telnet.c 31 Oct 2003 09:31:43 -0000 1.39
@@ -573,6 +573,7 @@
char *host;
char *port;
int len;
+ struct sockaddr_in s_in;
#ifdef USE_POLL
struct pollfd ufds[2];
#else
@@ -601,7 +602,8 @@
host = argv[1];
- G.netfd = xconnect(host, port);
+ bb_lookup_host(&s_in, host, port);
+ G.netfd = xconnect(&s_in);
setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);
Index: wget.c
===================================================================
RCS file: /var/cvs/busybox/networking/wget.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- wget.c 15 Sep 2003 08:33:37 -0000 1.60
+++ wget.c 31 Oct 2003 09:31:43 -0000 1.61
@@ -40,7 +40,7 @@
};
static void parse_url(char *url, struct host_info *h);
-static FILE *open_socket(char *host, int port);
+static FILE *open_socket(struct sockaddr_in *s_in, int port);
static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
@@ -155,6 +155,7 @@
int extra_headers_left = sizeof(extra_headers);
int which_long_opt = 0, option_index = -1;
struct host_info server, target;
+ struct sockaddr_in s_in;
FILE *sfp = NULL; /* socket to web/ftp server */
FILE *dfp = NULL; /* socket to ftp server (data) */
@@ -290,6 +291,15 @@
do_continue = 0;
}
+ /* We want to do exactly _one_ DNS lookup, since some
+ * sites (i.e. ftp.us.debian.org) use round-robin DNS
+ * and we want to connect to only one IP... */
+ bb_lookup_host(&s_in, server.host, NULL);
+ if (quiet_flag==FALSE) {
+ fprintf(stdout, "Connecting to %s[%s]:%d\n",
+ server.host, inet_ntoa(s_in.sin_addr), server.port);
+ }
+
if (proxy || !target.is_ftp) {
/*
* HTTP session
@@ -304,7 +314,7 @@
* Open socket to http server
*/
if (sfp) fclose(sfp);
- sfp = open_socket(server.host, server.port);
+ sfp = open_socket(&s_in, server.port);
/*
* Send HTTP request.
@@ -416,7 +426,7 @@
if (! target.user)
target.user = bb_xstrdup("anonymous:busybox@");
- sfp = open_socket(server.host, server.port);
+ sfp = open_socket(&s_in, server.port);
if (ftpcmd(NULL, NULL, sfp, buf) != 220)
close_delete_and_die("%s", buf+4);
@@ -459,7 +469,7 @@
port = atoi(s+1);
s = strrchr(buf, ',');
port += atoi(s+1) * 256;
- dfp = open_socket(server.host, port);
+ dfp = open_socket(&s_in, port);
if (do_continue) {
sprintf(buf, "REST %ld", beg_range);
@@ -584,14 +594,16 @@
}
-FILE *open_socket(char *host, int port)
+FILE *open_socket(struct sockaddr_in *s_in, int port)
{
int fd;
FILE *fp;
- char port_str[10];
- snprintf(port_str, sizeof(port_str), "%d", port);
- fd=xconnect(host, port_str);
+ if (port>0 && port < 65536) {
+ s_in->sin_port=htons(port);
+ }
+
+ fd=xconnect(s_in);
/*
* Get the server onto a stdio stream.
More information about the busybox-cvs
mailing list