Use port 37 by default.
authorMatt Kraai <kraai@debian.org>
Mon, 1 Oct 2001 17:52:14 +0000 (17:52 -0000)
committerMatt Kraai <kraai@debian.org>
Mon, 1 Oct 2001 17:52:14 +0000 (17:52 -0000)
rdate.c
util-linux/rdate.c

diff --git a/rdate.c b/rdate.c
index 50be4de8c2cee0f076a40ba430fcf4c38acdf841..04a76129a3f62d2e199ad042c8d412bc4313deb0 100644 (file)
--- a/rdate.c
+++ b/rdate.c
@@ -46,17 +46,17 @@ static time_t askremotedate(const char *host)
        int fd;
 
        h = xgethostbyname(host);         /* get the IP addr */
+       memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
+
+       s_in.sin_port = htons(37);                /* find port # */
+       if ((tserv = getservbyname("time", "tcp")) != NULL)
+               s_in.sin_port = tserv->s_port;
 
-       if ((tserv = getservbyname("time", "tcp")) == NULL)   /* find port # */
-               perror_msg_and_die("time");
+       s_in.sin_family = AF_INET;
 
        if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)    /* get net connection */
                perror_msg_and_die("socket");
 
-       memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
-       s_in.sin_port= tserv->s_port;
-       s_in.sin_family = AF_INET;
-
        if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0)      /* connect to time server */
                perror_msg_and_die("%s", host);
 
index 50be4de8c2cee0f076a40ba430fcf4c38acdf841..04a76129a3f62d2e199ad042c8d412bc4313deb0 100644 (file)
@@ -46,17 +46,17 @@ static time_t askremotedate(const char *host)
        int fd;
 
        h = xgethostbyname(host);         /* get the IP addr */
+       memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
+
+       s_in.sin_port = htons(37);                /* find port # */
+       if ((tserv = getservbyname("time", "tcp")) != NULL)
+               s_in.sin_port = tserv->s_port;
 
-       if ((tserv = getservbyname("time", "tcp")) == NULL)   /* find port # */
-               perror_msg_and_die("time");
+       s_in.sin_family = AF_INET;
 
        if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)    /* get net connection */
                perror_msg_and_die("socket");
 
-       memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
-       s_in.sin_port= tserv->s_port;
-       s_in.sin_family = AF_INET;
-
        if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0)      /* connect to time server */
                perror_msg_and_die("%s", host);