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