#include <rpc/des_crypt.h>
int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep, struct rpc_timeval *timeout);
TSP выдает время в секундах, начиная с полуночи 1900-01-01, и эта функция вычитает соответствующие константы для приведения результата к секундам, начиная с полуночи 1970-01-01, для Unix epoch.
Когда timeout не равен NULL, используется сокет udp/time (порт 37). Иначе используется сокет tcp/time (порт 37).
#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;
}
Некоторые версии in.timed поддерживают только TCP. Попробуйте использовать приведенный пример с use_tcp равным 1.
Libc5 использует прототип
int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
и требует
<sys/time.h>
вместо
<rpc/auth_des.h>.
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |