Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
gethostbyname(3)
Edit
PageHistory
Diff
Info
LikePages
!!NAME gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entry !!SYNOPSIS __#include <netdb.h>__ __extern int__ ''h_errno''__;__ __struct hostent *gethostbyname(const char *__''name''__);__ __struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);__ __#include <sys/socket.h> /* For AF_INET */__ __struct hostent *gethostbyaddr(const char *__''addr''__, int__ ''len''__, int__ ''type''__);__ __void sethostent(int__ ''stayopen''__);__ __void endhostent(void);__ __void herror(const char *__''s''__);__ __const char * hstrerror(int__ ''err''__);__ !!DESCRIPTION The __gethostbyname()__ function returns a structure of type ''hostent'' for the given host ''name''. Here ''name'' is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon (and possibly dot) notation. (See RFC 1884 for the description of IPv6 addresses.) If ''name'' is an IPv4 or IPv6 address, no lookup is performed and __gethostbyname__() simply copies ''name'' into the ''h_name'' field and its ''struct in_addr'' equivalent into the ''h_addr_list[[0]'' field of the returned ''hostent'' structure. If ''name'' doesn't end in a dot and the environment variable __HOSTALIASES__ is set, the alias file pointed to by __HOSTALIASES__ will first be searched for ''name'' (see hostname(7) for the file format). The current domain and its parents are searched unless ''name'' ends in a dot. The __gethostbyaddr()__ function returns a structure of type ''hostent'' for the given host address ''addr'' of length ''len'' and address type ''type''. The only valid address type is currently __AF_INET__. The __sethostent()__ function specifies, if ''stayopen'' is true (1), that a connected TCP socket should be used for the name server queries and that the connection should remain open during successive queries. Otherwise, name server queries will use UDP datagrams. The __endhostent()__ function ends the use of a TCP connection for name server queries. The (obsolete) __herror()__ function prints the error message associated with the current value of ''h_errno'' on stderr. The (obsolete) __hstrerror()__ function takes an error number (typically ''h_errno'') and returns the corresponding message string. The domain name queries carried out by __gethostbyname()__ and __gethostbyaddr()__ use a combination of any or all of the name server named(8), a broken out line from ''/etc/hosts'', and the Network Information Service (NIS or YP), depending upon the contents of the ''order'' line in ''/etc/host.conf''. (See resolv+(8)). The default action is to query named(8), followed by ''/etc/hosts''. The ''hostent'' structure is defined in '''' as follows: 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 */ The members of the ''hostent'' structure are: ;''h_name'': The official name of the host. ;''h_aliases'': A zero-terminated array of alternative names for the host. ;''h_addrtype'': The type of address; always __AF_INET__ at present. ;''h_length'': The length of the address in bytes. ;''h_addr_list'': A zero-terminated array of network addresses for the host in network byte order. ;''h_addr'': The first address in ''h_addr_list'' for backward compatibility. !!RETURN VALUE The __gethostbyname()__ and __gethostbyaddr()__ functions return the ''hostent'' structure or a NULL pointer if an error occurs. On error, the ''h_errno'' variable holds an error number. !!ERRORS The variable ''h_errno'' can have the following values: ;__HOST_NOT_FOUND__: The specified host is unknown. ;__NO_ADDRESS__ or __NO_DATA__: The requested name is valid but does not have an IP address. ;__NO_RECOVERY__: A non-recoverable name server error occurred. ;__TRY_AGAIN__: A temporary error occurred on an authoritative name server. Try again later. !!FILES ;''/etc/host.conf'': resolver configuration file ;''/etc/hosts'': host database file !!CONFORMING TO BSD 4.3. !!NOTES The functions __gethostbyname__() and __gethostbyaddr__() may return pointers to static data, which may be overwritten by later calls. Copying the ''struct hostent'' does not suffice, since it contains pointers - a deep copy is required. The SUS-v2 standard is buggy and declares the ''len'' parameter to be of type ''size_t''. (That is wrong, because it has to be ''int'', and ''size_t'' is not. The Austin draft makes it ''socklen_t'', which is OK.) Glibc2 also has a __struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__);__ that works like __gethostbyname()__, but permits to specify the address family to which the address must belong. The Austin draft marks __gethostbyaddr()__ and __gethostbyname()__ legacy, and introduces __struct hostent *getipnodebyaddr (const void *restrict__ ''addr''__, socklen_t__ ''len''__, int__ ''type''__, int *restrict__ ''error_num''__);__ __struct hostent *getipnodebyname (const char *__''name''__, int__ ''type''__, int__ ''flags''__, int *__''error_num''__);__ !!SEE ALSO resolver(3), hosts(5), hostname(7), resolv+(8), named(8)
42 pages link to
gethostbyname(3)
:
hostname(7)
res_init(3)
res_mkquery(3)
res_query(3)
res_querydomain(3)
res_search(3)
res_send(3)
resolver(3)
Man3g
ERANGE
dn_comp(3)
dn_expand(3)
freehostent(3)
getipnodebyaddr(3)
getipnodebyname(3)
byteorder(3)
host.conf(5)
environ(7)
inet(3)
inet_addr(3)
inet_lnaof(3)
inet_makeaddr(3)
inet_netof(3)
inet_network(3)
htonl(3)
htons(3)
iruserok(3)
nsswitch.conf(5)
ntohl(3)
ntohs(3)
rcmd(3)
resolver(5)
rresvport(3)
ruserok(3)
inet_ntoa(3)
sethostid(2)
gethostid(2)
inet_aton(3)
resolv.conf(5)
NetworkProgrammingOld
named(8)
ip(7)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.