]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/rtime.3
RFC references are now always writen as "RFC\ nnn" (not "RFC nnn" or
[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.\"
8.TH RTIME 3 2003-04-04 "sunrpc" "RPC time function"
9.SH NAME
10rtime \- get time from a remote machine
11.SH SYNOPSIS
12.sp
13.B "#include <rpc/des_crypt.h>"
14.sp
15.BI "int rtime(struct sockaddr_in *" addrp ,
16.BI "struct rpc_timeval *" timep ,
17.BI "struct rpc_timeval *" timeout );
18.sp
19.SH DESCRIPTION
20This function uses the Time Server Protocol as described in
331da7c3 21RFC\ 868 to obtain the time from a remote machine.
fea681da
MK
22.LP
23The Time Server Protocol gives the time in seconds since midnight 1900-01-01,
24and this function subtracts the appropriate constant in order to
25convert the result to seconds since midnight 1970-01-01, the Unix epoch.
26.LP
27When
28.I timeout
29is non-NULL, the udp/time socket (port 37) is used.
30Otherwise, the tcp/time socket (port 37) is used.
31.SH "RETURN VALUE"
32On success, 0 is returned, and the obtained 32-bit time value is stored in
33.IR timep->tv_sec .
8729177b 34In case of error \-1 is returned, and
fea681da
MK
35.I errno
36is set appropriately.
37.SH ERRORS
38All errors for underlying functions (sendto, poll, recvfrom, connect, read)
39can occur. Moreover:
40.TP
41.B EIO
42The number of returned bytes is not 4.
43.TP
44.B ETIMEDOUT
45The waiting time as defined in timeout has expired.
46.SH "EXAMPLE"
47This example requires that port 37 is up and open. You may check
48that the time entry within
49.I /etc/inetd.conf
50is not commented out.
51.br
52The program connects to a computer called 'linux'.
53Using 'localhost' does not work.
54The result is the localtime of the computer 'linux'.
55.sp
56.nf
57#include <stdio.h>
58#include <errno.h>
59#include <string.h>
60#include <time.h>
61#include <rpc/auth_des.h>
62#include <netdb.h>
63
64int use_tcp = 0;
65char *servername = "linux";
66
67int main() {
68 struct sockaddr_in name;
69 struct rpc_timeval time1 = {0,0};
70 struct rpc_timeval timeout = {1,0};
71 struct hostent *hent;
72 int ret;
73
74 memset((char *)&name, 0, sizeof(name));
75 sethostent(1);
76 hent = gethostbyname(servername);
77 memcpy((char *)&name.sin_addr, hent->h_addr, hent->h_length);
78
79 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
80 if (ret < 0)
81 perror("rtime error");
82 else
83 printf("%s", ctime((time_t *)&time1.tv_sec));
84
85 return 0;
86}
87.fi
88.SH "NOTES"
89Only IPV4 is supported.
90.LP
91Some
92.I in.timed
93versions only support TCP. Try the above example program with
94.I use_tcp
95set to 1.
96.LP
97Libc5 uses the prototype
98.br
99int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
100.br
101and requires
102.I <sys/time.h>
103instead of
104.IR <rpc/auth_des.h> .
105
106.SH "BUGS"
107rtime() in glibc <= 2.2.5 does not work properly on 64bit machines.
108.SH "SEE ALSO"
109.BR netdate (1),
110.BR ntpdate (1),
111.BR rdate (1),
112.BR inetd (8)