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 gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent,
54 gethostbyname2, gethostbyname2_r, gethostbyname_r,
55 gethostent_r \- ¥Í¥Ã¥È¥ï¡¼¥¯¾å¤Î¥Û¥¹¥È¤Î¥¨¥ó¥È¥ê¤ò¼èÆÀ¤¹¤ë
59 .B extern int h_errno;
61 .BI "struct hostent *gethostbyname(const char *" name );
63 .BR "#include <sys/socket.h>" " /* AF_INET ¤ò»È¤¦¾ì¹ç */"
64 .BI "struct hostent *gethostbyaddr(const void *" addr ,
65 .BI " socklen_t " len ", int " type );
67 .BI "void sethostent(int " stayopen );
69 .B void endhostent(void);
71 .BI "void herror(const char *" s );
73 .BI "const char *hstrerror(int " err );
75 /* System V/POSIX ³ÈÄ¥ */
77 .B struct hostent *gethostent(void);
81 .BI "struct hostent *gethostbyname2(const char *" name ", int " af );
83 .B "int gethostent_r("
84 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
85 .BI " struct hostent **" result ", int *" h_errnop );
87 .BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
88 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
89 .BI " struct hostent **" result ", int *" h_errnop );
91 .BI "int gethostbyname_r(const char *" name ,
92 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
93 .BI " struct hostent **" result ", int *" h_errnop );
95 .BI "int gethostbyname2_r(const char *" name ", int " af,
96 .BI " struct hostent *" ret ", char *" buf ", size_t " buflen ,
97 .BI " struct hostent **" result ", int *" h_errnop );
101 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
102 .RB ( feature_test_macros (7)
108 .BR gethostbyname2 (),
110 .BR gethostbyaddr_r (),
111 .BR gethostbyname_r (),
112 .BR gethostbyname2_r ():
114 _BSD_SOURCE || _SVID_SOURCE
122 _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE
130 .BR gethostbyname* ()
132 .BR gethostbyaddr* ()
134 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢Âå¤ï¤ê¤Ë
141 ´Ø¿ô¤ÏÍ¿¤¨¤é¤ì¤¿¥Û¥¹¥È̾
147 ¤Ë¤Ï¥Û¥¹¥È̾¡¢¥É¥Ã¥È¶èÀÚ¤ê¤Î IPv4 ¥¢¥É¥ì¥¹
149 »²¾È)¡¢¥³¥í¥ó¶èÀÚ¤ê¤Î IPv6 ¥¢¥É¥ì¥¹ (¤ª¤½¤é¤¯¥É¥Ã¥È¶èÀÚ¤ê¤Ç¤âÂç¾æÉ×)
151 (IPv6 ¥¢¥É¥ì¥¹¤Îµ½ÒÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï RFC\ 1884 ¤ò»²¹Í¤Ë¤·¤Æ¤Û¤·¤¤)¡£
153 ¤¬ IPv4 ¤« IPv6 ¤Î¥¢¥É¥ì¥¹¤À¤Ã¤¿¾ì¹ç¡¢
154 ̾Á°²ò·è (lookup) ¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£¤½¤Î¾ì¹ç¤Ë¤Ï¡¢
162 ¥Õ¥£¡¼¥ë¥É¤Ë¥³¥Ô¡¼¤·¡¢
171 ¥Õ¥£¡¼¥ë¥É¤ËÆþ¤ì¤Æ¡¢¤½¤Î
175 ¤¬¥É¥Ã¥È¤Ç½ªÎ»¤·¤Æ¤¤¤Æ¡¢¤«¤Ä´Ä¶ÊÑ¿ô
177 ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤Þ¤º
179 ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¥¨¥¤¥ê¥¢¥¹¥Õ¥¡¥¤¥ë¤«¤é
181 ¤Î¥¨¥ó¥È¥ê¤¬¸¡º÷¤µ¤ì¤ë (¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Ï
185 ¤¬¥É¥Ã¥È¤Ç½ªÎ»¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢¸½ºß¤Î¥É¥á¥¤¥ó¤È¤½¤Î¿Æ¥É¥á¥¤¥ó¤¬¸¡º÷¤µ¤ì¤ë¡£
188 ´Ø¿ô¤ÏÍ¿¤¨¤é¤ì¤¿¥Û¥¹¥È¥¢¥É¥ì¥¹
190 (Ťµ \fIlen\fP¡¢ ¥¿¥¤¥× \fItype\fP) ¤ËÂбþ¤¹¤ë¹½Â¤ÂÎ
193 ÍѤ¤¤ë¤³¤È¤Î¤Ç¤¤ë¥¿¥¤¥×¤Ï
198 ¥Û¥¹¥È¥¢¥É¥ì¥¹°ú¤¿ô¤Ï¥¢¥É¥ì¥¹¥¿¥¤¥×¤Ë°Í¸¤·¤¿
199 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
200 Î㤨¤Ð¡¢¥¢¥É¥ì¥¹¥¿¥¤¥×
204 ¤Î¸Æ¤Ó½Ð¤·¤ÇÆÀ¤é¤ì¤ë)
205 \fIstruct in_addr *\fP ¤Ç¤¢¤ë¡£
208 ´Ø¿ô¤Ï¡¢¥Í¡¼¥à¥µ¡¼¥Ð¤Ø¤ÎÀܳ·ÁÂÖ¤ò»ØÄꤹ¤ë¡£
210 ¤¬¿¿ (1) ¤Ê¤é¤Ð¡¢¥Í¡¼¥à¥µ¡¼¥Ð¤Ø¤ÎÌ䤤¹ç¤ï¤»¤Ë¤Ï¡¢
211 Àܳ¤µ¤ì¤¿ TCP ¥½¥±¥Ã¥È¤òÍѤ¤¡¢Ï¢Â³¤·¤¿Ì䤤¹ç¤ï¤»¤Î´Ö¤ËÀܳ¤ò°Ý»ý¤¹¤ë¡£
212 µ¶¤Ê¤é¤Ð¥Í¡¼¥à¥µ¡¼¥Ð¤Ø¤ÎÌ䤤¹ç¤ï¤»¤Ë UDP ¥Ç¡¼¥¿¥°¥é¥à¤òÍѤ¤¤ë¡£
215 ´Ø¿ô¤Ï¥Í¡¼¥à¥µ¡¼¥Ð¤Ø¤ÎÌ䤤¹ç¤ï¤»¤ËÍѤ¤¤¿ TCP Àܳ¤ÎÍøÍѤò½ªÎ»¤¹¤ë¡£
221 ¤ËÂбþ¤¹¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òɸ½à¥¨¥é¡¼ \fIstderr\fP ¤Ë½ÐÎϤ¹¤ë¡£
225 ´Ø¿ô¤Ï¥¨¥é¡¼ÈÖ¹æ (Ä̾ï¤Ï \fIh_errno\fP) ¤ò°ú¤¿ô¤Ë¼è¤ê¡¢
226 Âбþ¤¹¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸Ê¸»úÎó¤òÊÖ¤¹¡£
231 ¤Ë¤è¤Ã¤Æ¼Â¹Ô¤µ¤ì¤ë¥É¥á¥¤¥ó̾¤ÎÌ䤤¹ç¤ï¤»¤Ç¤Ï¡¢¥Í¡¼¥à¥µ¡¼¥Ð
235 Network Information Service (NIS ¤Þ¤¿¤Ï YP)
236 ¤¬ÁȤ߹ç¤ï¤»¤Æ»ÈÍѤµ¤ì¤ë¡£²¿¤¬»ÈÍѤµ¤ì¤ë¤«¤Ï¡¢
240 ¹Ô¤ÎÆâÍƤˤè¤ê·è¤Þ¤ë¡£
246 ¤ËÌ䤤¹ç¤ï¤»¤ò¹Ô¤¤¡¢¼¡¤¤¤Ç
253 ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
259 char *h_name; /* official name of host */
260 char **h_aliases; /* alias list */
261 int h_addrtype; /* host address type */
262 int h_length; /* length of address */
263 char **h_addr_list; /* list of addresses */
265 #define h_addr h_addr_list[0] /* ²áµî¤È¤Î¸ß´¹À¤Î¤¿¤á */
270 ¹½Â¤ÂΤΥá¥ó¥Ð¤Ï°Ê²¼¤ÎÄ̤ꡣ
273 ¥Û¥¹¥È¤ÎÀµ¼°Ì¾ (official name)¡£
276 ¥Û¥¹¥È¤ÎÊÌ̾¤ÎÇÛÎó¡£ÇÛÎó¤Ï NULL ¥Ý¥¤¥ó¥¿¤Ç½ªÃ¼¤µ¤ì¤ë¡£
279 ¥¢¥É¥ì¥¹¤Î¥¿¥¤¥×¡£¸½ºß¤Ï¤¹¤Ù¤Æ
286 ¥Ð¥¤¥Èñ°Ì¤Çɽ¤·¤¿¥¢¥É¥ì¥¹¤ÎŤµ¡£
289 ¥Û¥¹¥È¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤ÎÇÛÎó¡£
290 ÇÛÎó¤Ï NULL ¥Ý¥¤¥ó¥¿¤Ç½ªÃ¼¤µ¤ì¤ë¡£
291 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ï¥Í¥Ã¥È¥ï¡¼¥¯¥Ð¥¤¥È¥ª¡¼¥À·Á¼°¤Ç¤¢¤ë¡£
295 ¤ÎºÇ½é¤Î¥¢¥É¥ì¥¹¡£²áµî¤È¤Î¸ß´¹À¤òÊݤĤ¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
302 ¹½Â¤ÂΤòÊÖ¤¹¡£¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¤é NULL ¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥¨¥é¡¼¤ÎºÝ¤Ë¤Ï
304 ÊÑ¿ô¤¬¥¨¥é¡¼¤ÎÈÖ¹æ¤òÊÝ»ý¤¹¤ë¡£
305 ÊÖ¤êÃͤ¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢ÀÅŪ¥Ç¡¼¥¿¤ò¥Ý¥¤¥ó¥¿¤Ç»Ø¤·¤Æ¤¤¤ë¤³¤È¤â¤¢¤ë¡£
306 °Ê²¼¤Î¡ÖÃí°Õ¡×¤ò»²¾È¤¹¤ë¤³¤È¡£
309 ÊÑ¿ô¤Ï°Ê²¼¤ÎÃͤò¼è¤ê¤¦¤ë¡£
312 »ØÄꤷ¤¿¥Û¥¹¥È¤¬¸«¤Ä¤«¤é¤Ê¤¤¡£
314 .B NO_ADDRESS " ¤Þ¤¿¤Ï " NO_DATA
315 »ØÄꤷ¤¿Ì¾Á°¤Ï͸ú¤À¤¬ IP ¥¢¥É¥ì¥¹¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
318 ¥Í¡¼¥à¥µ¡¼¥Ð¤ÎÉüµìÉÔǽ¤Ê¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£
321 authoritative ¤Ê¥Í¡¼¥à¥µ¡¼¥Ð¤Ç°ì»þŪ¤Ê¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£
322 »þ´Ö¤ò¤ª¤¤¤Æ¤â¤¦°ìÅٻ¤³¤È¡£
326 ̾Á°²ò·è¤ÎÀßÄê¥Õ¥¡¥¤¥ë
329 ¥Û¥¹¥È¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë
331 .I /etc/nsswitch.conf
332 ¥Í¡¼¥à¥µ¡¼¥Ó¥¹ÀÚÂØÀßÄê
335 .BR gethostbyname (),
336 .BR gethostbyaddr (),
345 ¤ÏÇÑ»ßͽÄê¤Ç¤¢¤ë¤È¤µ¤ì¤Æ¤¤¤ë¡£
347 .BR gethostbyname (),
348 .BR gethostbyaddr (),
350 ¤Î»ÅÍͤ¬ºï½ü¤µ¤ì¤Æ¤¤¤ë¡£
355 ¤Î»ÈÍѤ¬¿ä¾©¤µ¤ì¤Æ¤¤¤ë¡£
360 ´Ø¿ô¤ÏÀÅŪ¥Ç¡¼¥¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
361 ¤³¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢¤½¤Î¸å¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
363 ¹½Â¤ÂΤϥݥ¤¥ó¥¿¤ò´Þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢¹½Â¤ÂΤΥ³¥Ô¡¼¤À¤±¤Ç¤ÏÉÔ½½Ê¬¤Ç¤¢¤ë;
364 ¤è¤ê¿¼¤¤¥³¥Ô¡¼¤¬É¬ÍפǤ¢¤ë¡£
366 ¥ª¥ê¥¸¥Ê¥ë¤Î BSD ¤Î¼ÂÁõ¤Ç¤Ï¡¢
373 SUSv2 ɸ½à¤Ï¥Ð¥°¤¬Â¿¤¯¡¢
379 ·¿¤È¤·¤ÆÀë¸À¤·¤Æ¤¤¤ë¡£
384 ·¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
385 POSIX.1-2001 ¤Ç¤Ï¤³¤ì¤ò
387 ¤È¤·¤Æ¤¤¤ë¤¬¡¢¤³¤ì¤Ï OK¡£)
392 ¤Î BSD ¤Î¥×¥í¥È¥¿¥¤¥×¤Ï¡¢ºÇ½é¤Î°ú¤¿ô¤È¤·¤Æ
395 .SS "System V/POSIX ³ÈÄ¥"
399 ¤³¤Î´Ø¿ô¤Ï¥Û¥¹¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¼¡¤Î¥¨¥ó¥È¥ê¤òÊÖ¤¹¡£
400 DNS/BIND ¤ò»È¤¦¾ì¹ç¤Ï¤¢¤Þ¤ê°ÕÌ£¤ò»ý¤¿¤Ê¤¤¤¬¡¢
401 ¥Û¥¹¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ 1 ¹Ô¤º¤ÄÆɤ߹þ¤Þ¤ì¤ë¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¾ì¹ç¤Ï°ÕÌ£¤¬¤¢¤ë¡£
402 ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¤³¤Î̾Á°¤Î¥ë¡¼¥Á¥ó¤Ï¥Õ¥¡¥¤¥ë
405 .\" Î㤨¤Ð¡¢Linux, FreeBSD, UnixWare, HP-UX
406 DNS ¥µ¥Ý¡¼¥È¤Ê¤·¤Ç¥é¥¤¥Ö¥é¥ê¤¬¥Ó¥ë¥É¤µ¤ì¤¿¾ì¹ç¤Ë¤Î¤ßÍøÍѲÄǽ¤Ç¤¢¤ë¡£
407 .\" Î㤨¤Ð¡¢FreeBSD, AIX
408 glibc ÈÇ¤Ï ipv6 ¥¨¥ó¥È¥ê¤ò̵»ë¤¹¤ë¡£
409 ¤³¤Î´Ø¿ô¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È (reentrant) ¤Ç¤Ï¤Ê¤¯¡¢
410 glibc ¤Ë¤Ï¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤÎ
415 .BR gethostbyname2 ()
418 ¤ÈƱ¤¸¤è¤¦¤ËÆ°ºî¤¹¤ë¤¬¡¢
419 ¤³¤Á¤é¤Ï¥¢¥É¥ì¥¹¤¬Â°¤¹¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
421 glibc2 ¤Ë¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È¤Ê
423 .BR gethostbyaddr_r (),
424 .BR gethostbyname_r ()
426 .BR gethostbyname2_r ()
428 ¸Æ¤Ó½Ð¤·Â¦¤Ï¡¢À®¸ù»þ¤Ë·ë²Ì¤¬³ÊǼ¤µ¤ì¤ë
434 ¤Î°ì»þŪ¤Êºî¶È¥Ð¥Ã¥Õ¥¡
437 ¥³¡¼¥ë½ªÎ»¸å¡¢À®¸ù¤·¤¿¾ì¹ç
440 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¤Þ¤¿¤Ï¥¨¥ó¥È¥ê¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
443 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç 0 ¤òÊÖ¤·¡¢¼ºÇԤξì¹ç¤Ï 0 °Ê³°¤Î¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤¹¡£
444 ¤³¤ì¤é¤Î´Ø¿ô¤Î¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤Ê¤¤¥Ð¡¼¥¸¥ç¥ó¤¬ÊÖ¤¹¥¨¥é¡¼¤Ë²Ã¤¨¤Æ¡¢
449 ¤òÊÖ¤¹¡£¤³¤Î¾ì¹ç¤Ï¤â¤Ã¤ÈÂ礤ʥХåե¡¤òÍÑ°Õ¤·¤Æ
450 ´Ø¿ô¸Æ¤Ó½Ð¤·¤òºÆÅÙ¹Ô¤¦¤Ù¤¤Ç¤¢¤ë¡£
453 ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¤¬¡¢¥¨¥é¡¼ÈÖ¹æ¤ò³ÊǼ¤¹¤ëÊÑ¿ô¤Î¥¢¥É¥ì¥¹¤¬
458 ¤Ï¡¢16¿Ê¿ôɽ¸½¤Î¥É¥Ã¥È¶èÀÚ¤ê¤Î IPv4 ¥¢¥É¥ì¥¹Ê¸»úÎó¤ÎÍ×ÁǤòǧ¼±¤·¤Ê¤¤¡£
459 .\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482973
462 .\" .BR getipnodebyaddr (3),
463 .\" .BR getipnodebyname (3),
470 .BR nsswitch.conf (5),