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