1 .\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\" Distributed under GPL
3 .\" Modified 2003-04-04 Walter Harms
4 .\" <walter.harms@informatik.uni-oldenburg.de>
6 .\" Slightly polished, aeb, 2003-04-06
8 .TH RTIME 3 2008-07-12 "GNU" "Linux Programmer's Manual"
10 rtime \- get time from a remote machine
13 .B "#include <rpc/des_crypt.h>"
15 .BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
16 .BI " struct rpc_timeval *" timeout );
19 This function uses the Time Server Protocol as described in
20 RFC\ 868 to obtain the time from a remote machine.
22 The Time Server Protocol gives the time in seconds since
23 00:00:00 UTC, 1 Jan 1900,
24 and this function subtracts the appropriate constant in order to
25 convert the result to seconds since the Epoch,
26 1970-01-01 00:00:00 +0000 (UTC).
30 is non-NULL, the udp/time socket (port 37) is used.
31 Otherwise, the tcp/time socket (port 37) is used.
33 On success, 0 is returned, and the obtained 32-bit time value is stored in
35 In case of error \-1 is returned, and
39 All errors for underlying functions
49 The number of returned bytes is not 4.
52 The waiting time as defined in timeout has expired.
54 Only IPv4 is supported.
58 versions only support TCP.
59 Try the example program with
63 Libc5 uses the prototype
65 int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
70 .IR <rpc/auth_des.h> .
73 in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
75 This example requires that port 37 is up and open.
77 that the time entry within
81 The program connects to a computer called "linux".
82 Using "localhost" does not work.
83 The result is the localtime of the computer "linux".
91 #include <rpc/auth_des.h>
95 char *servername = "linux";
100 struct sockaddr_in name;
101 struct rpc_timeval time1 = {0,0};
102 struct rpc_timeval timeout = {1,0};
103 struct hostent *hent;
106 memset((char *) &name, 0, sizeof(name));
108 hent = gethostbyname(servername);
109 memcpy((char *) &name.sin_addr, hent\->h_addr, hent\->h_length);
111 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
113 perror("rtime error");
115 printf("%s\\n", ctime((time_t *) &time1.tv_sec));