227 lines
6.3 KiB
HTML
227 lines
6.3 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of RTIME</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>RTIME</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
rtime - get time from a remote machine
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/rpc/auth_des.h">rpc/auth_des.h</A>></B>
|
|
|
|
<B>int rtime(struct sockaddr_in *</B><I>addrp</I><B>, struct rpc_timeval *</B><I>timep</I><B>,</B>
|
|
<B> struct rpc_timeval *</B><I>timeout</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
This function uses the Time Server Protocol as described in
|
|
RFC 868 to obtain the time from a remote machine.
|
|
<P>
|
|
|
|
The Time Server Protocol gives the time in seconds since
|
|
00:00:00 UTC, 1 Jan 1900,
|
|
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).
|
|
<P>
|
|
|
|
When
|
|
<I>timeout</I>
|
|
|
|
is non-NULL, the udp/time socket (port 37) is used.
|
|
Otherwise, the tcp/time socket (port 37) is used.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, 0 is returned, and the obtained 32-bit time value is stored in
|
|
<I>timep->tv_sec</I>.
|
|
|
|
In case of error -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
All errors for underlying functions
|
|
(<B><A HREF="/cgi-bin/man/man2html?2+sendto">sendto</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+poll">poll</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+recvfrom">recvfrom</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+connect">connect</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2))
|
|
|
|
can occur.
|
|
Moreover:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EIO</B>
|
|
|
|
<DD>
|
|
The number of returned bytes is not 4.
|
|
<DT id="2"><B>ETIMEDOUT</B>
|
|
|
|
<DD>
|
|
The waiting time as defined in timeout has expired.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>rtime</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Only IPv4 is supported.
|
|
<P>
|
|
|
|
Some
|
|
<I>in.timed</I>
|
|
|
|
versions support only TCP.
|
|
Try the example program with
|
|
<I>use_tcp</I>
|
|
|
|
set to 1.
|
|
<P>
|
|
|
|
Libc5 uses the prototype
|
|
<P>
|
|
|
|
<PRE>
|
|
int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
and requires
|
|
<I><<A HREF="file:///usr/include/sys/time.h">sys/time.h</A>></I>
|
|
|
|
instead of
|
|
<I><<A HREF="file:///usr/include/rpc/auth_des.h">rpc/auth_des.h</A>></I>.
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
<B>rtime</B>()
|
|
|
|
in glibc 2.2.5 and earlier does not work properly on 64-bit machines.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
This example requires that port 37 is up and open.
|
|
You may check
|
|
that the time entry within
|
|
<I>/etc/inetd.conf</I>
|
|
|
|
is not commented out.
|
|
<P>
|
|
|
|
The program connects to a computer called "linux".
|
|
Using "localhost" does not work.
|
|
The result is the localtime of the computer "linux".
|
|
<P>
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/errno.h">errno.h</A>>
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
#include <<A HREF="file:///usr/include/time.h">time.h</A>>
|
|
#include <<A HREF="file:///usr/include/rpc/auth_des.h">rpc/auth_des.h</A>>
|
|
#include <<A HREF="file:///usr/include/netdb.h">netdb.h</A>>
|
|
<P>
|
|
static int use_tcp = 0;
|
|
static char *servername = "linux";
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct sockaddr_in name;
|
|
<BR> struct rpc_timeval time1 = {0,0};
|
|
<BR> struct rpc_timeval timeout = {1,0};
|
|
<BR> struct hostent *hent;
|
|
<BR> int ret;
|
|
<P>
|
|
<BR> memset(&name, 0, sizeof(name));
|
|
<BR> <A HREF="/cgi-bin/man/man2html?1+sethostent">sethostent</A>(1);
|
|
<BR> hent = gethostbyname(servername);
|
|
<BR> memcpy(&name.sin_addr, hent->h_addr, hent->h_length);
|
|
<P>
|
|
<BR> ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
|
|
<BR> if (ret < 0)
|
|
<BR> perror("rtime error");
|
|
<BR> else {
|
|
<BR> time_t t = time1.tv_sec;
|
|
<BR> printf("%s\n", ctime(&t));
|
|
<BR> }
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ntpdate">ntpdate</A></B>(1),
|
|
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+inetd">inetd</A></B>(8)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAI">BUGS</A><DD>
|
|
<DT id="11"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:54 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|