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