]>
Commit | Line | Data |
---|---|---|
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 | .\" | |
8660ef9f | 12 | .TH RTIME 3 2014-05-28 "GNU" "Linux Programmer's Manual" |
fea681da MK |
13 | .SH NAME |
14 | rtime \- get time from a remote machine | |
15 | .SH SYNOPSIS | |
b9f02710 | 16 | .nf |
7362924b | 17 | .B "#include <rpc/auth_des.h>" |
fea681da | 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 |
23 | This function uses the Time Server Protocol as described in | |
331da7c3 | 24 | RFC\ 868 to obtain the time from a remote machine. |
fea681da | 25 | .LP |
ef55629d MK |
26 | The Time Server Protocol gives the time in seconds since |
27 | 00:00:00 UTC, 1 Jan 1900, | |
fea681da | 28 | and this function subtracts the appropriate constant in order to |
ef2e0660 MK |
29 | convert the result to seconds since the |
30 | Epoch, 1970-01-01 00:00:00 +0000 (UTC). | |
fea681da MK |
31 | .LP |
32 | When | |
33 | .I timeout | |
34 | is non-NULL, the udp/time socket (port 37) is used. | |
35 | Otherwise, the tcp/time socket (port 37) is used. | |
47297adb | 36 | .SH RETURN VALUE |
fea681da | 37 | On success, 0 is returned, and the obtained 32-bit time value is stored in |
94e9d9fe | 38 | .IR timep\->tv_sec . |
8729177b | 39 | In case of error \-1 is returned, and |
fea681da MK |
40 | .I errno |
41 | is set appropriately. | |
42 | .SH ERRORS | |
c13182ef | 43 | All 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 |
49 | can occur. |
50 | Moreover: | |
fea681da MK |
51 | .TP |
52 | .B EIO | |
53 | The number of returned bytes is not 4. | |
54 | .TP | |
55 | .B ETIMEDOUT | |
56 | The waiting time as defined in timeout has expired. | |
0dbaa5cc PH |
57 | .SH ATTRIBUTES |
58 | .SS Multithreading (see pthreads(7)) | |
59 | The | |
60 | .BR rtime () | |
61 | function is thread-safe. | |
47297adb | 62 | .SH NOTES |
a85e5d51 | 63 | Only IPv4 is supported. |
2b2581ee MK |
64 | .LP |
65 | Some | |
66 | .I in.timed | |
33a0ccb2 | 67 | versions support only TCP. |
ef55629d | 68 | Try the example program with |
2b2581ee MK |
69 | .I use_tcp |
70 | set to 1. | |
71 | .LP | |
72 | Libc5 uses the prototype | |
872127dd MK |
73 | .nf |
74 | ||
75 | int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); | |
76 | ||
77 | .fi | |
2b2581ee MK |
78 | and requires |
79 | .I <sys/time.h> | |
80 | instead of | |
81 | .IR <rpc/auth_des.h> . | |
47297adb | 82 | .SH BUGS |
2b2581ee | 83 | .BR rtime () |
74aace8a | 84 | in glibc 2.2.5 and earlier does not work properly on 64-bit machines. |
47297adb | 85 | .SH EXAMPLE |
c13182ef MK |
86 | This example requires that port 37 is up and open. |
87 | You may check | |
fea681da MK |
88 | that the time entry within |
89 | .I /etc/inetd.conf | |
90 | is not commented out. | |
3d6efadb | 91 | |
84c517a4 MK |
92 | The program connects to a computer called "linux". |
93 | Using "localhost" does not work. | |
94 | The result is the localtime of the computer "linux". | |
c13182ef | 95 | .sp |
fea681da MK |
96 | .nf |
97 | #include <stdio.h> | |
af9c7ff2 | 98 | #include <stdlib.h> |
fea681da MK |
99 | #include <errno.h> |
100 | #include <string.h> | |
101 | #include <time.h> | |
102 | #include <rpc/auth_des.h> | |
103 | #include <netdb.h> | |
104 | ||
5c91a624 MK |
105 | static int use_tcp = 0; |
106 | static char *servername = "linux"; | |
fea681da | 107 | |
c13182ef MK |
108 | int |
109 | main(void) | |
cf0a9ace | 110 | { |
b9f02710 MK |
111 | struct sockaddr_in name; |
112 | struct rpc_timeval time1 = {0,0}; | |
113 | struct rpc_timeval timeout = {1,0}; | |
114 | struct hostent *hent; | |
115 | int ret; | |
fea681da | 116 | |
13f78d96 | 117 | memset(&name, 0, sizeof(name)); |
b9f02710 MK |
118 | sethostent(1); |
119 | hent = gethostbyname(servername); | |
13f78d96 | 120 | memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length); |
fea681da | 121 | |
b9f02710 MK |
122 | ret = rtime(&name, &time1, use_tcp ? NULL : &timeout); |
123 | if (ret < 0) | |
124 | perror("rtime error"); | |
b63b27da | 125 | else { |
5a6194a4 | 126 | time_t t = time1.tv_sec; |
b63b27da MK |
127 | printf("%s\\n", ctime(&t)); |
128 | } | |
fea681da | 129 | |
5bc8c34c | 130 | exit(EXIT_SUCCESS); |
fea681da MK |
131 | } |
132 | .fi | |
47297adb | 133 | .SH SEE ALSO |
c789ed87 | 134 | .\" .BR netdate (1), |
fea681da | 135 | .BR ntpdate (1), |
c789ed87 | 136 | .\" .BR rdate (1), |
fea681da | 137 | .BR inetd (8) |