#rtime_man_example
Linux comes with a library function name rtime to provide access to a RFC 868 time (port 37) service on a remote server. When successful the rtime function will return the number of seconds since Jan 1st 1900 as determined by the server.
The (Ubuntu) Linux man page for the rtime gives an example snippet of code. Unfortunately the example doesn't compile on Ubuntu 22.04LTS, which is my current version, but will compile with gcc on earlier Ubuntu LTS releases, such as on Ubuntu 14.04 LTS up to 20.04 LTS. For example on 20.04.6LTS the following command line will compile the example code without any warnings or errors.
cc -Wall -o rtime_man_example rtime_man_example.c
On 22.04LTS the first difficulty is that header file rpc/auth_des.h cannot be found. That header file can be found if the compiler invocation is; -
cc -Wall -I /usr/include/tirpc -o rtimeExample rtimeExample.c -ltirpc
Unfortunately the necessary struct definitions are still not available. The Ubuntu 22.04 auth_des.h uses struct timeval rather than struct rpc_timeval. Modifying the struct to timeval allows the compile to succeed but the executable does not succeed in obtaining the time. Initially there is the known requirement to change the server name from "linux" to the name of a server that does exist. Once this is done the code outputs that there has been an I/O error. It doesn't make any difference if the code is modified to change rtime to use TCP rather than UDP as its means of connection.
Falling back to using an older version of Ubuntu the code in rtimeExample.c will work.