1RTIME(3)                   Linux Programmer's Manual                  RTIME(3)
2
3
4

NAME

6       rtime - get time from a remote machine
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

41       For   an   explanation   of   the  terms  used  in  this  section,  see
42       attributes(7).
43
44       ┌──────────┬───────────────┬─────────┐
45Interface Attribute     Value   
46       ├──────────┼───────────────┼─────────┤
47rtime()   │ Thread safety │ MT-Safe │
48       └──────────┴───────────────┴─────────┘

NOTES

50       Only IPv4 is supported.
51
52       Some in.timed versions support only TCP.  Try the example program  with
53       use_tcp set to 1.
54
55       Libc5 uses the prototype
56
57           int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
58
59       and requires <sys/time.h> instead of <rpc/auth_des.h>.
60

BUGS

62       rtime()  in  glibc  2.2.5  and earlier does not work properly on 64-bit
63       machines.
64

EXAMPLE

66       This example requires that port 37 is up and open.  You may check  that
67       the time entry within /etc/inetd.conf is not commented out.
68
69       The  program  connects to a computer called "linux".  Using "localhost"
70       does not work.  The result is the localtime of the computer "linux".
71
72       #include <stdio.h>
73       #include <stdlib.h>
74       #include <errno.h>
75       #include <string.h>
76       #include <time.h>
77       #include <rpc/auth_des.h>
78       #include <netdb.h>
79
80       static int use_tcp = 0;
81       static char *servername = "linux";
82
83       int
84       main(void)
85       {
86           struct sockaddr_in name;
87           struct rpc_timeval time1 = {0,0};
88           struct rpc_timeval timeout = {1,0};
89           struct hostent *hent;
90           int ret;
91
92           memset(&name, 0, sizeof(name));
93           sethostent(1);
94           hent = gethostbyname(servername);
95           memcpy(&name.sin_addr, hent->h_addr, hent->h_length);
96
97           ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
98           if (ret < 0)
99               perror("rtime error");
100           else {
101               time_t t = time1.tv_sec;
102               printf("%s\n", ctime(&t));
103           }
104
105           exit(EXIT_SUCCESS);
106       }
107

SEE ALSO

109       ntpdate(1), inetd(8)
110

COLOPHON

112       This page is part of release 4.16 of the Linux  man-pages  project.   A
113       description  of  the project, information about reporting bugs, and the
114       latest    version    of    this    page,    can     be     found     at
115       https://www.kernel.org/doc/man-pages/.
116
117
118
119GNU                               2017-09-15                          RTIME(3)
Impressum