rtimeのヘルプ・マニュアル
日本語 英語
rtime --help
man rtime
RTIME(3) Linux Programmer’s Manual RTIME(3)
名前
rtime - リモートマシンから時刻を取得する
書式
#include
int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep,
struct rpc_timeval *timeout);
説明
この関数は RFC 868 に記述されているタイムサーバプロトコルを使用し、リモ
ートマシンから時刻を取得する。
タイムサーバプロトコルは 00:00:00 UTC, 1 Jan 1900 から秒数を提供する の
で 、 こ の 関数は適切な定数値を引くことにより、提供された値を 00:00:00
UTC, 1 Jan 1970 (Unix における紀元) から秒数に変換する。
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 *);
を使い、 の代わりに を必要とする。
バグ
glibc 2.2.5 以前の rtime() は、64 ビットマシンで正確に動作しない。
例
この例ではポート 37 がアップされてオープンされてい る 必 要 が あ る 。
/etc/inetd.conf の time エントリがコメントアウトされていないことを確認
してほしい。
このプログラムは "linux" というコンピュータに接続する。 "localhost" を
使った場合は動作しない。結果はコンピュータ "linux" のローカル時刻である
。
#include
#include
#include
#include
#include
#include
#include
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((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\n", ctime((time_t *) &time1.tv_sec));
exit(EXIT_SUCCESS);
}
関連項目
ntpdate(1), inetd(8)
GNU 2008-07-12 RTIME(3)
RTIME(3) Linux Programmer’s Manual RTIME(3)
NAME
rtime - get time from a remote machine
SYNOPSIS
#include
int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep,
struct rpc_timeval *timeout);
DESCRIPTION
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 00:00:00 UTC,
1 Jan 1900, and this function subtracts the appropriate constant in
order to convert the result to seconds since 00:00:00 UTC, 1 Jan 1970,
the Unix Epoch.
When timeout is non-NULL, the udp/time socket (port 37) is used. Oth-
erwise, the tcp/time socket (port 37) is used.
RETURN VALUE
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.
ERRORS
All errors for underlying functions (sendto(2), poll(2), recvfrom(2),
connect(2), read(2)) can occur. Moreover:
EIO The number of returned bytes is not 4.
ETIMEDOUT
The waiting time as defined in timeout has expired.
NOTES
Only IPv4 is supported.
Some in.timed versions only support TCP. Try the example program with
use_tcp set to 1.
Libc5 uses the prototype
int rtime(struct sockaddr_in *, struct timeval *, struct timeval *);
and requires instead of .
BUGS
rtime() in glibc 2.2.5 and earlier does not work properly on 64-bit
machines.
EXAMPLE
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
#include
#include
#include
#include
#include
#include
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((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\n", ctime((time_t *) &time1.tv_sec));
exit(EXIT_SUCCESS);
}
SEE ALSO
ntpdate(1), inetd(8)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2008-07-12 RTIME(3)