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