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 or‐
20       der 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 at‐
42       tributes(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

BUGS

56       rtime() in glibc 2.2.5 and earlier does not work properly on 64-bit ma‐
57       chines.
58

EXAMPLES

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

SEE ALSO

103       ntpdate(1), inetd(8)
104

COLOPHON

106       This page is part of release 5.10 of the Linux  man-pages  project.   A
107       description  of  the project, information about reporting bugs, and the
108       latest    version    of    this    page,    can     be     found     at
109       https://www.kernel.org/doc/man-pages/.
110
111
112
113GNU                               2020-12-21                          RTIME(3)
Impressum