aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-10-31 09:31:46 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-10-31 09:31:46 +0000
commitf9ece60e489d3250dac2887a0f0b6ba62b8a158c (patch)
treebacb9f48301189de134d9f8edc2f1f45c65086c5 /libbb
parentab8f96331f5f70a30edc2e6232b8ae668b4bac8a (diff)
downloadbusybox-w32-f9ece60e489d3250dac2887a0f0b6ba62b8a158c.tar.gz
busybox-w32-f9ece60e489d3250dac2887a0f0b6ba62b8a158c.tar.bz2
busybox-w32-f9ece60e489d3250dac2887a0f0b6ba62b8a158c.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 git-svn-id: svn://busybox.net/trunk/busybox@7735 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/safe_write.c2
-rw-r--r--libbb/xconnect.c86
2 files changed, 38 insertions, 50 deletions
diff --git a/libbb/safe_write.c b/libbb/safe_write.c
index dd35f35ae..0ac6c2d96 100644
--- a/libbb/safe_write.c
+++ b/libbb/safe_write.c
@@ -26,7 +26,7 @@
26 26
27 27
28 28
29ssize_t safe_write(int fd, void *buf, size_t count) 29ssize_t safe_write(int fd, const void *buf, size_t count)
30{ 30{
31 ssize_t n; 31 ssize_t n;
32 32
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 2945d760f..27459791e 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -11,69 +11,57 @@
11#include <stdlib.h> 11#include <stdlib.h>
12#include <sys/types.h> 12#include <sys/types.h>
13#include <sys/socket.h> 13#include <sys/socket.h>
14#include <errno.h>
14#include <netdb.h> 15#include <netdb.h>
16#include <sys/socket.h>
15#include <netinet/in.h> 17#include <netinet/in.h>
18#include <arpa/inet.h>
16#include "libbb.h" 19#include "libbb.h"
17 20
18int xconnect(const char *host, const char *port) 21int bb_getport(char *port)
19{ 22{
20#ifdef CONFIG_FEATURE_IPV6 23 int port_nr;
21 struct addrinfo hints; 24 char *endptr;
22 struct addrinfo *res; 25 struct servent *tserv;
23 struct addrinfo *addr_info;
24 int error;
25 int s;
26 26
27 memset(&hints, 0, sizeof(hints)); 27 if (!port) {
28 /* set-up hints structure */ 28 return -1;
29 hints.ai_family = PF_UNSPEC;
30 hints.ai_socktype = SOCK_STREAM;
31 error = getaddrinfo(host, port, &hints, &res);
32 if (error||!res)
33 bb_perror_msg_and_die(gai_strerror(error));
34 addr_info=res;
35 while (res) {
36 s=socket(res->ai_family, res->ai_socktype, res->ai_protocol);
37 if (s<0)
38 {
39 error=s;
40 res=res->ai_next;
41 continue;
42 }
43 /* try to connect() to res->ai_addr */
44 error = connect(s, res->ai_addr, res->ai_addrlen);
45 if (error >= 0)
46 break;
47 close(s);
48 res=res->ai_next;
49 } 29 }
50 freeaddrinfo(addr_info); 30 port_nr=strtol(port, &endptr, 10);
51 if (error < 0) 31 if (errno != 0 || *endptr!='\0' || endptr==port || port_nr < 1 || port_nr > 65536)
52 { 32 {
53 bb_perror_msg_and_die("Unable to connect to remote host (%s)", host); 33 if (port_nr==0 && (tserv = getservbyname(port, "tcp")) != NULL) {
34 port_nr = tserv->s_port;
35 } else {
36 return -1;
37 }
38 } else {
39 port_nr = htons(port_nr);
54 } 40 }
55 return s; 41 return port_nr;
56#else 42}
57 struct sockaddr_in s_addr;
58 int s = socket(AF_INET, SOCK_STREAM, 0);
59 struct servent *tserv;
60 int port_nr=htons(atoi(port));
61 struct hostent * he;
62
63 if (port_nr==0 && (tserv = getservbyname(port, "tcp")) != NULL)
64 port_nr = tserv->s_port;
65 43
66 memset(&s_addr, 0, sizeof(struct sockaddr_in)); 44void bb_lookup_host(struct sockaddr_in *s_in, char *host, char *port)
67 s_addr.sin_family = AF_INET; 45{
68 s_addr.sin_port = port_nr; 46 struct hostent *he;
69 47
48 memset(s_in, 0, sizeof(struct sockaddr_in));
49 s_in->sin_family = AF_INET;
70 he = xgethostbyname(host); 50 he = xgethostbyname(host);
71 memcpy(&s_addr.sin_addr, he->h_addr, sizeof s_addr.sin_addr); 51 memcpy(&(s_in->sin_addr), he->h_addr_list[0], he->h_length);
72 52
73 if (connect(s, (struct sockaddr *)&s_addr, sizeof s_addr) < 0) 53 if (port) {
54 s_in->sin_port=bb_getport(port);
55 }
56}
57
58int xconnect(struct sockaddr_in *s_addr)
59{
60 int s = socket(AF_INET, SOCK_STREAM, 0);
61 if (connect(s, (struct sockaddr_in *)s_addr, sizeof(struct sockaddr_in)) < 0)
74 { 62 {
75 bb_perror_msg_and_die("Unable to connect to remote host (%s)", host); 63 bb_perror_msg_and_die("Unable to connect to remote host (%s)",
64 inet_ntoa(s_addr->sin_addr));
76 } 65 }
77 return s; 66 return s;
78#endif
79} 67}