Rechercher une page de manuel
rtime
Langue: ja
Version: 2003-04-04 (fedora - 25/11/07)
Section: 3 (Bibliothèques de fonctions)
名前
rtime - リモートマシンから時刻を取得する書式
#include <rpc/des_crypt.h> int rtime(struct sockaddr_in *addrp, struct rpc_timeval *timep, struct rpc_timeval *timeout);
説明
この関数は RFC 868 に記述されているタイムサーバプロトコルを使用し、 リモートマシンから時刻を取得する。タイムサーバプロトコルは 1900-01-01 の午前 0 時から秒数を提供するので、 この関数は適切な定数値を引くことにより、 提供された値を 1970-01-01 の午前 0 時 (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 *);
を使い、 <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 <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((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); }
関連項目
netdate(1), ntpdate(1), rdate(1), inetd(8)Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre