aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-11 16:50:23 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-11 16:50:23 +0000
commit8e9ccba371480fb1fb3da9235fabdbb7861523c3 (patch)
tree369636a4a765a571e1c6a6ecf2a52ca0131cc90e /util-linux
parent085231fbbad159d2275cbd5ecdcf4732512bb80f (diff)
downloadbusybox-w32-8e9ccba371480fb1fb3da9235fabdbb7861523c3.tar.gz
busybox-w32-8e9ccba371480fb1fb3da9235fabdbb7861523c3.tar.bz2
busybox-w32-8e9ccba371480fb1fb3da9235fabdbb7861523c3.zip
ipv6-ization efforts continue. Few bugs are found,
unknown number likely introduced...
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/rdate.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index 12105953d..ccbf96966 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -8,21 +8,15 @@
8 * Licensed under GPL v2 or later, see file License for details. 8 * Licensed under GPL v2 or later, see file License for details.
9*/ 9*/
10 10
11#include <sys/types.h> 11//#include <sys/socket.h>
12#include <sys/socket.h> 12//#include <netinet/in.h>
13#include <netinet/in.h> 13//#include <netdb.h>
14#include <netdb.h> 14//#include <signal.h>
15#include <stdio.h>
16#include <string.h>
17#include <time.h>
18#include <stdlib.h>
19#include <unistd.h>
20#include <signal.h>
21 15
22#include "busybox.h" 16#include "busybox.h"
23 17
24 18
25static const int RFC_868_BIAS = 2208988800UL; 19enum { RFC_868_BIAS = 2208988800UL };
26 20
27static void socket_timeout(int sig) 21static void socket_timeout(int sig)
28{ 22{
@@ -31,18 +25,14 @@ static void socket_timeout(int sig)
31 25
32static time_t askremotedate(const char *host) 26static time_t askremotedate(const char *host)
33{ 27{
34 unsigned long nett; 28 uint32_t nett;
35 struct sockaddr_in s_in;
36 int fd; 29 int fd;
37 30
38 bb_lookup_host(&s_in, host);
39 s_in.sin_port = bb_lookup_port("time", "tcp", 37);
40
41 /* Add a timeout for dead or inaccessible servers */ 31 /* Add a timeout for dead or inaccessible servers */
42 alarm(10); 32 alarm(10);
43 signal(SIGALRM, socket_timeout); 33 signal(SIGALRM, socket_timeout);
44 34
45 fd = xconnect_tcp_v4(&s_in); 35 fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37));
46 36
47 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ 37 if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
48 bb_error_msg_and_die("%s did not send the complete time", host); 38 bb_error_msg_and_die("%s did not send the complete time", host);
@@ -50,9 +40,9 @@ static time_t askremotedate(const char *host)
50 40
51 /* convert from network byte order to local byte order. 41 /* convert from network byte order to local byte order.
52 * RFC 868 time is the number of seconds 42 * RFC 868 time is the number of seconds
53 * since 00:00 (midnight) 1 January 1900 GMT 43 * since 00:00 (midnight) 1 January 1900 GMT
54 * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT 44 * the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
55 * Subtract the RFC 868 time to get Linux epoch 45 * Subtract the RFC 868 time to get Linux epoch
56 */ 46 */
57 47
58 return ntohl(nett) - RFC_868_BIAS; 48 return ntohl(nett) - RFC_868_BIAS;