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 to
29       indicate the error.
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       └────────────────────────────────────────────┴───────────────┴─────────┘
49

NOTES

51       Only IPv4 is supported.
52
53       Some in.timed versions support only TCP.  Try the example program  with
54       use_tcp set to 1.
55

BUGS

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

EXAMPLES

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

SEE ALSO

104       ntpdate(1), inetd(8)
105

COLOPHON

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