]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/rtime.3
unix.7: wfix
[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.\"
5c91a624 12.TH RTIME 3 2014-01-05 "GNU" "Linux Programmer's Manual"
fea681da
MK
13.SH NAME
14rtime \- get time from a remote machine
15.SH SYNOPSIS
b9f02710 16.nf
fea681da
MK
17.B "#include <rpc/des_crypt.h>"
18.sp
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.
fea681da 25.LP
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).
fea681da
MK
31.LP
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.
47297adb 57.SH NOTES
a85e5d51 58Only IPv4 is supported.
2b2581ee
MK
59.LP
60Some
61.I in.timed
33a0ccb2 62versions support only TCP.
ef55629d 63Try the example program with
2b2581ee
MK
64.I use_tcp
65set to 1.
66.LP
67Libc5 uses the prototype
872127dd
MK
68.nf
69
70 int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
71
72.fi
2b2581ee
MK
73and requires
74.I <sys/time.h>
75instead of
76.IR <rpc/auth_des.h> .
47297adb 77.SH BUGS
2b2581ee 78.BR rtime ()
74aace8a 79in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
47297adb 80.SH EXAMPLE
c13182ef
MK
81This example requires that port 37 is up and open.
82You may check
fea681da
MK
83that the time entry within
84.I /etc/inetd.conf
85is not commented out.
3d6efadb 86
84c517a4
MK
87The program connects to a computer called "linux".
88Using "localhost" does not work.
89The result is the localtime of the computer "linux".
c13182ef 90.sp
fea681da
MK
91.nf
92#include <stdio.h>
af9c7ff2 93#include <stdlib.h>
fea681da
MK
94#include <errno.h>
95#include <string.h>
96#include <time.h>
97#include <rpc/auth_des.h>
98#include <netdb.h>
99
5c91a624
MK
100static int use_tcp = 0;
101static char *servername = "linux";
fea681da 102
c13182ef
MK
103int
104main(void)
cf0a9ace 105{
b9f02710
MK
106 struct sockaddr_in name;
107 struct rpc_timeval time1 = {0,0};
108 struct rpc_timeval timeout = {1,0};
109 struct hostent *hent;
110 int ret;
fea681da 111
13f78d96 112 memset(&name, 0, sizeof(name));
b9f02710
MK
113 sethostent(1);
114 hent = gethostbyname(servername);
13f78d96 115 memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);
fea681da 116
b9f02710
MK
117 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
118 if (ret < 0)
119 perror("rtime error");
b63b27da
MK
120 else {
121 time_t t = time1.tv_sec;
122 printf("%s\\n", ctime(&t));
123 }
fea681da 124
5bc8c34c 125 exit(EXIT_SUCCESS);
fea681da
MK
126}
127.fi
47297adb 128.SH SEE ALSO
c789ed87 129.\" .BR netdate (1),
fea681da 130.BR ntpdate (1),
c789ed87 131.\" .BR rdate (1),
fea681da 132.BR inetd (8)