Changes.old: Add missing entry in 5.13 changelog
[man-pages.git] / man3 / rtime.3
blob9512f92236b67e676fa5bdfdf87d259757c956a9
1 .\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
5 .\" %%%LICENSE_END
6 .\"
7 .\" Modified 2003-04-04 Walter Harms
8 .\" <walter.harms@informatik.uni-oldenburg.de>
9 .\"
10 .\" Slightly polished, aeb, 2003-04-06
11 .\"
12 .TH RTIME 3 2021-03-22 "GNU" "Linux Programmer's Manual"
13 .SH NAME
14 rtime \- get time from a remote machine
15 .SH SYNOPSIS
16 .nf
17 .B "#include <rpc/auth_des.h>"
18 .PP
19 .BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
20 .BI "          struct rpc_timeval *" timeout );
21 .fi
22 .SH DESCRIPTION
23 This function uses the Time Server Protocol as described in
24 RFC\ 868 to obtain the time from a remote machine.
25 .PP
26 The Time Server Protocol gives the time in seconds since
27 00:00:00 UTC, 1 Jan 1900,
28 and this function subtracts the appropriate constant in order to
29 convert the result to seconds since the
30 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
31 .PP
32 When
33 .I timeout
34 is non-NULL, the udp/time socket (port 37) is used.
35 Otherwise, the tcp/time socket (port 37) is used.
36 .SH RETURN VALUE
37 On success, 0 is returned, and the obtained 32-bit time value is stored in
38 .IR timep\->tv_sec .
39 In case of error \-1 is returned, and
40 .I errno
41 is set to indicate the error.
42 .SH ERRORS
43 All errors for underlying functions
44 .RB ( sendto (2),
45 .BR poll (2),
46 .BR recvfrom (2),
47 .BR connect (2),
48 .BR read (2))
49 can occur.
50 Moreover:
51 .TP
52 .B EIO
53 The number of returned bytes is not 4.
54 .TP
55 .B ETIMEDOUT
56 The waiting time as defined in timeout has expired.
57 .SH ATTRIBUTES
58 For an explanation of the terms used in this section, see
59 .BR attributes (7).
60 .ad l
61 .nh
62 .TS
63 allbox;
64 lbx lb lb
65 l l l.
66 Interface       Attribute       Value
68 .BR rtime ()
69 T}      Thread safety   MT-Safe
70 .TE
71 .hy
72 .ad
73 .sp 1
74 .SH NOTES
75 Only IPv4 is supported.
76 .PP
77 Some
78 .I in.timed
79 versions support only TCP.
80 Try the example program with
81 .I use_tcp
82 set to 1.
83 .\" .PP
84 .\" Libc5 uses the prototype
85 .\" .PP
86 .\" .nf
87 .\"    int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
88 .\" .fi
89 .\" .PP
90 .\" and requires
91 .\" .I <sys/time.h>
92 .\" instead of
93 .\" .IR <rpc/auth_des.h> .
94 .SH BUGS
95 .BR rtime ()
96 in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
97 .SH EXAMPLES
98 This example requires that port 37 is up and open.
99 You may check
100 that the time entry within
101 .I /etc/inetd.conf
102 is not commented out.
104 The program connects to a computer called "linux".
105 Using "localhost" does not work.
106 The result is the localtime of the computer "linux".
109 #include <stdio.h>
110 #include <stdlib.h>
111 #include <errno.h>
112 #include <string.h>
113 #include <time.h>
114 #include <rpc/auth_des.h>
115 #include <netdb.h>
117 static int use_tcp = 0;
118 static char *servername = "linux";
121 main(void)
123     struct sockaddr_in name;
124     struct rpc_timeval time1 = {0,0};
125     struct rpc_timeval timeout = {1,0};
126     struct hostent *hent;
127     int ret;
129     memset(&name, 0, sizeof(name));
130     sethostent(1);
131     hent = gethostbyname(servername);
132     memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);
134     ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
135     if (ret < 0)
136         perror("rtime error");
137     else {
138         time_t t = time1.tv_sec;
139         printf("%s\en", ctime(&t));
140     }
142     exit(EXIT_SUCCESS);
145 .SH SEE ALSO
146 .\" .BR netdate (1),
147 .BR ntpdate (1),
148 .\" .BR rdate (1),
149 .BR inetd (8)