O nás     Inzerce     KontaktSpolehlivé informace o IT již od roku 2011
Nepřehlédněte: Tip: Nové Pozoruhodné IT produkty pro rok 2022
Správa dokumentů
Digitální transformace
Informační systémy
Hlavní rubriky: Informační systémy, Mobilní technologie, Datová centra, Sítě, IT bezpečnost, Software, Hardware, Zkušenosti a názory, Speciály

Pozoruhodné IT produkty 2021
E-knihy o IT zdarma

Odborné IT konference BusinessIT
Manuál Linux
[Linux manuál]

rtime: získejte čas ze vzdáleného stroje

Originální popis anglicky: rtime - get time from a remote machine

Návod, kniha: RPC time function


#include <rpc/des_crypt.h>
int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep, struct rpc_timeval *timeout);


This function uses the Time Server Protocol as described in RFC 868 to obtain the time from a remote machine.
The Time Server Protocol gives the time in seconds since midnight 1900-01-01, and this function subtracts the appropriate constant in order to convert the result to seconds since midnight 1970-01-01, the Unix epoch.
When timeout is non-NULL, the udp/time socket (port 37) is used. Otherwise, the tcp/time socket (port 37) is used.


On success, 0 is returned, and the obtained 32-bit time value is stored in timep->tv_sec. In case of error -1 is returned, and errno is set appropriately.


All errors for underlying functions (sendto, poll, recvfrom, connect, read) can occur. Moreover:
The number of returned bytes is not 4.
The waiting time as defined in timeout has expired.


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 <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <rpc/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,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); if (ret < 0) perror("rtime error"); else printf("%s", ctime((time_t *)&time1.tv_sec));
return 0; }


Only IPV4 is supported.
Some in.timed versions only support TCP. Try the above example program with use_tcp set to 1.
Libc5 uses the prototype
int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
and requires <sys/time.h> instead of <rpc/auth_des.h>.


rtime() in glibc <= 2.2.5 does not work properly on 64bit machines.


netdate(1), ntpdate(1), rdate(1), inetd(8)
2003-04-04 sunrpc
©2011-2022 BusinessIT.cz, ISSN 1805-0522 | Názvy použité v textech mohou být ochrannými známkami příslušných vlastníků.
Provozovatel: Bispiral, s.r.o., kontakt: BusinessIT(at)Bispiral.com | Inzerce: Best Online Media, s.r.o., zuzana@online-media.cz
O vydavateli | Pravidla webu BusinessIT.cz a ochrana soukromí | Používáme účetní program Money S3 | pg(8097)