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