gethostbyname(3) Library Functions Manual gethostbyname(3) gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent, h_errno, herror, hstrerror, gethostbyaddr_r, gethostbyname2, gethostbyname2_r, gethostbyname_r, gethostent_r - (libc -lc) #include void sethostent(int stayopen); void endhostent(void); [[deprecated]] extern int h_errno; [[deprecated]] struct hostent *gethostbyname(const char *name); [[deprecated]] struct hostent *gethostbyaddr(socklen_t size; const void addr[size], socklen_t size, int type); [[deprecated]] void herror(const char *s); [[deprecated]] const char *hstrerror(int err); /* System V/POSIX extension */ struct hostent *gethostent(void); /* GNU extensions */ [[deprecated]] struct hostent *gethostbyname2(const char *name, int af); int gethostent_r(size_t bufsize; struct hostent *restrict ret, char buf[restrict bufsize], size_t bufsize, struct hostent **restrict result, int *restrict h_errnop); [[deprecated]] int gethostbyaddr_r(socklen_t size, size_t bufsize; const void addr[restrict size], socklen_t size, int type, struct hostent *restrict ret, char buf[restrict bufsize], size_t bufsize, struct hostent **restrict result, int *restrict h_errnop); [[deprecated]] int gethostbyname_r(size_t bufsize; const char *restrict name, struct hostent *restrict ret, char buf[restrict bufsize], size_t bufsize, struct hostent **restrict result, int *restrict h_errnop); [[deprecated]] int gethostbyname2_r(size_t bufsize; const char *restrict name, int af, struct hostent *restrict ret, char buf[restrict bufsize], size_t bufsize, struct hostent **restrict result, int *restrict h_errnop); glibc ( feature_test_macros(7)): gethostbyname2(), gethostent_r(), gethostbyaddr_r(), gethostbyname_r(), gethostbyname2_r(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19: _BSD_SOURCE || _SVID_SOURCE herror(), hstrerror(): glibc 2.19: _DEFAULT_SOURCE glibc 2.8 glibc 2.19: _BSD_SOURCE || _SVID_SOURCE glibc 2.8: none h_errno: glibc 2.19 _DEFAULT_SOURCE || _POSIX_C_SOURCE < 200809L glibc 2.12 glibc 2.19: _BSD_SOURCE || _SVID_SOURCE || _POSIX_C_SOURCE < 200809L glibc 2.12: none gethostbyname*(), gethostbyaddr*(), herror(), hstrerror() . getaddrinfo(3), getnameinfo(3), gai_strerror(3) . sethostent() stayopen (1) TCP . UDP. endhostent() TCP . gethostbyname() hostent name. name IPv4 ( inet_addr(3)). name IPv4 gethostbyname() name h_name struct in_addr h_addr_list[0] hostent . name HOSTALIASES name HOSTALIASES ( hostname(7) ). name . gethostbyaddr() hostent addr size type. AF_INET AF_INET6 ( ). struct in_addr * ( inet_addr(3)) AF_INET. () herror() h_errno stderr. () hstrerror() ( h_errno) . gethostbyname() gethostbyaddr() (nsswitch.conf(5)) (named(8)). (nsswitch.conf(5)) (named(8)). nsswitch.conf(5) . glibc 2.4 order /etc/host.conf (host.conf(5)). hostent : struct hostent { char *h_name; /* */ char **h_aliases; /* */ int h_addrtype; /* */ int h_length; /* */ char **h_addr_list; /* */ } #define h_addr h_addr_list[0] /* */ hostent : h_name . h_aliases . h_addrtype AF_INET AF_INET6 . h_length . h_addr_list ( ) . h_addr h_addr_list . gethostbyname() gethostbyaddr() hostent . h_errno . . h_errno : HOST_NOT_FOUND . NO_DATA IP. . NO_ADDRESS NO_DATA. NO_RECOVERY . TRY_AGAIN . . /etc/host.conf (resolver) /etc/hosts /etc/nsswitch.conf attributes(7). +----------------------+------------------------------------+----------+ | | | | +----------------------+------------------------------------+----------+ |gethostbyname() | | MT-Unsafe | | | | race:hostbyname | | | | env | | | | locale | +----------------------+------------------------------------+----------+ |gethostbyaddr() | | MT-Unsafe | | | | race:hostbyaddr | | | | env | | | | locale | +----------------------+------------------------------------+----------+ |sethostent() | | MT-Unsafe | |endhostent() | | race:hostent | |gethostent_r() | | env | | | | locale | +----------------------+------------------------------------+----------+ |herror() | | MT-Safe | |hstrerror() | | | +----------------------+------------------------------------+----------+ |gethostent() | | MT-Unsafe | | | | race:hostent | | | | race:hostentbuf | | | | env | | | | locale | +----------------------+------------------------------------+----------+ |gethostbyname2() | | MT-Unsafe | | | | race:hostbyname2 | | | | env | | | | locale | +----------------------+------------------------------------+----------+ |gethostbyaddr_r() | | | |gethostbyname_r() | | | |gethostbyname2_r() | | | | | | | | | | | | | | (MT-Safe) | +----------------------+------------------------------------+----------+ hostent race:hostent sethostent() gethostent() gethostent_r() endhostent() . sethostent() endhostent() gethostent() POSIX.1-2008. gethostent_r() GNU. : . sethostent() endhostent() gethostent() POSIX.1-2001. gethostbyname() gethostbyaddr() h_errno POSIX.1-2001. POSIX.1-2008 getaddrinfo(3) getnameinfo(3) . gethostbyname() gethostbyaddr() . struct hostent . BSD size gethostbyname() int. SUSv2 size gethostbyaddr() size_t. ( int size_t . POSIX.1-2001 socklen_t .) accept(2). BSD gethostbyaddr() const char * . System V/POSIX POSIX gethostent() . DNS/BIND . /etc/hosts. DNS. glibc ipv6. glibc gethostent_r(). glibc2 gethostbyname2() gethostbyname() . glibc2 gethostent_r() gethostbyaddr_r() gethostbyname_r() gethostbyname2_r(). hostent ret buf bufsize. result . result NULL. 0 . buf ERANGE . h_errno h_errnop. gethostbyname() IPv4 . getaddrinfo(3), getnameinfo(3), inet(3), inet_ntop(3), inet_pton(3), resolver(3), hosts(5), nsswitch.conf(5), hostname(7), named(8) 3 . . : . 6.18 8 2026 gethostbyname(3)