gethostent(3N) gethostent(3N)
NAME
gethostent, gethostbyaddr, gethostbyname, sethostent,
endhostent - get network host entry
SYNOPSIS
#include <netdb.h>
struct hostent *gethostent()
struct hostent *gethostbyname(name)
char *name;
struct hostent *gethostbyaddr(addr, len, type)
char *addr; int len, type;
sethostent(stayopen)
int stayopen
endhostent()
cc ... -lnet
DESCRIPTION
gethostent, gethostbyname, and gethostbyaddr 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.
struct hostent {
char *h_name; /*official name of host*/
char **h_aliases; /*alias list*/
int h_addrtype; /*address type*/
int h_length; /*length of address*/
char *h_addr; /*address*/
};
The members of this structure are:
hname Official name of the host.
haliases A zero terminated array of alternate names for
the host.
haddrtype The type of address being returned; currently
always AFINET.
hlength The length, in bytes, of the address.
haddr A pointer to the network address for the host.
Host addresses are returned in network byte
order.
Page 1 (last mod. 1/14/87)
gethostent(3N) gethostent(3N)
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).
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 EOF is encountered. Host
addresses are supplied in network order.
FILES
/etc/hosts
LINKING
This library is accessed by specifying -lnet as the last
argument to the compile line, e.g.:
cc -o prog prog.c -lnet
SEE ALSO
hosts(4N)
DIAGNOSTICS
Null pointer (0) returned on EOF or error.
BUGS
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 (last mod. 1/14/87)