| 1 |
'\" t |
| 2 |
.\" Copyright 2003, Walter Harms <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: GPL-1.0-or-later |
| 6 |
.\" |
| 7 |
.TH rtime 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
rtime \- get time from a remote machine |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B "#include <rpc/auth_des.h>" |
| 16 |
.P |
| 17 |
.BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep , |
| 18 |
.BI " struct rpc_timeval *" timeout ); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
This function uses the Time Server Protocol as described in |
| 22 |
RFC\ 868 to obtain the time from a remote machine. |
| 23 |
.P |
| 24 |
The Time Server Protocol gives the time in seconds since |
| 25 |
00:00:00 UTC, 1 Jan 1900, |
| 26 |
and this function subtracts the appropriate constant in order to |
| 27 |
convert the result to seconds since the |
| 28 |
Epoch, 1970-01-01 00:00:00 +0000 (UTC). |
| 29 |
.P |
| 30 |
When |
| 31 |
.I timeout |
| 32 |
is non-NULL, the udp/time socket (port 37) is used. |
| 33 |
Otherwise, the tcp/time socket (port 37) is used. |
| 34 |
.SH RETURN VALUE |
| 35 |
On success, 0 is returned, and the obtained 32-bit time value is stored in |
| 36 |
.IR timep\->tv_sec . |
| 37 |
In case of error \-1 is returned, and |
| 38 |
.I errno |
| 39 |
is set to indicate the error. |
| 40 |
.SH ERRORS |
| 41 |
All errors for underlying functions |
| 42 |
.RB ( sendto (2), |
| 43 |
.BR poll (2), |
| 44 |
.BR recvfrom (2), |
| 45 |
.BR connect (2), |
| 46 |
.BR read (2)) |
| 47 |
can occur. |
| 48 |
Moreover: |
| 49 |
.TP |
| 50 |
.B EIO |
| 51 |
The number of returned bytes is not 4. |
| 52 |
.TP |
| 53 |
.B ETIMEDOUT |
| 54 |
The waiting time as defined in timeout has expired. |
| 55 |
.SH ATTRIBUTES |
| 56 |
For an explanation of the terms used in this section, see |
| 57 |
.BR attributes (7). |
| 58 |
.TS |
| 59 |
allbox; |
| 60 |
lbx lb lb |
| 61 |
l l l. |
| 62 |
Interface Attribute Value |
| 63 |
T{ |
| 64 |
.na |
| 65 |
.nh |
| 66 |
.BR rtime () |
| 67 |
T} Thread safety MT-Safe |
| 68 |
.TE |
| 69 |
.SH NOTES |
| 70 |
Only IPv4 is supported. |
| 71 |
.P |
| 72 |
Some |
| 73 |
.I in.timed |
| 74 |
versions support only TCP. |
| 75 |
Try the example program with |
| 76 |
.I use_tcp |
| 77 |
set to 1. |
| 78 |
.\" .P |
| 79 |
.\" Libc5 uses the prototype |
| 80 |
.\" .P |
| 81 |
.\" .nf |
| 82 |
.\" int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); |
| 83 |
.\" .fi |
| 84 |
.\" .P |
| 85 |
.\" and requires |
| 86 |
.\" .I <sys/time.h> |
| 87 |
.\" instead of |
| 88 |
.\" .IR <rpc/auth_des.h> . |
| 89 |
.SH BUGS |
| 90 |
.BR rtime () |
| 91 |
in glibc 2.2.5 and earlier does not work properly on 64-bit machines. |
| 92 |
.SH EXAMPLES |
| 93 |
This example requires that port 37 is up and open. |
| 94 |
You may check |
| 95 |
that the time entry within |
| 96 |
.I /etc/inetd.conf |
| 97 |
is not commented out. |
| 98 |
.P |
| 99 |
The program connects to a computer called "linux". |
| 100 |
Using "localhost" does not work. |
| 101 |
The result is the localtime of the computer "linux". |
| 102 |
.P |
| 103 |
.\" SRC BEGIN (rtime.c) |
| 104 |
.EX |
| 105 |
#include <errno.h> |
| 106 |
#include <netdb.h> |
| 107 |
#include <stdio.h> |
| 108 |
#include <stdlib.h> |
| 109 |
#include <string.h> |
| 110 |
#include <time.h> |
| 111 |
\& |
| 112 |
#include <rpc/auth_des.h> |
| 113 |
\& |
| 114 |
static int use_tcp = 0; |
| 115 |
static const char servername[] = "linux"; |
| 116 |
\& |
| 117 |
int |
| 118 |
main(void) |
| 119 |
{ |
| 120 |
int ret; |
| 121 |
time_t t; |
| 122 |
struct hostent *hent; |
| 123 |
struct rpc_timeval time1 = {0, 0}; |
| 124 |
struct rpc_timeval timeout = {1, 0}; |
| 125 |
struct sockaddr_in name; |
| 126 |
\& |
| 127 |
memset(&name, 0, sizeof(name)); |
| 128 |
sethostent(1); |
| 129 |
hent = gethostbyname(servername); |
| 130 |
memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length); |
| 131 |
\& |
| 132 |
ret = rtime(&name, &time1, use_tcp ? NULL : &timeout); |
| 133 |
if (ret < 0) |
| 134 |
perror("rtime error"); |
| 135 |
else { |
| 136 |
t = time1.tv_sec; |
| 137 |
printf("%s\[rs]n", ctime(&t)); |
| 138 |
} |
| 139 |
\& |
| 140 |
exit(EXIT_SUCCESS); |
| 141 |
} |
| 142 |
.EE |
| 143 |
.\" SRC END |
| 144 |
.SH SEE ALSO |
| 145 |
.\" .BR netdate (1), |
| 146 |
.BR ntpdate (1), |
| 147 |
.\" .BR rdate (1), |
| 148 |
.BR inetd (8) |