1RTIME(3)                       RPC time function                      RTIME(3)
2
3
4

NAME

6       rtime - get time from a remote machine
7

SYNOPSIS

9       #include <rpc/des_crypt.h>
10
11       int  rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep, struct
12       rpc_timeval *timeout);
13
14

DESCRIPTION

16       This function uses the Time Server Protocol as described in RFC 868  to
17       obtain the time from a remote machine.
18
19       The  Time  Server  Protocol  gives  the  time in seconds since midnight
20       1900-01-01, and this function subtracts  the  appropriate  constant  in
21       order  to  convert the result to seconds since midnight 1970-01-01, the
22       Unix epoch.
23
24       When timeout is non-NULL, the udp/time socket (port 37) is used.   Oth‐
25       erwise, the tcp/time socket (port 37) is used.
26

RETURN VALUE

28       On success, 0 is returned, and the obtained 32-bit time value is stored
29       in timep->tv_sec.  In case of error -1 is returned, and  errno  is  set
30       appropriately.
31

ERRORS

33       All errors for underlying functions (sendto(), poll(), recvfrom(), con‐
34       nect(), read()) can occur. Moreover:
35
36       EIO    The number of returned bytes is not 4.
37
38       ETIMEDOUT
39              The waiting time as defined in timeout has expired.
40

EXAMPLE

42       This example requires that port 37 is up and open. You may  check  that
43       the time entry within /etc/inetd.conf is not commented out.
44       The  program  connects to a computer called 'linux'.  Using 'localhost'
45       does not work.  The result is the localtime of the computer 'linux'.
46
47       #include <stdio.h>
48       #include <errno.h>
49       #include <string.h>
50       #include <time.h>
51       #include <rpc/auth_des.h>
52       #include <netdb.h>
53
54       int use_tcp = 0;
55       char *servername = "linux";
56
57       int main() {
58         struct sockaddr_in name;
59         struct rpc_timeval time1 = {0,0};
60         struct rpc_timeval timeout = {1,0};
61         struct hostent *hent;
62         int ret;
63
64         memset((char *)&name, 0, sizeof(name));
65         sethostent(1);
66         hent = gethostbyname(servername);
67         memcpy((char *)&name.sin_addr, hent->h_addr, hent->h_length);
68
69         ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
70         if (ret < 0)
71           perror("rtime error");
72         else
73           printf("%s", ctime((time_t *)&time1.tv_sec));
74
75         return 0;
76       }
77

NOTES

79       Only IPV4 is supported.
80
81       Some in.timed versions only support TCP. Try the above example  program
82       with use_tcp set to 1.
83
84       Libc5 uses the prototype
85       int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
86       and requires <sys/time.h> instead of <rpc/auth_des.h>.
87
88

BUGS

90       rtime() in glibc <= 2.2.5 does not work properly on 64bit machines.
91

SEE ALSO

93       netdate(1), ntpdate(1), rdate(1), inetd(8)
94
95
96
97sunrpc                            2003-04-04                          RTIME(3)
Impressum