rtime(3)
π rtime(3) β the get-time-from-a-remote-machine girlie π
okay bestie, sit down, hydrate, because we're talking about rtime(3) from the Library Functions Manual, and it lives in the Standard C library (libc, -lc). she's giving β¨ retro networking β¨ and honestly? iconic. no cap.
πΈ NAME πΈ
rtime β get time from a remote machine π°οΈβ¨
π LIBRARY π
Standard C library (libc, -lc). yes queen, she's built in fr fr.
π SYNOPSIS π
#include <rpc/auth_des.h>
int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep,
struct rpc_timeval *timeout);
π¦ DESCRIPTION π¦
so the whole vibe of this function is: it uses the Time Server Protocol, exactly as described in RFC 868, to pull the time off a remote machine. periodt.
here's the little conversion moment you need to know about π : the Time Server Protocol hands you the time as seconds since 00:00:00 UTC, 1 Jan 1900, and this function does the math and subtracts the appropriate constant so you get seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). she's out here converting epochs for you, no cap.
and now the transport tea β:
- when
timeoutis non-NULL, theudp/timesocket (port 37) is used. - otherwise, the
tcp/timesocket (port 37) is used.
main character energy: decide the protocol by whether you passed a timeout or not. iykyk.
β¨ RETURN VALUE β¨
- on success,
0is returned, and the obtained 32-bit time value gets stored intimep->tv_secπ«Ά - in case of error,
-1is returned, anderrnois set to indicate the error π
π ERRORS π
all errors for the underlying functions can occur, bestie β that's sendto(2), poll(2), recvfrom(2), connect(2), read(2). and moreover:
EIOβ the number of returned bytes is not 4. like. it wanted exactly 4. it got not-4. tragic.ETIMEDOUTβ the waiting time as defined intimeouthas expired. she waited. she's done. π
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7).
- Interface:
rtime() - Attribute: Thread safety
- Value:
MT-Safeπ₯
so yeah, thread-safe, we love that for her.
π NOTES π
- only IPv4 is supported. sorry IPv6 girlies, not today π
- some
in.timedversions support only TCP. try the example program withuse_tcpset to1.
π BUGS π
rtime()in glibc 2.2.5 and earlier does not work properly on 64-bit machines. ancient lore, but we're documenting it fr fr. π
β EXAMPLES β
this example requires that port 37 is up and open. you may check that the time entry within /etc/inetd.conf is not commented out π
the program connects to a computer called "linux". using "localhost" does not work. the result is the localtime of the computer "linux".
#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\n", ctime(&t));
}
exit(EXIT_SUCCESS);
}
π SEE ALSO π
ntpdate(1)inetd(8)
and that's the whole page, bestie!! this came from Linux man-pages 6.20, dated 2026-02-08, for rtime(3) β go forth and ask remote machines what time it is, you absolute icon πβ¨π¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-1.0-or-later
- Copyright 2003, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms