RTIME

Section: Linux Programmer's Manual (3)
Updated: 2020-12-21
Index JM Home Page
 

名前

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

書式

#include <rpc/auth_des.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 で定義された待ち時間の期限が切れた。
 

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース 属性
rtime() Thread safety MT-Safe
 

注意

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

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

バグ

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>

static int use_tcp = 0; static 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 プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

include, struct, RTIME, rtime, 時刻, timeout, エラー, time, timeval, int

Linux マニュアル 一覧

[man1] [man2] [man3] [man4] [man5] [man6] [man7] [man8]
[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m] [n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

 

Index

名前
書式
説明
返り値
エラー
属性
注意
バグ
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 12:08:39 GMT, June 11, 2022