.\" Copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de) .\" Distributed under GPL .\" Modified 2003-04-04 Walter Harms .\" .\" .\" Slightly polished, aeb, 2003-04-06 .\" .\" Japanese Version Copyright (c) 2004 Yuichi SATO .\" all rights reserved. .\" Translated Thu Sep 2 07:40:48 JST 2004 .\" by Yuichi SATO .\" .TH RTIME 3 2010-02-25 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O rtime \- get time from a remote machine rtime \- リモートマシンから時刻を取得する .\"O .SH SYNOPSIS .SH 書式 .nf .B "#include " .sp .BI "int rtime(struct sockaddr_in *" addrp ", struct rpc_timeval *" timep , .BI " struct rpc_timeval *" timeout ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O This function uses the Time Server Protocol as described in .\"O RFC\ 868 to obtain the time from a remote machine. この関数は RFC\ 868 に記述されているタイムサーバプロトコルを使用し、 リモートマシンから時刻を取得する。 .LP .\"O The Time Server Protocol gives the time in seconds since .\"O 00:00:00 UTC, 1 Jan 1900, .\"O and this function subtracts the appropriate constant in order to .\"O convert the result to seconds since the .\"O Epoch, 1970-01-01 00:00:00 +0000 (UTC). タイムサーバプロトコルは 00:00:00 UTC, 1 Jan 1900 から秒数を提供するので、 この関数は適切な定数値を引くことにより、 提供された値を Unix における時刻紀元 (1970-01-01 00:00:00 +0000 (UTC)) から秒数に変換する。 .LP .\"O When .\"O .I timeout .\"O is non-NULL, the udp/time socket (port 37) is used. .I timeout が NULL でない場合、udp/time ソケット (ポート 37) が使用される。 .\"O Otherwise, the tcp/time socket (port 37) is used. それ以外の場合、tcp/time ソケット (ポート 37) が使用される。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, 0 is returned, and the obtained 32-bit time value is stored in .\"O .IR timep\->tv_sec . 成功した場合は、0 が返されて、得られた 32 ビットの時刻値は .I timep\->tv_sec に格納される。 .\"O In case of error \-1 is returned, and .\"O .I errno .\"O is set appropriately. エラーの場合は、\-1 が返されて、 .I errno が適切に設定される。 .\"O .SH ERRORS .SH エラー .\"O All errors for underlying functions .\"O .RB ( sendto (2), .\"O .BR poll (2), .\"O .BR recvfrom (2), .\"O .BR connect (2), .\"O .BR read (2)) .\"O can occur. .\"O Moreover: 内部で使用している関数 .RB ( sendto (2), .BR poll (2), .BR recvfrom (2), .BR connect (2), .BR read (2)) の全てのエラーが起こる可能性がある。 更に次のエラーが起こる可能性がある: .TP .B EIO .\"O The number of returned bytes is not 4. 返されたバイト数が 4 バイトでない。 .TP .B ETIMEDOUT .\"O The waiting time as defined in timeout has expired. timeout で定義された待ち時間の期限が切れた。 .\"O .SH "NOTES" .SH 注意 .\"O Only IPv4 is supported. IPv4 のみがサポートされている。 .LP .\"O Some .\"O .I in.timed .\"O versions only support TCP. .\"O Try the example program with .\"O .I use_tcp .\"O set to 1. .I in.timed のバージョンによっては TCP しかサポートしていないものもある。 .I use_tcp を 1 に設定して、例にあるプログラムを試すこと。 .LP .\"O Libc5 uses the prototype .\"O .br .\"O int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); .\"O .br .\"O and requires .\"O .I .\"O instead of .\"O .IR . libc5 はプロトタイプ .br int rtime(struct sockaddr_in *, struct timeval *, struct timeval *); .br を使い、 .I の代わりに .I を必要とする。 .\"O .SH "BUGS" .SH バグ .\"O .BR rtime () .\"O in glibc and earlier does not work properly on 64-bit machines. glibc 2.2.5 以前の .BR rtime () は、64 ビットマシンで正確に動作しない。 .\"O .SH "EXAMPLE" .SH 例 .\"O This example requires that port 37 is up and open. .\"O You may check .\"O that the time entry within .\"O .I /etc/inetd.conf .\"O is not commented out. この例ではポート 37 がアップされてオープンされている必要がある。 .I /etc/inetd.conf の time エントリがコメントアウトされていないことを確認してほしい。 .br .\"O The program connects to a computer called "linux". .\"O Using "localhost" does not work. .\"O The result is the localtime of the computer "linux". このプログラムは "linux" というコンピュータに接続する。 "localhost" を使った場合は動作しない。 結果はコンピュータ "linux" のローカル時刻である。 .sp .nf #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); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .\" .BR netdate (1), .BR ntpdate (1), .\" .BR rdate (1), .BR inetd (8)