HP-UX Reference (11i v3 07/02) - 3 Library Functions A-M (vol 6)

g
gethostent(3N) gethostent(3N)
gethostent() Always returns a NULL pointer.
sethostent() Requests the use of a connected stream socket for queries to the name server
if the stayopen flag is non-zero. The connection is retained after each call to
gethostbyname()
or gethostbyaddr()
.
endhostent() Closes the stream socket connection.
gethostbyname()
gethostbyaddr()
Each retrieves host information from the name server. Names are matched
without respect to uppercase or lowercase. For example,
berkeley.edu ,
Berkeley.EDU , and BERKELEY.EDU all match the entry for
berkeley.edu .
NIS Server Operation
If ypserv, the server for the Network Information Service (see ypserv(1M)), is used for name or address
resolution, then the function:
gethostent() Returns the next entry in the NIS database.
sethostent() Initializes an internal key for the NIS database. If the stayopen flag is non-
zero, the internal key is not cleared after calls to endhostent() .
endhostent() Clears the internal NIS database key.
gethostbyname()
gethostbyaddr()
Each retrieves host information from the NIS database. Names are matched
without respect to uppercase or lowercase. For example,
berkeley.edu ,
Berkeley.EDU , and BERKELEY.EDU all match the entry for
berkeley.edu .
Nonserver Operation
If the /etc/hosts file is used for name or address resolution, then the function:
gethostent() Reads the next line of /etc/hosts , opening the file if necessary.
sethostent() Opens and rewinds the file. If the stayopen flag is non-zero, the host data
base is not closed after each call to gethostent() (either directly or
indirectly through one of the other gethost calls).
endhostent() Closes the file.
gethostbyname() Sequentially searches from the beginning of the file until a host name (among
either the official names or the aliases) matching its name parameter is
found, or until EOF is encountered. Names are matched without respect to
uppercase or lowercase, as described above in the name server case.
gethostbyaddr() Sequentially searches from the beginning of the file until an Internet address
matching its addr parameter is found, or until EOF is encountered.
The return value, struct hostent, must be saved before a subsequent call to the functions
gethost*() , getaddrinfo(), and
getnameinfo().
In a multithreaded application,
gethostent() , gethostbyaddr(), and
gethostbyname() use
thread-specific storage that is re-used in each call. The return value,
struct hostent, should be unique
for each thread and should be saved, if desired, before the thread makes the next gethost*() call. The
return value must be saved before a subsequent call to the function getaddrinfo() or get-
nameinfo()
, because these functions may internally call the gethost*() function which may
overwrite their return value.
For enumeration in multithreaded applications, the position within the enumeration is a process-wide pro-
perty shared by all threads. sethostent() may be used in a multithreaded application, but resets the
enumeration position for all threads. If multiple threads interleave calls to gethostent() , the threads
will enumerate disjoint subsets of the host database.
Arguments
Currently, only the Internet address format is understood. In calls to gethostbyaddr(), the parame-
ter addr must be a pointer to an in_addr structure, an Internet address in network order (see
byteorder(3N)) and the header file <netinet/in.h>). The parameter len must be the number of bytes
in an Internet address; that is, sizeof (struct in_addr). The parameter type must be the
HP-UX 11i Version 3: February 2007 2 Hewlett-Packard Company 519