gethostent(3N) UNIX System V gethostent(3N)
NAME
gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent - get
network host entry
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
struct hostent *gethostent(void);
struct hostent *gethostbyaddr(char *addr, int len, int type);
struct hostent *gethostbyname(char *name);
int sethostent(int stayopen);
int endhostent(void);
DESCRIPTION
gethostent, gethostbyaddr, and gethostbyname each return a pointer to an
object with the following structure containing the broken-out fields of a
line in the network host data base, /etc/hosts. In the case of
gethostbyaddr, addr is a pointer to the binary format address of length
len (not a character string).
The hostent structure has the following members:
char *hname; /* official name of host */
char **haliases; /* alias list */
int haddrtype; /* host address type */
int hlength; /* length of address */
char **haddrlist; /* list of addresses from name server */
The members of this structure are:
h_name Official name of the host.
h_aliases A zero terminated array of alternate names for the
host.
h_addrtype The type of address being returned; currently always
AFINET.
h_length The length, in bytes, of the address.
h_addr_list A pointer to a list of network addresses for the named
host. Host addresses are returned in network byte
order.
gethostent reads the next line of the file, opening the file if
necessary.
sethostent opens and rewinds the file. If the stayopen flag is non-zero,
the host data base will not be closed after each call to gethostent
(either directly, or indirectly through one of the other gethost calls).
10/89 Page 1
gethostent(3N) UNIX System V gethostent(3N)
endhostent closes the file.
gethostbyname and gethostbyaddr sequentially search from the beginning of
the file until a matching host name or host address is found, or until an
EOF is encountered. Host addresses are supplied in network order.
gethostbyaddr takes a pointer to an address structure. This structure is
unique to each type of address. For address of type AFINET this is an
inaddr structure. See netinet/in.h for the inaddr structure
definition.
FILES
/etc/hosts
SEE ALSO
hosts(4)
DIAGNOSTICS
A NULL pointer is returned on an EOF or error.
NOTES
All information is contained in a static area so it must be copied if it
is to be saved. Only the Internet address format is currently
understood.
Page 2 10/89