EN JA
RTIME(3)
RTIME(3) Linux Programmer's Manual RTIME(3)

名前

rtime -リモートマシンから時刻を取得する

書式


#include <rpc/des_crypt.h>
 

int rtime(struct sockaddr_in * addrp , struct rpc_timeval * timep ,
struct rpc_timeval * timeout );

説明

この関数は RFC 868 に記述されているタイムサーバプロトコルを使用し、リモートマシンから時刻を取得する。

タイムサーバプロトコルは 00:00:00 UTC, 1 Jan 1900 から秒数を提供するので、この関数は適切な定数値を引くことにより、提供された値を Unix における時刻紀元 (1970-01-01 00:00:00 +0000 (UTC)) から秒数に変換する。

timeout が NULL でない場合、udp/time ソケット (ポート 37) が使用される。それ以外の場合、tcp/time ソケット (ポート 37) が使用される。

返り値

成功した場合は、0 が返されて、得られた 32 ビットの時刻値は timep->tv_sec に格納される。エラーの場合は、-1 が返されて、 errno が適切に設定される。

エラー

内部で使用している関数 ( sendto(2), poll(2), recvfrom(2), connect(2), read(2)) の全てのエラーが起こる可能性がある。更に次のエラーが起こる可能性がある:
EIO
返されたバイト数が 4 バイトでない。
ETIMEDOUT
timeout で定義された待ち時間の期限が切れた。

注意

IPv4 のみがサポートされている。

in.timed のバージョンによっては TCP しかサポートしていないものもある。 use_tcp を 1 に設定して、例にあるプログラムを試すこと。

libc5 はプロトタイプ

 

int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);

 

を使い、 <rpc/auth_des.h> の代わりに <sys/time.h> を必要とする。

バグ

glibc 2.2.5 以前の rtime() は、64 ビットマシンで正確に動作しない。

この例ではポート 37 がアップされてオープンされている必要がある。 /etc/inetd.conf の time エントリがコメントアウトされていないことを確認してほしい。
 
このプログラムは "linux"というコンピュータに接続する。 "localhost"を使った場合は動作しない。結果はコンピュータ "linux"のローカル時刻である。
 

#include <stdio.h>
#include <stdlib.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(void)
{
struct sockaddr_in name;
struct rpc_timeval time1 = {0,0};
struct rpc_timeval timeout = {1,0};
struct hostent *hent;
int ret;


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 {
time_t t = time1.tv_sec;
printf("%s\n", ctime(&t));
}


exit(EXIT_SUCCESS);
}

関連項目

ntpdate(1), inetd(8)

この文書について

この man ページは Linux man-pages プロジェクトのリリース 3.51 の一部である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man-pages/ に書かれている。
2012-08-03 GNU