aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-07-03 11:51:44 +0000
committerEric Andersen <andersen@codepoet.org>2002-07-03 11:51:44 +0000
commit0b31586c7113b9b26ca0aeee9247a831b55b308c (patch)
tree7071145eeeea4dd92d18e05fce6d8e710dc67d52 /util-linux
parent51b8bd68bb22b1cc5d95e418813c2f08a194ec2b (diff)
downloadbusybox-w32-0b31586c7113b9b26ca0aeee9247a831b55b308c.tar.gz
busybox-w32-0b31586c7113b9b26ca0aeee9247a831b55b308c.tar.bz2
busybox-w32-0b31586c7113b9b26ca0aeee9247a831b55b308c.zip
A patch from Bart Visscher <magick@linux-fan.com> to add an
xconnect helper routine which does: -address and port resolving -tries to connect to all resolved addresses until connected -uses getaddrinfo, so works for IPv6 too This patch also ports rdate, telnet, and wget to use the new xconnect function. Thanks Bart!
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/rdate.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index 04a76129a..df7d7bbc4 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -39,26 +39,14 @@ static const int RFC_868_BIAS = 2208988800UL;
39 39
40static time_t askremotedate(const char *host) 40static time_t askremotedate(const char *host)
41{ 41{
42 struct hostent *h;
43 struct sockaddr_in s_in;
44 struct servent *tserv;
45 unsigned long int nett, localt; 42 unsigned long int nett, localt;
43 const char *port="37";
46 int fd; 44 int fd;
47 45
48 h = xgethostbyname(host); /* get the IP addr */ 46 if (getservbyname("time", "tcp") != NULL)
49 memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr)); 47 port="time";
50 48
51 s_in.sin_port = htons(37); /* find port # */ 49 fd = xconnect(host, port);
52 if ((tserv = getservbyname("time", "tcp")) != NULL)
53 s_in.sin_port = tserv->s_port;
54
55 s_in.sin_family = AF_INET;
56
57 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */
58 perror_msg_and_die("socket");
59
60 if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) /* connect to time server */
61 perror_msg_and_die("%s", host);
62 50
63 if (read(fd, (void *)&nett, 4) != 4) /* read time from server */ 51 if (read(fd, (void *)&nett, 4) != 4) /* read time from server */
64 error_msg_and_die("%s did not send the complete time", host); 52 error_msg_and_die("%s did not send the complete time", host);