summaryrefslogtreecommitdiff
path: root/util-linux/rdate.c
diff options
context:
space:
mode:
authorEric Andersen2002-07-03 11:51:44 +0000
committerEric Andersen2002-07-03 11:51:44 +0000
commit0b31586c7113b9b26ca0aeee9247a831b55b308c (patch)
tree7071145eeeea4dd92d18e05fce6d8e710dc67d52 /util-linux/rdate.c
parent51b8bd68bb22b1cc5d95e418813c2f08a194ec2b (diff)
downloadbusybox-0b31586c7113b9b26ca0aeee9247a831b55b308c.zip
busybox-0b31586c7113b9b26ca0aeee9247a831b55b308c.tar.gz
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/rdate.c')
-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 04a7612..df7d7bb 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -39,26 +39,14 @@ static const int RFC_868_BIAS = 2208988800UL;
static time_t askremotedate(const char *host)
{
- struct hostent *h;
- struct sockaddr_in s_in;
- struct servent *tserv;
unsigned long int nett, localt;
+ const char *port="37";
int fd;
- h = xgethostbyname(host); /* get the IP addr */
- memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
+ if (getservbyname("time", "tcp") != NULL)
+ port="time";
- s_in.sin_port = htons(37); /* find port # */
- if ((tserv = getservbyname("time", "tcp")) != NULL)
- s_in.sin_port = tserv->s_port;
-
- s_in.sin_family = AF_INET;
-
- if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) /* get net connection */
- perror_msg_and_die("socket");
-
- if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) /* connect to time server */
- perror_msg_and_die("%s", host);
+ fd = xconnect(host, port);
if (read(fd, (void *)&nett, 4) != 4) /* read time from server */
error_msg_and_die("%s did not send the complete time", host);