.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified 1993-05-22, David Metcalfe .\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu) .\" Modified 1997-02-16, Andries Brouwer (aeb@cwi.nl) .\" Modified 1998-12-21, Andries Brouwer (aeb@cwi.nl) .\" Modified 2000-08-12, Andries Brouwer (aeb@cwi.nl) .\" Modified 2001-05-19, Andries Brouwer (aeb@cwi.nl) .\" Modified 2002-08-05, Michael Kerrisk .\" Modified 2004-10-31, Andries Brouwer .\" .\" Japanese Version Copyright (c) 1998-2000 NAKANO Takeo all rights reserved. .\" Translated 1998-04-30, NAKANO Takeo .\" Modified 1998-12-06, NAKANO Takeo .\" Updated & Modified 1999-10-12, NAKANO Takeo .\" Updated & Modified 2001-07-01, Yuichi SATO .\" Updated & Modified 2002-01-03, Yuichi SATO .\" Updated & Modified 2003-11-27, Yuichi SATO .\" Updated & Modified 2005-01-10, Yuichi SATO .\" Updated 2006-01-18, Akihiro MOTOKI .\" Updated 2007-06-11, Akihiro MOTOKI, LDP v2.54 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05 .\" .TH GETHOSTBYNAME 3 2010-10-04 "" "Linux Programmer's Manual" .\"O .SH NAME .\"O gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent, .\"O h_errno, .\"O herror, hstrerror, .\"O gethostbyaddr_r, .\"O gethostbyname2, gethostbyname2_r, gethostbyname_r, .\"O gethostent_r \- get network host entry .SH 名前 gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent, h_errno, herror, hstrerror, gethostbyaddr_r, gethostbyname2, gethostbyname2_r, gethostbyname_r, gethostent_r \- ネットワーク上のホストのエントリを取得する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .B extern int h_errno; .sp .BI "struct hostent *gethostbyname(const char *" name ); .sp .\"O .BR "#include " " /* for AF_INET */" .BR "#include " " /* AF_INET を使う場合 */" .BI "struct hostent *gethostbyaddr(const void *" addr , .BI " socklen_t " len ", int " type ); .sp .BI "void sethostent(int " stayopen ); .sp .B void endhostent(void); .sp .BI "void herror(const char *" s ); .sp .BI "const char *hstrerror(int " err ); .sp .\"O /* System V/POSIX extension */ /* System V/POSIX 拡張 */ .br .B struct hostent *gethostent(void); .sp .\"O /* GNU extensions */ /* GNU 拡張 */ .br .BI "struct hostent *gethostbyname2(const char *" name ", int " af ); .sp .B "int gethostent_r(" .BI " struct hostent *" ret ", char *" buf ", size_t " buflen , .BI " struct hostent **" result ", int *" h_errnop ); .sp .BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type , .BI " struct hostent *" ret ", char *" buf ", size_t " buflen , .BI " struct hostent **" result ", int *" h_errnop ); .sp .BI "int gethostbyname_r(const char *" name , .BI " struct hostent *" ret ", char *" buf ", size_t " buflen , .BI " struct hostent **" result ", int *" h_errnop ); .sp .BI "int gethostbyname2_r(const char *" name ", int " af, .BI " struct hostent *" ret ", char *" buf ", size_t " buflen , .BI " struct hostent **" result ", int *" h_errnop ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .PD 0 .ad l .BR gethostbyname2 (), .BR gethostent_r (), .BR gethostbyaddr_r (), .BR gethostbyname_r (), .BR gethostbyname2_r (): .RS 4 _BSD_SOURCE || _SVID_SOURCE .RE .BR herror (), .BR hstrerror (): .RS 4 .TP 4 .\"O Since glibc 2.8: glibc 2.8 以降: _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE .TP .\"O Before glibc 2.8: .\"O none glibc 2.8 より前: なし .RE .ad b .PD .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR gethostbyname* () .\"O and .\"O .BR gethostbyaddr* () .\"O functions are obsolete. .\"O Applications should use .\"O .BR getaddrinfo (3) .\"O and .\"O .BR getnameinfo (3) .\"O instead. .BR gethostbyname* () と .BR gethostbyaddr* () は過去のものである。 アプリケーションでは、代わりに .BR getaddrinfo (3) と .BR getnameinfo (3) を使用すること。 .\"O The .\"O .BR gethostbyname () .\"O function returns a structure of type .\"O .I hostent .\"O for the given host .\"O .IR name . .\"O Here .\"O .I name .\"O is either a hostname, or an IPv4 address in standard dot notation (as for .\"O .BR inet_addr (3)), .\"O or an IPv6 address in colon (and possibly dot) notation. .\"O (See RFC\ 1884 for the description of IPv6 addresses.) .BR gethostbyname () 関数は与えられたホスト名 .I name に対応する構造体 .I hostent を返す。 .I name にはホスト名、ドット区切りの IPv4 アドレス .RB ( inet_addr (3) 参照)、コロン区切りの IPv6 アドレス (おそらくドット区切りでも大丈夫) のいずれかを指定する (IPv6 アドレスの記述方法については RFC\ 1884 を参考にしてほしい)。 .\"O If .\"O .I name .\"O is an IPv4 or IPv6 address, no lookup is performed and .\"O .BR gethostbyname () .\"O simply copies .\"O .I name .\"O into the .\"O .I h_name .\"O field and its .\"O .I struct in_addr .\"O equivalent into the .\"O .I h_addr_list[0] .\"O field of the returned .\"O .I hostent .\"O structure. .I name が IPv4 か IPv6 のアドレスだった場合、 名前解決 (lookup) は行われない。その場合には、 .BR gethostbyname () は .I name をそのまま .I hostent 構造体の .I h_name フィールドにコピーし、 さらに .I name を .I struct in_addr 形式で表したデータを .I hostent 構造体の .I h_addr_list[0] フィールドに入れて、その .I hostent 構造体を返す。 .\"O If .\"O .I name .\"O doesn't end in a dot and the environment variable .\"O .B HOSTALIASES .\"O is set, the alias file pointed to by .\"O .B HOSTALIASES .\"O will first be searched for .\"O .I name .\"O (see .\"O .BR hostname (7) .\"O for the file format). .I name がドットで終了していて、かつ環境変数 .B HOSTALIASES が設定されている場合、まず .B HOSTALIASES で指定されているエイリアスファイルから .I name のエントリが検索される (ファイルのフォーマットについては .BR hostname (7) を参照のこと)。 .\"O The current domain and its parents are searched unless \fIname\fP .\"O ends in a dot. .I name がドットで終了していなければ、現在のドメインとその親ドメインが検索される。 .PP .\"O The .\"O .BR gethostbyaddr () .\"O function returns a structure of type \fIhostent\fP .\"O for the given host address \fIaddr\fP of length \fIlen\fP and address type .\"O \fItype\fP. .\"O Valid address types are .\"O .B AF_INET .\"O and .\"O .BR AF_INET6 . .BR gethostbyaddr () 関数は与えられたホストアドレス .I addr (長さ \fIlen\fP、 タイプ \fItype\fP) に対応する構造体 .I hostent を返す。 用いることのできるタイプは .B AF_INET と .B AF_INET6 である。 .\"O The host address argument is a pointer to a struct of a type depending .\"O on the address type, for example a \fIstruct in_addr *\fP (probably .\"O obtained via a call to .\"O .BR inet_addr (3)) .\"O for address type .\"O .BR AF_INET . ホストアドレス引き数はアドレスタイプに依存した 構造体へのポインタである。 例えば、アドレスタイプ .B AF_INET に対しては .RB ( inet_addr (3) の呼び出しで得られる) \fIstruct in_addr *\fP である。 .PP .\"O The .\"O .BR sethostent () .\"O function specifies, if \fIstayopen\fP is true (1), .\"O that a connected TCP socket should be used for the name server queries and .\"O that the connection should remain open during successive queries. .\"O Otherwise, name server queries will use UDP datagrams. .BR sethostent () 関数は、ネームサーバへの接続形態を指定する。 .I stayopen が真 (1) ならば、ネームサーバへの問い合わせには、 接続された TCP ソケットを用い、連続した問い合わせの間に接続を維持する。 偽ならばネームサーバへの問い合わせに UDP データグラムを用いる。 .PP .\"O The .\"O .BR endhostent () .\"O function ends the use of a TCP connection for name .\"O server queries. .BR endhostent () 関数はネームサーバへの問い合わせに用いた TCP 接続の利用を終了する。 .PP .\"O The (obsolete) .\"O .BR herror () .\"O function prints the error message associated .\"O with the current value of \fIh_errno\fP on \fIstderr\fP. (廃止予定の) .BR herror () 関数は現在の .I h_errno に対応するエラーメッセージを標準エラー \fIstderr\fP に出力する。 .PP .\"O The (obsolete) .\"O .BR hstrerror () .\"O function takes an error number .\"O (typically \fIh_errno\fP) and returns the corresponding message string. (廃止予定の) .BR hstrerror () 関数はエラー番号 (通常は \fIh_errno\fP) を引き数に取り、 対応するエラーメッセージ文字列を返す。 .PP .\"O The domain name queries carried out by .\"O .BR gethostbyname () .\"O and .\"O .BR gethostbyaddr () .\"O use a combination of any or all of the name server .\"O .BR named (8), .\"O a broken out line from \fI/etc/hosts\fP, and the Network .\"O Information Service (NIS or YP), depending upon the contents of the .\"O \fIorder\fP line in .\"O .IR /etc/host.conf . .\"O .\" (See .\"O .\" .BR resolv+ (8)). .\"O The default action is to query .\"O .BR named (8), .\"O followed by .\"O .IR /etc/hosts . .BR gethostbyname () と .BR gethostbyaddr () によって実行されるドメイン名の問い合わせでは、ネームサーバ .BR named (8)、 .I /etc/hosts のデータ行、および Network Information Service (NIS または YP) が組み合わせて使用される。何が使用されるかは、 .I /etc/host.conf の .I order 行の内容により決まる。 .\" (詳しくは .\" .BR resolv+ (8) .\" を参照)。 デフォルトでは、まず .BR named (8) に問い合わせを行い、次いで .I /etc/hosts を参照する。 .PP .\"O The \fIhostent\fP structure is defined in \fI\fP as follows: .I hostent 構造体は .I で以下のように定義されている: .sp .in +4n .nf .ne 7 struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses */ } .\"O #define h_addr h_addr_list[0] /* for backward compatibility */ #define h_addr h_addr_list[0] /* 過去との互換性のため */ .fi .in .PP .\"O The members of the \fIhostent\fP structure are: .I hostent 構造体のメンバは以下の通り。 .TP .I h_name .\"O The official name of the host. ホストの正式名 (official name)。 .TP .I h_aliases .\"O An array of alternative names for the host, terminated by a NULL pointer. ホストの別名の配列。配列は NULL ポインタで終端される。 .TP .I h_addrtype .\"O The type of address; always .\"O .B AF_INET .\"O or .\"O .B AF_INET6 .\"O at present. アドレスのタイプ。現在はすべて .B AF_INET または .B AF_INET6 である。 .TP .I h_length .\"O The length of the address in bytes. バイト単位で表したアドレスの長さ。 .TP .I h_addr_list .\"O An array of pointers to network addresses for the host (in network byte .\"O order), terminated by a NULL pointer. ホストのネットワークアドレスへのポインタの配列。 配列は NULL ポインタで終端される。 ネットワークアドレスはネットワークバイトオーダ形式である。 .TP .I h_addr .\"O The first address in \fIh_addr_list\fP for backward compatibility. .I h_addr_list の最初のアドレス。過去との互換性を保つためのものである。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The .\"O .BR gethostbyname () .\"O and .\"O .BR gethostbyaddr () .\"O functions return the .\"O .I hostent .\"O structure or a NULL pointer if an error occurs. .\"O On error, the .\"O .I h_errno .\"O variable holds an error number. .BR gethostbyname () および .BR gethostbyaddr () 関数は .I hostent 構造体を返す。エラーが起こったら NULL ポインタを返す。エラーの際には .I h_errno 変数がエラーの番号を保持する。 .\"O When non-NULL, the return value may point at static data, see the notes below. 返り値が NULL でない場合、静的データをポインタで指していることもある。 以下の「注意」を参照すること。 .\"O .SH "ERRORS" .SH エラー .\"O The variable \fIh_errno\fP can have the following values: .I h_errno 変数は以下の値を取りうる。 .TP .B HOST_NOT_FOUND .\"O The specified host is unknown. 指定したホストが見つからない。 .TP .\"O .B NO_ADDRESS " or " NO_DATA .B NO_ADDRESS " または " NO_DATA .\"O The requested name is valid but does not have an IP address. 指定した名前は有効だが IP アドレスを持っていない。 .TP .B NO_RECOVERY .\"O A nonrecoverable name server error occurred. ネームサーバの復旧不能なエラーが起こった。 .TP .B TRY_AGAIN .\"O A temporary error occurred on an authoritative name server. .\"O Try again later. authoritative なネームサーバで一時的なエラーが起こった。 時間をおいてもう一度試すこと。 .\"O .SH FILES .SH ファイル .TP .I /etc/host.conf .\"O resolver configuration file 名前解決の設定ファイル .TP .I /etc/hosts .\"O host database file ホストのデータベースファイル .TP .I /etc/nsswitch.conf .\"O name service switch configuration ネームサービス切替設定 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O POSIX.1-2001 specifies .\"O .BR gethostbyname (), .\"O .BR gethostbyaddr (), .\"O .BR sethostent (), .\"O .BR endhostent (), .\"O .BR gethostent (), .\"O and .\"O .IR h_errno ; .\"O .BR gethostbyname (), .\"O .BR gethostbyaddr (), .\"O and .\"O .IR h_errno .\"O are marked obsolescent in that standard. POSIX.1-2001 では、 .BR gethostbyname (), .BR gethostbyaddr (), .BR sethostent (), .BR endhostent (), .BR gethostent (), .I h_errno が規定されており、 .BR gethostbyaddr () と .BR gethostbyname () は廃止予定であるとされている。 .\"O POSIX.1-2008 removes the specifications of .\"O .BR gethostbyname (), .\"O .BR gethostbyaddr (), .\"O and .\"O .IR h_errno , .\"O recommending the use of .\"O .BR getaddrinfo (3) .\"O and .\"O .BR getnameinfo (3) .\"O instead. POSIX.1-2008 では .BR gethostbyname (), .BR gethostbyaddr (), .I h_errno の仕様が削除されている。 代わりに、 .BR getaddrinfo (3) と .BR getnameinfo (3) の使用が推奨されている。 .\"O .SH NOTES .SH 注意 .\"O The functions .\"O .BR gethostbyname () .\"O and .\"O .BR gethostbyaddr () .\"O may return pointers to static data, which may be overwritten by .\"O later calls. .\"O Copying the .\"O .I struct hostent .\"O does not suffice, since it contains pointers; a deep copy is required. .BR gethostbyname () および .BR gethostbyaddr () 関数は静的データへのポインタを返す。 このポインタは、その後の呼び出しで上書きされるかもしれない。 .I hostent 構造体はポインタを含んでいるので、構造体のコピーだけでは不十分である; より深いコピーが必要である。 .LP .\"O In the original BSD implementation the .\"O .I len .\"O argument .\"O of .\"O .BR gethostbyname () .\"O was an .\"O .IR int . オリジナルの BSD の実装では、 .BR gethostbyname () の .I len 引き数は .I int であった。 .\"O The SUSv2 standard is buggy and declares the .\"O .I len .\"O argument of .\"O .BR gethostbyaddr () .\"O to be of type .\"O .IR size_t . .\"O (That is wrong, because it has to be .\"O .IR int , .\"O and .\"O .I size_t .\"O is not. .\"O POSIX.1-2001 makes it .\"O .IR socklen_t , .\"O which is OK.) .\"O See also .\"O .BR accept (2). SUSv2 標準はバグが多く、 .BR gethostbyaddr () の .I len パラメータを .I size_t 型として宣言している。 (これは誤りで、 .I size_t 型ではなく .I int 型でなければならない。 POSIX.1-2001 ではこれを .I socklen_t としているが、これは OK。) .BR accept (2) も参照。 .LP .\"O The BSD prototype for .\"O .BR gethostbyaddr () .\"O uses .\"O .I const char * .\"O for the first argument. .BR gethostbyaddr () の BSD のプロトタイプは、最初の引き数として .I const char * を使う。 .\"O .SS "System V/POSIX Extension" .SS "System V/POSIX 拡張" .\"O POSIX requires the .\"O .BR gethostent () .\"O call, that should return the next entry in the host data base. POSIX では、 .BR gethostent () が必須とされている。 この関数はホストデータベースの次のエントリを返す。 .\"O When using DNS/BIND this does not make much sense, but it may .\"O be reasonable if the host data base is a file that can be read .\"O line by line. .\"O On many systems a routine of this name reads .\"O from the file .\"O .IR /etc/hosts . DNS/BIND を使う場合はあまり意味を持たないが、 ホストデータベースが 1 行ずつ読み込まれるファイルである場合は意味がある。 多くのシステムでは、この名前のルーチンはファイル .I /etc/hosts を読み込む。 .\"O .\" e.g., Linux, FreeBSD, UnixWare, HP-UX .\"O It may be available only when the library was built without DNS support. .\"O .\" e.g., FreeBSD, AIX .\"O The glibc version will ignore ipv6 entries. .\"O This function is not reentrant, .\"O and glibc adds a reentrant version .\"O .BR gethostent_r (). .\" 例えば、Linux, FreeBSD, UnixWare, HP-UX DNS サポートなしでライブラリがビルドされた場合にのみ利用可能である。 .\" 例えば、FreeBSD, AIX glibc 版は ipv6 エントリを無視する。 この関数はリエントラント (reentrant) ではなく、 glibc にはリエントラント版の .BR gethostent_r () が追加された。 .\"O .SS "GNU Extensions" .SS "GNU 拡張" .\"O Glibc2 also has a .\"O .BR gethostbyname2 () .\"O that works like .\"O .BR gethostbyname (), .\"O but permits to specify the address family to which the address must belong. glibc2 には .BR gethostbyname2 () もあり、 .BR gethostbyname () と同じように動作するが、 こちらはアドレスが属するアドレスファミリーを指定することができる。 .LP .\"O Glibc2 also has reentrant versions .\"O .BR gethostent_r (), .\"O .BR gethostbyaddr_r (), .\"O .BR gethostbyname_r () .\"O and .\"O .BR gethostbyname2_r (). glibc2 にはリエントラントな .BR gethostent_r (), .BR gethostbyaddr_r (), .BR gethostbyname_r () と .BR gethostbyname2_r () もある。 .\"O The caller supplies a .\"O .I hostent .\"O structure .\"O .I ret .\"O which will be filled in on success, and a temporary work buffer .\"O .I buf .\"O of size .\"O .IR buflen . 呼び出し側は、成功時に結果が格納される .I hostent 構造体 .I ret と、大きさ .I buflen の一時的な作業バッファ .I buf を提供する。 .\"O After the call, .\"O .I result .\"O will point to the result on success. .\"O In case of an error .\"O or if no entry is found .\"O .I result .\"O will be NULL. コール終了後、成功した場合 .I result は結果を指している。 エラーの場合、またはエントリが見つからなかった場合、 .I result は NULL になる。 .\"O The functions return 0 on success and a nonzero error number on failure. .\"O In addition to the errors returned by the nonreentrant .\"O versions of these functions, if .\"O .I buf .\"O is too small, the functions will return .\"O .BR ERANGE , .\"O and the call should be retried with a larger buffer. これらの関数は、成功した場合 0 を返し、失敗の場合は 0 以外のエラー番号を返す。 これらの関数のリエントラントでないバージョンが返すエラーに加えて、 これらの関数は、 .I buf が小さすぎた場合に .B ERANGE を返す。この場合はもっと大きなバッファを用意して 関数呼び出しを再度行うべきである。 .\"O The global variable .\"O .I h_errno .\"O is not modified, but the address of a variable in which to store error numbers .\"O is passed in .\"O .IR h_errnop . 大域変数 .I h_errno は変更されないが、エラー番号を格納する変数のアドレスが .I h_errnop に渡される。 .\"O .SH BUGS .SH バグ .\"O .BR gethostbyname () .\"O does not recognize components of a dotted IPv4 address string .\"O that are expressed in hexadecimal. .BR gethostbyname () は、16進数表現のドット区切りの IPv4 アドレス文字列の要素を認識しない。 .\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973 .\"O .SH "SEE ALSO" .SH 関連項目 .BR getaddrinfo (3), .\" .BR getipnodebyaddr (3), .\" .BR getipnodebyname (3), .BR getnameinfo (3), .BR inet (3), .BR inet_ntop (3), .BR inet_pton (3), .BR resolver (3), .BR hosts (5), .BR nsswitch.conf (5), .BR hostname (7), .BR named (8) .\" .BR resolv+ (8)