OSDN Git Service

e5ed57c3492e23a37f9474b4e34a395612f6487e
[linuxjm/LDP_man-pages.git] / original / man3 / rtime.3
1 .\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
5 .\" %%%LICENSE_END
6 .\"
7 .\" Modified 2003-04-04 Walter Harms
8 .\" <walter.harms@informatik.uni-oldenburg.de>
9 .\"
10 .\" Slightly polished, aeb, 2003-04-06
11 .\"
12 .TH RTIME 3 2014-01-05 "GNU" "Linux Programmer's Manual"
13 .SH NAME
14 rtime \- get time from a remote machine
15 .SH SYNOPSIS
16 .nf
17 .B "#include <rpc/des_crypt.h>"
18 .sp
19 .BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
20 .BI "          struct rpc_timeval *" timeout );
21 .fi
22 .SH DESCRIPTION
23 This function uses the Time Server Protocol as described in
24 RFC\ 868 to obtain the time from a remote machine.
25 .LP
26 The Time Server Protocol gives the time in seconds since
27 00:00:00 UTC, 1 Jan 1900,
28 and this function subtracts the appropriate constant in order to
29 convert the result to seconds since the
30 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
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.
36 .SH RETURN VALUE
37 On success, 0 is returned, and the obtained 32-bit time value is stored in
38 .IR timep\->tv_sec .
39 In case of error \-1 is returned, and
40 .I errno
41 is set appropriately.
42 .SH ERRORS
43 All errors for underlying functions
44 .RB ( sendto (2),
45 .BR poll (2),
46 .BR recvfrom (2),
47 .BR connect (2),
48 .BR read (2))
49 can occur.
50 Moreover:
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.
57 .SH NOTES
58 Only IPv4 is supported.
59 .LP
60 Some
61 .I in.timed
62 versions support only TCP.
63 Try the example program with
64 .I use_tcp
65 set to 1.
66 .LP
67 Libc5 uses the prototype
68 .nf
69
70     int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
71
72 .fi
73 and requires
74 .I <sys/time.h>
75 instead of
76 .IR <rpc/auth_des.h> .
77 .SH BUGS
78 .BR rtime ()
79 in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
80 .SH EXAMPLE
81 This example requires that port 37 is up and open.
82 You may check
83 that the time entry within
84 .I /etc/inetd.conf
85 is not commented out.
86
87 The program connects to a computer called "linux".
88 Using "localhost" does not work.
89 The result is the localtime of the computer "linux".
90 .sp
91 .nf
92 #include <stdio.h>
93 #include <stdlib.h>
94 #include <errno.h>
95 #include <string.h>
96 #include <time.h>
97 #include <rpc/auth_des.h>
98 #include <netdb.h>
99
100 static int use_tcp = 0;
101 static char *servername = "linux";
102
103 int
104 main(void)
105 {
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;
111
112     memset(&name, 0, sizeof(name));
113     sethostent(1);
114     hent = gethostbyname(servername);
115     memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);
116
117     ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
118     if (ret < 0)
119         perror("rtime error");
120     else {
121         time_t t = time1.tv_sec;
122         printf("%s\\n", ctime(&t));
123     }
124
125     exit(EXIT_SUCCESS);
126 }
127 .fi
128 .SH SEE ALSO
129 .\" .BR netdate (1),
130 .BR ntpdate (1),
131 .\" .BR rdate (1),
132 .BR inetd (8)
133 .SH COLOPHON
134 This page is part of release 3.64 of the Linux
135 .I man-pages
136 project.
137 A description of the project,
138 and information about reporting bugs,
139 can be found at
140 \%http://www.kernel.org/doc/man\-pages/.