Debian Codegraph @

upstream/debian-trixie/man3/rtime.3

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