man-pages/man3/rtime.3

125 lines
2.9 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
.\" Distributed under GPL
.\" Modified 2003-04-04 Walter Harms
.\" <walter.harms@informatik.uni-oldenburg.de>
.\"
.\" Slightly polished, aeb, 2003-04-06
.\"
.TH RTIME 3 2010-02-25 "GNU" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
rtime \- get time from a remote machine
.SH SYNOPSIS
2007-04-03 15:32:52 +00:00
.nf
2004-11-03 13:51:07 +00:00
.B "#include <rpc/des_crypt.h>"
.sp
2007-04-03 15:32:52 +00:00
.BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
.BI " struct rpc_timeval *" timeout );
.fi
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
This function uses the Time Server Protocol as described in
RFC\ 868 to obtain the time from a remote machine.
2004-11-03 13:51:07 +00:00
.LP
The Time Server Protocol gives the time in seconds since
00:00:00 UTC, 1 Jan 1900,
2004-11-03 13:51:07 +00:00
and this function subtracts the appropriate constant in order to
convert the result to seconds since the
Epoch, 1970-01-01 00:00:00 +0000 (UTC).
2004-11-03 13:51:07 +00:00
.LP
When
.I timeout
is non-NULL, the udp/time socket (port 37) is used.
Otherwise, the tcp/time socket (port 37) is used.
.SH "RETURN VALUE"
On success, 0 is returned, and the obtained 32-bit time value is stored in
.IR timep\->tv_sec .
2005-06-15 14:10:23 +00:00
In case of error \-1 is returned, and
2004-11-03 13:51:07 +00:00
.I errno
is set appropriately.
.SH ERRORS
All errors for underlying functions
.RB ( sendto (2),
.BR poll (2),
.BR recvfrom (2),
.BR connect (2),
.BR read (2))
can occur.
Moreover:
2004-11-03 13:51:07 +00:00
.TP
.B EIO
The number of returned bytes is not 4.
.TP
.B ETIMEDOUT
The waiting time as defined in timeout has expired.
.SH "NOTES"
2009-02-03 08:30:55 +00:00
Only IPv4 is supported.
.LP
Some
.I in.timed
versions only support TCP.
Try the example program with
.I use_tcp
set to 1.
.LP
Libc5 uses the prototype
.br
int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
.br
and requires
.I <sys/time.h>
instead of
.IR <rpc/auth_des.h> .
.SH "BUGS"
.BR rtime ()
in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
2004-11-03 13:51:07 +00:00
.SH "EXAMPLE"
This example requires that port 37 is up and open.
You may check
2004-11-03 13:51:07 +00:00
that the time entry within
.I /etc/inetd.conf
is not commented out.
.br
The program connects to a computer called "linux".
Using "localhost" does not work.
The result is the localtime of the computer "linux".
.sp
2004-11-03 13:51:07 +00:00
.nf
#include <stdio.h>
#include <stdlib.h>
2004-11-03 13:51:07 +00:00
#include <errno.h>
#include <string.h>
#include <time.h>
#include <rpc/auth_des.h>
#include <netdb.h>
int use_tcp = 0;
char *servername = "linux";
int
main(void)
2007-04-05 12:36:57 +00:00
{
2007-04-03 15:32:52 +00:00
struct sockaddr_in name;
struct rpc_timeval time1 = {0,0};
struct rpc_timeval timeout = {1,0};
struct hostent *hent;
int ret;
2004-11-03 13:51:07 +00:00
2007-04-05 12:36:57 +00:00
memset((char *) &name, 0, sizeof(name));
2007-04-03 15:32:52 +00:00
sethostent(1);
hent = gethostbyname(servername);
2007-06-20 21:39:45 +00:00
memcpy((char *) &name.sin_addr, hent\->h_addr, hent\->h_length);
2004-11-03 13:51:07 +00:00
2007-04-03 15:32:52 +00:00
ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
if (ret < 0)
perror("rtime error");
else
2007-04-03 17:54:06 +00:00
printf("%s\\n", ctime((time_t *) &time1.tv_sec));
2004-11-03 13:51:07 +00:00
exit(EXIT_SUCCESS);
2004-11-03 13:51:07 +00:00
}
.fi
.SH "SEE ALSO"
.\" .BR netdate (1),
2004-11-03 13:51:07 +00:00
.BR ntpdate (1),
.\" .BR rdate (1),
2004-11-03 13:51:07 +00:00
.BR inetd (8)