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 timeout is non-NULL, the udp/time socket (port 37) is used.
  • otherwise, the tcp/time socket (port 37) is used.

main character energy: decide the protocol by whether you passed a timeout or not. iykyk.

✨ RETURN VALUE ✨

  • on success, 0 is returned, and the obtained 32-bit time value gets stored in timep->tv_sec 🫢
  • in case of error, -1 is returned, and errno is 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 in timeout has 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.timed versions support only TCP. try the example program with use_tcp set to 1.

πŸ› 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 πŸ’œ


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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms