]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rtime.3
stime.2, time.2, utimensat.2, ctime.3, difftime.3, ftime.3, getspnam.3, mq_receive...
[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 2008-07-12 "GNU" "Linux Programmer's Manual"
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
23 00:00:00 UTC, 1 Jan 1900,
24 and this function subtracts the appropriate constant in order to
25 convert the result to seconds since the Epoch,
26 1970-01-01 00:00:00 +0000 (UTC).
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
34 .IR timep\->tv_sec .
35 In case of error \-1 is returned, and
36 .I errno
37 is set appropriately.
38 .SH ERRORS
39 All errors for underlying functions
40 .RB ( sendto (2),
41 .BR poll (2),
42 .BR recvfrom (2),
43 .BR connect (2),
44 .BR read (2))
45 can occur.
46 Moreover:
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.
53 .SH "NOTES"
54 Only IPv4 is supported.
55 .LP
56 Some
57 .I in.timed
58 versions only support TCP.
59 Try the example program with
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 ()
73 in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
74 .SH "EXAMPLE"
75 This example requires that port 37 is up and open.
76 You may check
77 that the time entry within
78 .I /etc/inetd.conf
79 is not commented out.
80 .br
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".
84 .sp
85 .nf
86 #include <stdio.h>
87 #include <stdlib.h>
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
97 int
98 main(void)
99 {
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;
105
106 memset((char *) &name, 0, sizeof(name));
107 sethostent(1);
108 hent = gethostbyname(servername);
109 memcpy((char *) &name.sin_addr, hent\->h_addr, hent\->h_length);
110
111 ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
112 if (ret < 0)
113 perror("rtime error");
114 else
115 printf("%s\\n", ctime((time_t *) &time1.tv_sec));
116
117 exit(EXIT_SUCCESS);
118 }
119 .fi
120 .SH "SEE ALSO"
121 .\" .BR netdate (1),
122 .BR ntpdate (1),
123 .\" .BR rdate (1),
124 .BR inetd (8)