1 .\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
7 .\" Modified 2003-04-04 Walter Harms
8 .\" <walter.harms@informatik.uni-oldenburg.de>
10 .\" Slightly polished, aeb, 2003-04-06
12 .TH RTIME 3 2012-08-03 "GNU" "Linux Programmer's Manual"
14 rtime \- get time from a remote machine
17 .B "#include <rpc/des_crypt.h>"
19 .BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
20 .BI " struct rpc_timeval *" timeout );
23 This function uses the Time Server Protocol as described in
24 RFC\ 868 to obtain the time from a remote machine.
26 The Time Server Protocol gives the time in seconds since
27 00:00:00 UTC, 1 Jan 1900,
28 and this function subtracts the appropriate constant in order to
29 convert the result to seconds since the
30 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
34 is non-NULL, the udp/time socket (port 37) is used.
35 Otherwise, the tcp/time socket (port 37) is used.
37 On success, 0 is returned, and the obtained 32-bit time value is stored in
39 In case of error \-1 is returned, and
43 All errors for underlying functions
53 The number of returned bytes is not 4.
56 The waiting time as defined in timeout has expired.
58 Only IPv4 is supported.
62 versions support only TCP.
63 Try the example program with
67 Libc5 uses the prototype
69 int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
74 .IR <rpc/auth_des.h> .
77 in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
79 This example requires that port 37 is up and open.
81 that the time entry within
85 The program connects to a computer called "linux".
86 Using "localhost" does not work.
87 The result is the localtime of the computer "linux".
95 #include <rpc/auth_des.h>
99 char *servername = "linux";
104 struct sockaddr_in name;
105 struct rpc_timeval time1 = {0,0};
106 struct rpc_timeval timeout = {1,0};
107 struct hostent *hent;
110 memset(&name, 0, sizeof(name));
112 hent = gethostbyname(servername);
113 memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);
115 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
117 perror("rtime error");
119 time_t t = time1.tv_sec;
120 printf("%s\\n", ctime(&t));