gethostidのヘルプ・マニュアル
日本語 英語
gethostid --help
man gethostid
GETHOSTID(3) Linux Programmer’s Manual GETHOSTID(3)
名前
gethostid, sethostid - 現在のホストの固有の識別子を取得/設定する
書式
#include
long gethostid(void);
int sethostid(long hostid);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
sethostid(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
説明
gethostid() と sethostid() は、それぞれ、現在使用しているホストに固有の
32 ビットの識別子の取得/設定を行う。この 32 ビットの識別子は、現在存 在
し て い る全ての Unix システムの中で唯一になるように決められる。通常は
gethostbyname(3) により返されるローカルマシンの Internet アドレスが代わ
りに使用され、普通は識別子をあえて設定する必要はない。
sethostid() はスーパーユーザしか使用できない。
返り値
gethostid() は、 sethostid() によって設定された、現在使用しているホスト
の 32 ビットの識別子の値を返す。
成功すると、 sethostid() は 0 を返す。エラーの場合、-1 を返し 、 errno
にエラーを示す値を設定する。
エラー
sethostid() は以下のエラーで失敗する可能性がある。
EACCES 呼び出し元がホスト ID を保存するのに使用されるファイルへの書き込
み許可を持っていなかった。
EPERM 呼び出し元プロセスの実効 UID/GID が対応する実 UID/GID と同じでは
ない。
準拠
4.2BSD 。4.4BSD ではこれらの関数はなくなった。 SVr4 には gethostid() は
含まれているが、 sethostid() は含まれていない。 POSIX.1-2001 で は 、
gethostid() は規定されているが、 sethostid() は規定されていない。
注意
glibc の実装では、 hostid はファイル /etc/hostid に保存される (バージョ
ン 2.2 より前の glibc では、 /var/adm/hostid が使用されていた)。
glibc の実装では、ホスト ID を保存したファイルをオープンできなかった 場
合、 gethostid() は gethostname(2) を使ってホスト名を入手し、そのホスト
名を gethostbyname_r(3) に渡しホストの IPv4 アドレスを取得して 、 そ の
IPv4 アドレスのビット入れ替えを行った値を返す。
バグ
識別子が世界中で一意であることを保証することはできない。
関連項目
hostid(1), gethostbyname(3)
Linux 2009-01-13 GETHOSTID(3)
GETHOSTID(3) Linux Programmer’s Manual GETHOSTID(3)
NAME
gethostid, sethostid - get or set the unique identifier of the current
host
SYNOPSIS
#include
long gethostid(void);
int sethostid(long hostid);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
sethostid(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
DESCRIPTION
gethostid() and sethostid() respectively get or set a unique 32-bit
identifier for the current machine. The 32-bit identifier is intended
to be unique among all Unix systems in existence. This normally resem-
bles the Internet address for the local machine, as returned by geth-
ostbyname(3), and thus usually never needs to be set.
The sethostid() call is restricted to the superuser.
RETURN VALUE
gethostid() returns the 32-bit identifier for the current host as set
by sethostid().
On success, sethostid() returns 0; on error, -1 is returned, and errno
is set to indicate the error.
ERRORS
sethostid() can fail with the following errors:
EACCES The caller did not have permission to write to the file used to
store the host ID.
EPERM The calling process’s effective user or group ID is not the same
as its corresponding real ID.
CONFORMING TO
4.2BSD; these functions were dropped in 4.4BSD. SVr4 includes geth-
ostid() but not sethostid(). POSIX.1-2001 specifies gethostid() but
not sethostid().
NOTES
In the glibc implementation, the hostid is stored in the file
/etc/hostid. (In glibc versions before 2.2, the file /var/adm/hostid
was used.)
In the glibc implementation, if gethostid() cannot open the file con-
taining the host ID, then it obtains the hostname using gethostname(2),
passes that hostname to gethostbyname_r(3) in order to obtain the
host’s IPv4 address, and returns a value obtained by bit-twiddling the
IPv4 address. (This value may not be unique.)
BUGS
It is impossible to ensure that the identifier is globally unique.
SEE ALSO
hostid(1), gethostbyname(3)
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/.
Linux 2009-01-13 GETHOSTID(3)