]>
Commit | Line | Data |
---|---|---|
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 | |
10 | rtime \- 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 | |
20 | This function uses the Time Server Protocol as described in | |
21 | RFC 868 to obtain the time from a remote machine. | |
22 | .LP | |
23 | The Time Server Protocol gives the time in seconds since midnight 1900-01-01, | |
24 | and this function subtracts the appropriate constant in order to | |
25 | convert the result to seconds since midnight 1970-01-01, the Unix epoch. | |
26 | .LP | |
27 | When | |
28 | .I timeout | |
29 | is non-NULL, the udp/time socket (port 37) is used. | |
30 | Otherwise, the tcp/time socket (port 37) is used. | |
31 | .SH "RETURN VALUE" | |
32 | On success, 0 is returned, and the obtained 32-bit time value is stored in | |
33 | .IR timep->tv_sec . | |
34 | In case of error -1 is returned, and | |
35 | .I errno | |
36 | is set appropriately. | |
37 | .SH ERRORS | |
38 | All errors for underlying functions (sendto, poll, recvfrom, connect, read) | |
39 | can occur. Moreover: | |
40 | .TP | |
41 | .B EIO | |
42 | The number of returned bytes is not 4. | |
43 | .TP | |
44 | .B ETIMEDOUT | |
45 | The waiting time as defined in timeout has expired. | |
46 | .SH "EXAMPLE" | |
47 | This example requires that port 37 is up and open. You may check | |
48 | that the time entry within | |
49 | .I /etc/inetd.conf | |
50 | is not commented out. | |
51 | .br | |
52 | The program connects to a computer called 'linux'. | |
53 | Using 'localhost' does not work. | |
54 | The 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 | ||
64 | int use_tcp = 0; | |
65 | char *servername = "linux"; | |
66 | ||
67 | int 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" | |
89 | Only IPV4 is supported. | |
90 | .LP | |
91 | Some | |
92 | .I in.timed | |
93 | versions only support TCP. Try the above example program with | |
94 | .I use_tcp | |
95 | set to 1. | |
96 | .LP | |
97 | Libc5 uses the prototype | |
98 | .br | |
99 | int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); | |
100 | .br | |
101 | and requires | |
102 | .I <sys/time.h> | |
103 | instead of | |
104 | .IR <rpc/auth_des.h> . | |
105 | ||
106 | .SH "BUGS" | |
107 | rtime() 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) |