1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified 1993-05-22, David Metcalfe
28 .\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu)
29 .\" Modified 1997-02-16, Andries Brouwer (aeb@cwi.nl)
30 .\" Modified 1998-12-21, Andries Brouwer (aeb@cwi.nl)
31 .\" Modified 2000-08-12, Andries Brouwer (aeb@cwi.nl)
32 .\" Modified 2001-05-19, Andries Brouwer (aeb@cwi.nl)
33 .\" Modified 2002-08-05, Michael Kerrisk
34 .\" Modified 2004-10-31, Andries Brouwer
36 .\" Japanese Version Copyright (c) 1998-2000 NAKANO Takeo all rights reserved.
37 .\" Translated 1998-04-30, NAKANO Takeo <nakano@apm.seikei.ac.jp>
38 .\" Modified 1998-12-06, NAKANO Takeo
39 .\" Updated & Modified 1999-10-12, NAKANO Takeo
40 .\" Updated & Modified 2001-07-01, Yuichi SATO <ysato@h4.dion.ne.jp>
41 .\" Updated & Modified 2002-01-03, Yuichi SATO
42 .\" Updated & Modified 2003-11-27, Yuichi SATO <ysato444@yahoo.co.jp>
43 .\" Updated & Modified 2005-01-10, Yuichi SATO
44 .\" Updated 2006-01-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
45 .\" Updated 2007-06-11, Akihiro MOTOKI, LDP v2.54
46 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
48 .TH GETHOSTBYNAME 3 2010-10-04 "" "Linux Programmer's Manual"
50 .\"O gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
52 .\"O herror, hstrerror,
54 .\"O gethostbyname2, gethostbyname2_r, gethostbyname_r,
55 .\"O gethostent_r \- get network host entry
57 gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
61 gethostbyname2, gethostbyname2_r, gethostbyname_r,
62 gethostent_r \- ネットワーク上のホストのエントリを取得する
67 .B extern int h_errno;
69 .BI "struct hostent *gethostbyname(const char *" name );
71 .\"O .BR "#include <sys/socket.h>" " /* for AF_INET */"
72 .BR "#include <sys/socket.h>" " /* AF_INET を使う場合 */"
73 .BI "struct hostent *gethostbyaddr(const void *" addr ,
74 .BI " socklen_t " len ", int " type );
76 .BI "void sethostent(int " stayopen );
78 .B void endhostent(void);
80 .BI "void herror(const char *" s );
82 .BI "const char *hstrerror(int " err );
84 .\"O /* System V/POSIX extension */
85 /* System V/POSIX 拡張 */
87 .B struct hostent *gethostent(void);
89 .\"O /* GNU extensions */
92 .BI "struct hostent *gethostbyname2(const char *" name ", int " af );
94 .B "int gethostent_r("
95 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
96 .BI " struct hostent **" result ", int *" h_errnop );
98 .BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
99 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
100 .BI " struct hostent **" result ", int *" h_errnop );
102 .BI "int gethostbyname_r(const char *" name ,
103 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
104 .BI " struct hostent **" result ", int *" h_errnop );
106 .BI "int gethostbyname2_r(const char *" name ", int " af,
107 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
108 .BI " struct hostent **" result ", int *" h_errnop );
112 .\"O Feature Test Macro Requirements for glibc (see
113 .\"O .BR feature_test_macros (7)):
115 .RB ( feature_test_macros (7)
121 .BR gethostbyname2 (),
123 .BR gethostbyaddr_r (),
124 .BR gethostbyname_r (),
125 .BR gethostbyname2_r ():
127 _BSD_SOURCE || _SVID_SOURCE
134 .\"O Since glibc 2.8:
136 _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE
138 .\"O Before glibc 2.8:
148 .\"O .BR gethostbyname* ()
150 .\"O .BR gethostbyaddr* ()
151 .\"O functions are obsolete.
152 .\"O Applications should use
153 .\"O .BR getaddrinfo (3)
155 .\"O .BR getnameinfo (3)
157 .BR gethostbyname* ()
159 .BR gethostbyaddr* ()
168 .\"O .BR gethostbyname ()
169 .\"O function returns a structure of type
171 .\"O for the given host
175 .\"O is either a hostname, or an IPv4 address in standard dot notation (as for
176 .\"O .BR inet_addr (3)),
177 .\"O or an IPv6 address in colon (and possibly dot) notation.
178 .\"O (See RFC\ 1884 for the description of IPv6 addresses.)
186 にはホスト名、ドット区切りの IPv4 アドレス
188 参照)、コロン区切りの IPv6 アドレス (おそらくドット区切りでも大丈夫)
190 (IPv6 アドレスの記述方法については RFC\ 1884 を参考にしてほしい)。
193 .\"O is an IPv4 or IPv6 address, no lookup is performed and
194 .\"O .BR gethostbyname ()
200 .\"O .I struct in_addr
201 .\"O equivalent into the
202 .\"O .I h_addr_list[0]
203 .\"O field of the returned
207 が IPv4 か IPv6 のアドレスだった場合、
208 名前解決 (lookup) は行われない。その場合には、
230 .\"O doesn't end in a dot and the environment variable
232 .\"O is set, the alias file pointed to by
234 .\"O will first be searched for
237 .\"O .BR hostname (7)
238 .\"O for the file format).
246 のエントリが検索される (ファイルのフォーマットについては
249 .\"O The current domain and its parents are searched unless \fIname\fP
252 がドットで終了していなければ、現在のドメインとその親ドメインが検索される。
255 .\"O .BR gethostbyaddr ()
256 .\"O function returns a structure of type \fIhostent\fP
257 .\"O for the given host address \fIaddr\fP of length \fIlen\fP and address type
259 .\"O Valid address types are
266 (長さ \fIlen\fP、 タイプ \fItype\fP) に対応する構造体
274 .\"O The host address argument is a pointer to a struct of a type depending
275 .\"O on the address type, for example a \fIstruct in_addr *\fP (probably
276 .\"O obtained via a call to
277 .\"O .BR inet_addr (3))
278 .\"O for address type
280 ホストアドレス引き数はアドレスタイプに依存した
287 \fIstruct in_addr *\fP である。
290 .\"O .BR sethostent ()
291 .\"O function specifies, if \fIstayopen\fP is true (1),
292 .\"O that a connected TCP socket should be used for the name server queries and
293 .\"O that the connection should remain open during successive queries.
294 .\"O Otherwise, name server queries will use UDP datagrams.
296 関数は、ネームサーバへの接続形態を指定する。
298 が真 (1) ならば、ネームサーバへの問い合わせには、
299 接続された TCP ソケットを用い、連続した問い合わせの間に接続を維持する。
300 偽ならばネームサーバへの問い合わせに UDP データグラムを用いる。
303 .\"O .BR endhostent ()
304 .\"O function ends the use of a TCP connection for name
307 関数はネームサーバへの問い合わせに用いた TCP 接続の利用を終了する。
311 .\"O function prints the error message associated
312 .\"O with the current value of \fIh_errno\fP on \fIstderr\fP.
317 に対応するエラーメッセージを標準エラー \fIstderr\fP に出力する。
320 .\"O .BR hstrerror ()
321 .\"O function takes an error number
322 .\"O (typically \fIh_errno\fP) and returns the corresponding message string.
325 関数はエラー番号 (通常は \fIh_errno\fP) を引き数に取り、
328 .\"O The domain name queries carried out by
329 .\"O .BR gethostbyname ()
331 .\"O .BR gethostbyaddr ()
332 .\"O use a combination of any or all of the name server
334 .\"O a broken out line from \fI/etc/hosts\fP, and the Network
335 .\"O Information Service (NIS or YP), depending upon the contents of the
336 .\"O \fIorder\fP line in
337 .\"O .IR /etc/host.conf .
339 .\"O .\" .BR resolv+ (8)).
340 .\"O The default action is to query
343 .\"O .IR /etc/hosts .
347 によって実行されるドメイン名の問い合わせでは、ネームサーバ
351 Network Information Service (NIS または YP)
352 が組み合わせて使用される。何が使用されるかは、
366 .\"O The \fIhostent\fP structure is defined in \fI<netdb.h>\fP as follows:
376 char *h_name; /* official name of host */
377 char **h_aliases; /* alias list */
378 int h_addrtype; /* host address type */
379 int h_length; /* length of address */
380 char **h_addr_list; /* list of addresses */
382 .\"O #define h_addr h_addr_list[0] /* for backward compatibility */
383 #define h_addr h_addr_list[0] /* 過去との互換性のため */
387 .\"O The members of the \fIhostent\fP structure are:
392 .\"O The official name of the host.
393 ホストの正式名 (official name)。
396 .\"O An array of alternative names for the host, terminated by a NULL pointer.
397 ホストの別名の配列。配列は NULL ポインタで終端される。
400 .\"O The type of address; always
412 .\"O The length of the address in bytes.
416 .\"O An array of pointers to network addresses for the host (in network byte
417 .\"O order), terminated by a NULL pointer.
418 ホストのネットワークアドレスへのポインタの配列。
420 ネットワークアドレスはネットワークバイトオーダ形式である。
423 .\"O The first address in \fIh_addr_list\fP for backward compatibility.
425 の最初のアドレス。過去との互換性を保つためのものである。
426 .\"O .SH "RETURN VALUE"
429 .\"O .BR gethostbyname ()
431 .\"O .BR gethostbyaddr ()
432 .\"O functions return the
434 .\"O structure or a NULL pointer if an error occurs.
437 .\"O variable holds an error number.
443 構造体を返す。エラーが起こったら NULL ポインタを返す。エラーの際には
446 .\"O When non-NULL, the return value may point at static data, see the notes below.
447 返り値が NULL でない場合、静的データをポインタで指していることもある。
451 .\"O The variable \fIh_errno\fP can have the following values:
456 .\"O The specified host is unknown.
459 .\"O .B NO_ADDRESS " or " NO_DATA
460 .B NO_ADDRESS " または " NO_DATA
461 .\"O The requested name is valid but does not have an IP address.
462 指定した名前は有効だが IP アドレスを持っていない。
465 .\"O A nonrecoverable name server error occurred.
466 ネームサーバの復旧不能なエラーが起こった。
469 .\"O A temporary error occurred on an authoritative name server.
470 .\"O Try again later.
471 authoritative なネームサーバで一時的なエラーが起こった。
477 .\"O resolver configuration file
481 .\"O host database file
484 .I /etc/nsswitch.conf
485 .\"O name service switch configuration
487 .\"O .SH "CONFORMING TO"
489 .\"O POSIX.1-2001 specifies
490 .\"O .BR gethostbyname (),
491 .\"O .BR gethostbyaddr (),
492 .\"O .BR sethostent (),
493 .\"O .BR endhostent (),
494 .\"O .BR gethostent (),
497 .\"O .BR gethostbyname (),
498 .\"O .BR gethostbyaddr (),
501 .\"O are marked obsolescent in that standard.
503 .BR gethostbyname (),
504 .BR gethostbyaddr (),
514 .\"O POSIX.1-2008 removes the specifications of
515 .\"O .BR gethostbyname (),
516 .\"O .BR gethostbyaddr (),
519 .\"O recommending the use of
520 .\"O .BR getaddrinfo (3)
522 .\"O .BR getnameinfo (3)
525 .BR gethostbyname (),
526 .BR gethostbyaddr (),
537 .\"O .BR gethostbyname ()
539 .\"O .BR gethostbyaddr ()
540 .\"O may return pointers to static data, which may be overwritten by
543 .\"O .I struct hostent
544 .\"O does not suffice, since it contains pointers; a deep copy is required.
549 このポインタは、その後の呼び出しで上書きされるかもしれない。
551 構造体はポインタを含んでいるので、構造体のコピーだけでは不十分である;
554 .\"O In the original BSD implementation the
558 .\"O .BR gethostbyname ()
568 .\"O The SUSv2 standard is buggy and declares the
571 .\"O .BR gethostbyaddr ()
574 .\"O (That is wrong, because it has to be
579 .\"O POSIX.1-2001 makes it
602 .\"O The BSD prototype for
603 .\"O .BR gethostbyaddr ()
606 .\"O for the first argument.
608 の BSD のプロトタイプは、最初の引き数として
611 .\"O .SS "System V/POSIX Extension"
612 .SS "System V/POSIX 拡張"
613 .\"O POSIX requires the
614 .\"O .BR gethostent ()
615 .\"O call, that should return the next entry in the host data base.
619 この関数はホストデータベースの次のエントリを返す。
620 .\"O When using DNS/BIND this does not make much sense, but it may
621 .\"O be reasonable if the host data base is a file that can be read
623 .\"O On many systems a routine of this name reads
625 .\"O .IR /etc/hosts .
626 DNS/BIND を使う場合はあまり意味を持たないが、
627 ホストデータベースが 1 行ずつ読み込まれるファイルである場合は意味がある。
628 多くのシステムでは、この名前のルーチンはファイル
631 .\"O .\" e.g., Linux, FreeBSD, UnixWare, HP-UX
632 .\"O It may be available only when the library was built without DNS support.
633 .\"O .\" e.g., FreeBSD, AIX
634 .\"O The glibc version will ignore ipv6 entries.
635 .\"O This function is not reentrant,
636 .\"O and glibc adds a reentrant version
637 .\"O .BR gethostent_r ().
638 .\" 例えば、Linux, FreeBSD, UnixWare, HP-UX
639 DNS サポートなしでライブラリがビルドされた場合にのみ利用可能である。
641 glibc 版は ipv6 エントリを無視する。
642 この関数はリエントラント (reentrant) ではなく、
646 .\"O .SS "GNU Extensions"
648 .\"O Glibc2 also has a
649 .\"O .BR gethostbyname2 ()
651 .\"O .BR gethostbyname (),
652 .\"O but permits to specify the address family to which the address must belong.
654 .BR gethostbyname2 ()
658 こちらはアドレスが属するアドレスファミリーを指定することができる。
660 .\"O Glibc2 also has reentrant versions
661 .\"O .BR gethostent_r (),
662 .\"O .BR gethostbyaddr_r (),
663 .\"O .BR gethostbyname_r ()
665 .\"O .BR gethostbyname2_r ().
668 .BR gethostbyaddr_r (),
669 .BR gethostbyname_r ()
671 .BR gethostbyname2_r ()
673 .\"O The caller supplies a
677 .\"O which will be filled in on success, and a temporary work buffer
692 .\"O will point to the result on success.
693 .\"O In case of an error
694 .\"O or if no entry is found
700 エラーの場合、またはエントリが見つからなかった場合、
703 .\"O The functions return 0 on success and a nonzero error number on failure.
704 .\"O In addition to the errors returned by the nonreentrant
705 .\"O versions of these functions, if
707 .\"O is too small, the functions will return
709 .\"O and the call should be retried with a larger buffer.
710 これらの関数は、成功した場合 0 を返し、失敗の場合は 0 以外のエラー番号を返す。
711 これらの関数のリエントラントでないバージョンが返すエラーに加えて、
716 を返す。この場合はもっと大きなバッファを用意して
718 .\"O The global variable
720 .\"O is not modified, but the address of a variable in which to store error numbers
725 は変更されないが、エラー番号を格納する変数のアドレスが
730 .\"O .BR gethostbyname ()
731 .\"O does not recognize components of a dotted IPv4 address string
732 .\"O that are expressed in hexadecimal.
734 は、16進数表現のドット区切りの IPv4 アドレス文字列の要素を認識しない。
735 .\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973
739 .\" .BR getipnodebyaddr (3),
740 .\" .BR getipnodebyname (3),
747 .BR nsswitch.conf (5),