RTIME(3) RPC time(1,2,n) function RTIME(3) NAME rtime - get time(1,2,n) from a remote machine SYNOPSIS #include <rpc(3,5,8)/des_crypt.h> int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep, struct rpc_timeval *timeout(1,3x,3x cbreak)); DESCRIPTION This function uses the Time Server Protocol as described in(1,8) RFC 868 to obtain the time(1,2,n) from a remote machine. The Time Server Protocol gives the time(1,2,n) in(1,8) seconds since midnight 1900-01-01, and this function subtracts the appropriate constant in(1,8) order to convert the result to seconds since midnight 1970-01-01, the Unix epoch. When timeout(1,3x,3x cbreak) is non-NULL, the udp/time(1,2,n) socket(2,7,n) (port 37) is used. Oth- erwise, the tcp/time(1,2,n) socket(2,7,n) (port 37) is used. RETURN VALUE On success, 0 is returned, and the obtained 32-bit time(1,2,n) value is stored in(1,8) timep->tv_sec. In case of error(8,n) -1 is returned, and errno is set(7,n,1 builtins) appropriately. ERRORS All errors for underlying functions (sendto, poll, recvfrom, connect, read(2,n,1 builtins)) can occur. Moreover: EIO The number of returned bytes is not 4. ETIMEDOUT The waiting time(1,2,n) as defined in(1,8) timeout(1,3x,3x cbreak) has expired. EXAMPLE This example requires that port 37 is up and open. You may check that the time(1,2,n) 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 <stdio.h> #include <errno.h> #include <string.h> #include <time.h> #include <rpc(3,5,8)/auth_des.h> #include <netdb.h> int use_tcp = 0; char *servername = "linux"; int main() { struct sockaddr_in name; struct rpc_timeval time1 = {0,0}; struct rpc_timeval timeout(1,3x,3x cbreak) = {1,0}; struct hostent *hent; int ret; memset((char *)&name, 0, sizeof(name)); sethostent(1); hent = gethostbyname(servername); memcpy((char *)&name.sin_addr, hent->h_addr, hent->h_length); ret = rtime(&name, &time1, use_tcp ? NULL : &timeout(1,3x,3x cbreak)); if(3,n) (ret < 0) perror(1,3)("rtime error(8,n)"); else printf(1,3,1 builtins)("%s", ctime((time_t *)&time1.tv_sec)); return 0; } NOTES Only IPV4 is supported. Some in.timed versions only support TCP. Try the above example program with use_tcp set(7,n,1 builtins) to 1. Libc5 uses the prototype int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); and requires <sys/time.h> instead of <rpc(3,5,8)/auth_des.h>. BUGS rtime() in(1,8) glibc <= 2.2.5 does not work properly on 64bit machines. SEE ALSO netdate(1), ntpdate(1), rdate(1), inetd(8) sunrpc 2003-04-04 RTIME(3)