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 2003-04-04 "sunrpc" "RPC time function"
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 midnight 1900-01-01,
23 and this function subtracts the appropriate constant in order to
24 convert the result to seconds since midnight 1970-01-01, the Unix epoch.
28 is non-NULL, the udp/time socket (port 37) is used.
29 Otherwise, the tcp/time socket (port 37) is used.
31 On success, 0 is returned, and the obtained 32-bit time value is stored in
33 In case of error \-1 is returned, and
37 All errors for underlying functions
46 The number of returned bytes is not 4.
49 The waiting time as defined in timeout has expired.
51 This example requires that port 37 is up and open. You may check
52 that the time entry within
56 The program connects to a computer called 'linux'.
57 Using 'localhost' does not work.
58 The result is the localtime of the computer 'linux'.
65 #include <rpc/auth_des.h>
69 char *servername = "linux";
72 struct sockaddr_in name;
73 struct rpc_timeval time1 = {0,0};
74 struct rpc_timeval timeout = {1,0};
78 memset((char *)&name, 0, sizeof(name));
80 hent = gethostbyname(servername);
81 memcpy((char *)&name.sin_addr, hent->h_addr, hent->h_length);
83 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
85 perror("rtime error");
87 printf("%s", ctime((time_t *) &time1.tv_sec));
93 Only IPV4 is supported.
97 versions only support TCP. Try the above example program with
101 Libc5 uses the prototype
103 int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
108 .IR <rpc/auth_des.h> .
112 in glibc <= 2.2.5 does not work properly on 64bit machines.