Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
endhostent(3)
Edit
PageHistory
Diff
Info
LikePages
GETHOSTBYNAME !!!GETHOSTBYNAME NAME SYNOPSIS DESCRIPTION RETURN VALUE ERRORS FILES CONFORMING TO NOTES SEE ALSO ---- !!NAME gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entry !!SYNOPSIS __#include __''name''__); struct hostent *gethostbyname2(const char *__''name''__, int__ ''af''__); #include __''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) ----
One page links to
endhostent(3)
:
Man3e
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.