summaryrefslogtreecommitdiffstats
path: root/upstream/opensuse-leap-15-6/man3/rtime.3
blob: 6cade6094abb007cc77e13d4322177c156a204af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'\" t
.\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de)
.\"
.\" SPDX-License-Identifier: GPL-1.0-or-later
.\"
.\" Modified 2003-04-04 Walter Harms
.\" <walter.harms@informatik.uni-oldenburg.de>
.\"
.\" Slightly polished, aeb, 2003-04-06
.\"
.TH rtime 3 2022-12-15 "Linux man-pages 6.04"
.SH NAME
rtime \- get time from a remote machine
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B "#include <rpc/auth_des.h>"
.PP
.BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep ,
.BI "          struct rpc_timeval *" timeout );
.fi
.SH DESCRIPTION
This function uses the Time Server Protocol as described in
RFC\ 868 to obtain the time from a remote machine.
.PP
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).
.PP
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 .
In case of error \-1 is returned, and
.I errno
is set to indicate the error.
.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:
.TP
.B EIO
The number of returned bytes is not 4.
.TP
.B ETIMEDOUT
The waiting time as defined in timeout has expired.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.ad l
.nh
.TS
allbox;
lbx lb lb
l l l.
Interface	Attribute	Value
T{
.BR rtime ()
T}	Thread safety	MT-Safe
.TE
.hy
.ad
.sp 1
.SH NOTES
Only IPv4 is supported.
.PP
Some
.I in.timed
versions support only TCP.
Try the example program with
.I use_tcp
set to 1.
.\" .PP
.\" Libc5 uses the prototype
.\" .PP
.\" .nf
.\"    int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
.\" .fi
.\" .PP
.\" 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.
.SH EXAMPLES
This example requires that port 37 is up and open.
You may check
that the time entry within
.I /etc/inetd.conf
is not commented out.
.PP
The program connects to a computer called "linux".
Using "localhost" does not work.
The result is the localtime of the computer "linux".
.PP
.\" SRC BEGIN (rtime.c)
.EX
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <rpc/auth_des.h>

static int use_tcp = 0;
static const char servername[] = "linux";

int
main(void)
{
    int                 ret;
    time_t              t;
    struct hostent      *hent;
    struct rpc_timeval  time1 = {0, 0};
    struct rpc_timeval  timeout = {1, 0};
    struct sockaddr_in  name;

    memset(&name, 0, sizeof(name));
    sethostent(1);
    hent = gethostbyname(servername);
    memcpy(&name.sin_addr, hent\->h_addr, hent\->h_length);

    ret = rtime(&name, &time1, use_tcp ? NULL : &timeout);
    if (ret < 0)
        perror("rtime error");
    else {
        t = time1.tv_sec;
        printf("%s\en", ctime(&t));
    }

    exit(EXIT_SUCCESS);
}
.EE
.\" SRC END
.SH SEE ALSO
.\" .BR netdate (1),
.BR ntpdate (1),
.\" .BR rdate (1),
.BR inetd (8)