Rechercher une page de manuel
gethostbyname
Langue: ja
Version: 2004-10-31 (openSuse - 09/10/07)
Section: 3 (Bibliothèques de fonctions)
̾Á°
gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent, herror, hstrerror - ¥Í¥Ã¥È¥ï¡¼¥¯¾å¤Î¥Û¥¹¥È¤Î¥¨¥ó¥È¥ê¤ò¼èÆÀ¤¹¤ë½ñ¼°
#include <netdb.h> extern int h_errno; struct hostent *gethostbyname(const char *name); #include <sys/socket.h> /* AF_INET ¤ò»È¤¦¾ì¹ç */ struct hostent *gethostbyaddr(const void *addr, int len, int type); void sethostent(int stayopen); void endhostent(void); void herror(const char *s); const char *hstrerror(int err); /* System V/POSIX ³ÈÄ¥ */
struct hostent *gethostent(void); /* GNU ³ÈÄ¥ */
struct hostent *gethostbyname2(const char *name, int af); int gethostent_r( struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); int gethostbyname2_r(const char *name, int af, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop);
ÀâÌÀ
gethostbyname() ´Ø¿ô¤ÏÍ¿¤¨¤é¤ì¤¿¥Û¥¹¥È̾ name ¤ËÂбþ¤¹¤ë¹½Â¤ÂÎ hostent ¤òÊÖ¤¹¡£¤³¤³¤Ç name ¤Ï¥Û¥¹¥È̾¡¢¥É¥Ã¥È¶èÀÚ¤ê¤Î IPv4 ¥¢¥É¥ì¥¹¡¢¥³¥í¥ó¶èÀÚ¤ê¤Î (¥É¥Ã¥È¶èÀÚ¤ê¤Ç¤âÂç¾æÉפ«¤â¤·¤ì¤Ê¤¤) IPv6 ¥¢¥É¥ì¥¹¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£ (IPv6 ¥¢¥É¥ì¥¹¤Îµ½Ò¤Ë¤Ä¤¤¤Æ¤Ï RFC 1884 ¤ò»²¹Í¤Ë¤·¤Æ¤Û¤·¤¤)¡£ name ¤¬ IPv4 ¤« IPv6 ¤Î¥¢¥É¥ì¥¹¤À¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢ ̾Á°°ú¤ (lookup) ¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£ gethostbyname() ¤Ïñ¤Ë name ¤ò¤½¤Î¤Þ¤Þ hostent ¹½Â¤ÂΤΠh_name ¥Õ¥£¡¼¥ë¥É¤Ë¥³¥Ô¡¼¤·¡¢ ¤µ¤é¤Ë name ¤ò struct in_addr ·Á¼°¤Çɽ¤·¤¿¥Ç¡¼¥¿¤òƱ¹½Â¤ÂΤΠh_addr_list[0] ¥Õ¥£¡¼¥ë¥É¤ËÆþ¤ì¤Æ¡¢¤½¤Î¹½Â¤ÂΤòÊÖ¤¹¡£ name ¤¬¥É¥Ã¥È¤Ç½ªÎ»¤·¤Æ¤¤¤Æ¡¢¤«¤Ä´Ä¶ÊÑ¿ô HOSTALIASES ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤Þ¤º HOSTALIASES ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¥¨¥¤¥ê¥¢¥¹¥Õ¥¡¥¤¥ë¤«¤é name ¤Î¥¨¥ó¥È¥ê¤¬¸¡º÷¤µ¤ì¤ë (¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Ï hostname(7) ¤ò»²¾È¤Î¤³¤È)¡£ name ¤¬¥É¥Ã¥È¤Ç½ªÎ»¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¸½ºß¤Î¥É¥á¥¤¥ó¤È¤½¤Î¿Æ¥É¥á¥¤¥ó¤¬¸¡º÷¤µ¤ì¤ë¡£gethostbyaddr() ´Ø¿ô¤ÏÍ¿¤¨¤é¤ì¤¿¥Û¥¹¥È¥¢¥É¥ì¥¹ addr (Ťµ len¡¢ ¥¿¥¤¥× type) ¤ËÂбþ¤¹¤ë¹½Â¤ÂÎ hostent ¤òÊÖ¤¹¡£ ÍѤ¤¤ë¤³¤È¤Î¤Ç¤¤ë¥¿¥¤¥×¤Ï AF_INET ¤È AF_INET6 ¤Ç¤¢¤ë¡£ ¥Û¥¹¥È¥¢¥É¥ì¥¹°ú¤¿ô¤Ï¥¢¥É¥ì¥¹¥¿¥¤¥×¤Ë°Í¸¤·¤¿ ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£ Î㤨¤Ð¡¢¥¢¥É¥ì¥¹¥¿¥¤¥× AF_INET ¤ËÂФ·¤Æ¤Ï (inet_addr(3) ¤Î¸Æ¤Ó½Ð¤·¤ÇÆÀ¤é¤ì¤ë) struct in_addr * ¤Ç¤¢¤ë¡£
sethostent() ´Ø¿ô¤Ï¡¢¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ø¤ÎÀܳÍͼ°¤ò»ØÄꤹ¤ë¡£ stayopen ¤¬¿¿ (1) ¤Ê¤é¤Ð¡¢¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ø¤ÎÌ䤤¹ç¤ï¤»¤Ë¤Ï¡¢ Àܳ¤µ¤ì¤¿ TCP ¥½¥±¥Ã¥È¤òÍѤ¤¡¢Ï¢Â³¤·¤¿Ì䤤¹ç¤ï¤»¤Î´Ö¤ËÀܳ¤ò°Ý»ý¤¹¤ë¡£ µ¶¤Ê¤é¤Ð¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ø¤ÎÌ䤤¹ç¤ï¤»¤Ë UDP ¥Ç¡¼¥¿¥°¥é¥à¤òÍѤ¤¤ë¡£
endhostent() ´Ø¿ô¤Ï¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ø¤ÎÌ䤤¹ç¤ï¤»¤ËÍѤ¤¤¿ TCP Àܳ¤ÎÍøÍѤò½ªÎ»¤¹¤ë¡£
herror() ´Ø¿ô (¤â¤¦¸Å¤¤) ¤Ï¸½ºß¤Î h_errno ¤ËÂбþ¤¹¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò stderr ¤Ë½ÐÎϤ¹¤ë¡£
hsterror() ´Ø¿ô (¤â¤¦¸Å¤¤) ¤Ï¥¨¥é¡¼ÈÖ¹æ (ŵ·¿Åª¤Ë¤Ï h_errno) ¤ò °ú¤¿ô¤Ë¼è¤ê¡¢Âбþ¤¹¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸Ê¸»úÎó¤òÊÖ¤¹¡£
gethostbyname() ¤È gethostbyaddr() ¤Ë¤è¤Ã¤Æ¼Â¹Ô¤µ¤ì¤ë¥É¥á¥¤¥ó̾¤ÎÌ䤤¹ç¤ï¤»¤Ç¤Ï¡¢¥Í¡¼¥à¥µ¡¼¥Ð¡¼ named(8)¡¢ /etc/hosts ¤Î¥Ç¡¼¥¿¹Ô¡¢¤ª¤è¤Ó Network Information Service (NIS ¤Þ¤¿¤Ï YP) ¤Î¤¤¤º¤ì¤«¡¢¤¢¤ë¤¤¤Ï¤¹¤Ù¤Æ¤¬ÍѤ¤¤é¤ì¤ë¡£¤³¤ì¤Ï /etc/host.conf ¤Î order ¹Ô¤ÎÆâÍƤ˰͸¤¹¤ë ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¤Þ¤º named(8) ¤ËÌ䤤¹ç¤ï¤»¡¢¼¡¤¤¤Ç /etc/hosts ¤ò±ÜÍ÷¤¹¤ë¡£
hostent ¹½Â¤ÂÎ¤Ï <netdb.h> Ãæ¤Ç°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
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 */ } #define h_addr h_addr_list[0] /* for backward compatibility */
hostent ¹½Â¤ÂΤΥá¥ó¥Ð¤Ï°Ê²¼¤ÎÄ̤ꡣ
- h_name
- ¥Û¥¹¥È¤ÎÀµ¼°Ì¾ (official name)¡£
- h_aliases
- ¥Û¥¹¥È¤ÎÊÌ̾¤ÎÇÛÎó¡£ÇÛÎó¤Ï NULL ¥Ý¥¤¥ó¥¿¤Ç½ªÃ¼¤µ¤ì¤ë¡£
- h_addrtype
- ¥¢¥É¥ì¥¹¤Î¥¿¥¤¥×¡£¸½ºß¤Ï¤¹¤Ù¤Æ AF_INET ¤Þ¤¿¤Ï AF_INET6 ¤Ç¤¢¤ë¡£
- h_length
- ¥Ð¥¤¥Èñ°Ì¤Çɽ¤·¤¿¥¢¥É¥ì¥¹¤ÎŤµ¡£
- h_addr_list
- ¥Û¥¹¥È¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤ÎÇÛÎó¡£ ÇÛÎó¤Ï NULL ¥Ý¥¤¥ó¥¿¤Ç½ªÃ¼¤µ¤ì¤ë¡£ ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ï¥Í¥Ã¥È¥ï¡¼¥¯¥Ð¥¤¥È¥ª¡¼¥À¡¼·Á¼°¤Ç¤¢¤ë¡£
- h_addr
- h_addr_list ¤ÎºÇ½é¤Î¥¢¥É¥ì¥¹¡£²áµî¤È¤Î¸ß´¹À¤òÊݤĤ¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
ÊÖ¤êÃÍ
gethostbyname() ¤ª¤è¤Ó gethostbyaddr() ´Ø¿ô¤Ï hostent ¹½Â¤ÂΤòÊÖ¤¹¡£¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¤é NULL ¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¥¨¥é¡¼¤ÎºÝ¤Ë¤Ï h_errno ÊÑ¿ô¤¬¥¨¥é¡¼¤ÎÈÖ¹æ¤òÊÝ»ý¤¹¤ë¡£ ÊÖ¤êÃͤ¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢ÀÅŪ¥Ç¡¼¥¿¤ò¥Ý¥¤¥ó¥¿¤Ç»Ø¤·¤Æ¤¤¤ë¤³¤È¤â¤¢¤ë¡£ °Ê²¼¤Î¡ÖÃí°Õ¡×¤ò»²¾È¤¹¤ë¤³¤È¡£¥¨¥é¡¼
h_errno ÊÑ¿ô¤Ï°Ê²¼¤ÎÃͤò¼è¤ê¤¦¤ë¡£- HOST_NOT_FOUND
- »ØÄꤷ¤¿¥Û¥¹¥È¤¬¸«¤Ä¤«¤é¤Ê¤¤¡£
- NO_ADDRESS ¤Þ¤¿¤Ï NO_DATA
- »ØÄꤷ¤¿Ì¾Á°¤Ï͸ú¤À¤¬ IP ¥¢¥É¥ì¥¹¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£
- NO_RECOVERY
- ¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤ÎÉüµìÉÔǽ¤Ê¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£
- TRY_AGAIN
- authoritative ¤Ê¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤Ç°ì»þŪ¤Ê¥¨¥é¡¼¤¬µ¯¤³¤Ã¤¿¡£»þ´Ö¤ò¤ª¤¤¤Æ ¤â¤¦°ìÅٻ¤³¤È¡£
¥Õ¥¡¥¤¥ë
- /etc/host.conf
- ̾Á°²ò·è¤ÎÀßÄê¥Õ¥¡¥¤¥ë
- /etc/hosts
- ¥Û¥¹¥È¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë
- /etc/nsswitch.conf
- ¥Í¡¼¥à¥µ¡¼¥Ó¥¹ÀÚÂØÀßÄê
½àµò
4.3BSD, POSIX.1-2001.Ãí°Õ
gethostbyname() ¤ª¤è¤Ó gethostbyaddr() ´Ø¿ô¤ÏÀÅŪ¥Ç¡¼¥¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£ ¤³¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢¤½¤Î¸å¤Î¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£ hostent ¹½Â¤ÂΤϥݥ¤¥ó¥¿¤ò´Þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢¹½Â¤ÂΤΥ³¥Ô¡¼¤À¤±¤Ç¤ÏÉÔ½½Ê¬¤Ç¤¢¤ë; ¤è¤ê¿¼¤¤¥³¥Ô¡¼¤¬É¬ÍפǤ¢¤ë¡£SUS-v2 ¤Ï¥Ð¥°¤¬Â¿¤¯¡¢ gethostbyaddr() ¤Î len ¥Ñ¥é¥á¡¼¥¿¤ò size_t ·¿¤È¤·¤ÆÀë¸À¤·¤Æ¤¤¤ë¡£ (¤³¤ì¤Ï¸í¤ê¤Ç¡¢ size_t ·¿¤Ç¤Ï¤Ê¤¯ int ·¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ POSIX.1-2001 ¤Ç¤Ï¤³¤ì¤ò socklen_t ¤È¤·¤Æ¤¤¤ë¤¬¡¢¤³¤ì¤Ï OK¡£)
gethostbyaddr() ¤Î BSD ¤Î¥×¥í¥È¥¿¥¤¥×¤Ï¡¢ºÇ½é¤Î°ú¤¿ô¤È¤·¤Æ const char * ¤ò»È¤¦¡£
POSIX.1-2001 ¤Ç¤Ï gethostbyaddr() ¤ª¤è¤Ó gethostbyname() ¤òÇѤ줫¤«¤Ã¤¿¤â¤Î¤È¤µ¤ì¤Æ¤¤¤ë¡£ getaddrinfo(3), getnameinfo(3), gai_strerror(3) ¤ò»²¾È¡£
System V/POSIX ³ÈÄ¥
POSIX ¤Ç¤Ï¡¢¥Û¥¹¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¼¡¤Î¥¨¥ó¥È¥ê¤òÊÖ¤¹ gethostent() ¥³¡¼¥ë¤òɬÍפȤ¹¤ë¡£ DNS/BIND ¤ò»È¤¦¾ì¹ç¤Ï¤¢¤Þ¤ê°ÕÌ£¤ò»ý¤¿¤Ê¤¤¤¬¡¢ ¥Û¥¹¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ 1 ¹Ô¤º¤ÄÆɤ߹þ¤Þ¤ì¤ë¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë¾ì¹ç¤Ï°ÕÌ£¤¬¤¢¤ë¡£ ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¤³¤Î̾Á°¤Î¥ë¡¼¥Á¥ó¤Ï¥Õ¥¡¥¤¥ë /etc/hosts ¤òÆɤ߹þ¤à¡£ DNS ¥µ¥Ý¡¼¥È¤Ê¤·¤Ç¥é¥¤¥Ö¥é¥ê¤¬¥Ó¥ë¥É¤µ¤ì¤¿¾ì¹ç¤Ë¤Î¤ßÍøÍѲÄǽ¤Ç¤¢¤ë¡£ glibc ÈÇ¤Ï ipv6 ¥¨¥ó¥È¥ê¤ò̵»ë¤¹¤ë¡£ ¤³¤Î´Ø¿ô¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È (reentrant) ¤Ç¤Ï¤Ê¤¯¡¢ glibc ¤Ë¤Ï¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤΠgethostent_r() ¤¬Äɲ䵤줿¡£GNU ³ÈÄ¥
glibc2 ¤Ë¤Ï gethostbyname2() ¤â¤¢¤ê¡¢ gethostbyname() ¤ÈƱ¤¸¤è¤¦¤ËÆ°ºî¤¹¤ë¤¬¡¢ ¤³¤Á¤é¤Ï¥¢¥É¥ì¥¹¤¬Â°¤¹¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£glibc2 ¤Ë¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È¤Ê gethostbyname_r() ¤È gethostbyname2_r() ¤â¤¢¤ë¡£ ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¤Ï 0 ¤òÊÖ¤·¡¢¼ºÇÔ¤·¤¿¾ì¹ç¤Ï 0 °Ê³°¤òÊÖ¤¹¡£ ¸½ºß¤Î¤È¤³¤í¡¢¤³¤Î¸Æ¤Ó½Ð¤·¤Î·ë²Ì¤Ï¥¢¥É¥ì¥¹¤¬ ret ¤Î¹½Â¤ÂΤ˳ÊǼ¤µ¤ì¤ë¡£ ¸Æ¤Ó½Ð¤·¤Î¸å¡¢¼ºÇÔ¤·¤¿¾ì¹ç¤Ï *result ¤¬ NULL ¤Ë¤Ê¤ê¡¢À®¸ù¤·¤¿¾ì¹ç¤Ï *result ¤¬·ë²Ì¤ò»Ø¤·¼¨¤¹¡£ Êä¥ǡ¼¥¿¤ÏŤµ buflen ¤Î¥Ð¥Ã¥Õ¥¡ buf ¤Ë³ÊǼ¤µ¤ì¤ë¡£ (¥Ð¥Ã¥Õ¥¡¤¬¾®¤µ¤¹¤®¤ë¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï ERANGE ¤òÊÖ¤¹¡£) Âç°èÊÑ¿ô h_errno ¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¤¬¡¢¥¨¥é¡¼ÈÖ¹æ¤ò³ÊǼ¤¹¤ëÊÑ¿ô¤Î¥¢¥É¥ì¥¹¤¬ h_errnop ¤ËÅϤµ¤ì¤ë¡£
´ØÏ¢¹àÌÜ
getaddrinfo(3), getipnodebyaddr(3), getipnodebyname(3), getnameinfo(3), inet_ntop(3), inet_pton(3), resolver(3), hosts(5), nsswitch.conf(5), hostname(7), named(8)Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre