X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=util-linux%2Frdate.c;h=c9a7ffeabe2970ae7ce5ca664c6043fa0fd8b3b2;hb=50547c07451d07178eeb64e7d8637952b427bd4c;hp=3c3b152a22657462375cd673a4d479255fb6c0cc;hpb=cad5364599eb5062d59e0c397ed638ddd61a8d5d;p=oweals%2Fbusybox.git diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 3c3b152a2..c9a7ffeab 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -32,23 +32,33 @@ #include #include #include +#include + #include "busybox.h" static const int RFC_868_BIAS = 2208988800UL; +static void socket_timeout(int sig) +{ + bb_error_msg_and_die("timeout connecting to time server"); +} + static time_t askremotedate(const char *host) { unsigned long int nett, localt; - const char *port="37"; + struct sockaddr_in s_in; int fd; - if (getservbyname("time", "tcp") != NULL) - port="time"; + bb_lookup_host(&s_in, host, "time"); + + /* Add a timeout for dead or non accessable servers */ + alarm(10); + signal(SIGALRM, socket_timeout); - fd = xconnect(host, port); + fd = xconnect(&s_in); - if (read(fd, (void *)&nett, 4) != 4) /* read time from server */ + if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ bb_error_msg_and_die("%s did not send the complete time", host); close(fd);