.\" @(#)gethostent 40.6 90/01/29 SMI; from UCB 4.2 BSD
.\" Copyright 1989 AT&T
.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
.nr X
.if \nX=0 .ds x} gethostent 3N "" "\&"
.if \nX=1 .ds x} gethostent 3N ""
.if \nX=2 .ds x} gethostent 3N "" "\&"
.if \nX=3 .ds x} gethostent "" "" "\&"
.TH \*(x}
.SH NAME
\f4gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent\fP \- get network host entry
.SH SYNOPSIS
.nf
.ft 4
#include <sys/types.h>
#include <sys/socket.h>
.\"please check on the location of the following include file
#include <netdb.h>
.P
.ft 4
struct hostent *gethostent(\|)
.P
.ft 4
struct hostent *gethostbyaddr(addr, len, type)
char *addr;
int len, type;
.P
.ft 4
struct hostent *gethostbyname(name)
char *name;
.P
.ft 4
sethostent(stayopen)
int stayopen
.P
.ft 4
endhostent(\|)
.ft R
.fi
.SH DESCRIPTION
.P
\f4gethostent(\|)\fR,
\f4gethostbyaddr(\|)\fR,
and
\f4gethostbyname(\|)\fR
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,
\f4/etc/hosts\fR.
In the case of
\f4gethostbyaddr(\|)\fR,
\f2addr\fR
is a pointer to the binary format address of length
\f2len\fR
(not a character string).
.RS
.P
.nf
.ft 4
\s-1struct	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_list;	/* list of addresses from name server */
};\s+1
.ft R
.fi
.RE
.P
The members of this structure are:
.RS
.TP 20
\f2h_name\fR
Official name of the host.
.TP
\f2h_aliases\fR
A zero terminated array of alternate names for the host.
.TP
\f2h_addrtype\fR
The type of address being returned; currently always
\f4\s-1AF_INET\s0\fR.
.TP
\f2h_length\fR
The length, in bytes, of the address.
.TP
\f2h_addr_list\fR
A pointer to a list of network addresses for the named host.
Host addresses are returned in network byte order.
.RE
.P
\f4gethostent(\|)\fR
reads the next line of the file, opening the file if necessary.
.P
\f4sethostent(\|)\fR
opens and rewinds the file.  If the
\f2stayopen\fR
flag is non-zero,
the host data base will not be closed after each call to
\f4gethostent(\|)\fR
(either directly, or indirectly through one of the other
\*(lqgethost\*(rq calls).
.P
\f4endhostent(\|)\fR
closes the file.
.P
\f4gethostbyname(\|)\fR
and
\f4gethostbyaddr(\|)\fR
sequentially search from the beginning
of the file until a matching
host name or host address is found,
or until an
\s-1EOF\s0
is encountered.
Host addresses are supplied in network order.
.P
\f4gethostbyaddr(\|)\fR
takes a pointer to an address structure.
This structure is unique to each type of address.
For addres of type
\f4\s-1AF_INET\s0\fR
this is 
\f4in_addr\fR
structure.
See
\f4<netinet/in.h>\fR.
.SH FILES
.PD 0
.TP 20
\f4/etc/hosts\fR
.PD
.SH "SEE ALSO"
\f4hosts\fR(4)
.SH DIAGNOSTICS
.P
A
\s-1NULL\s0
pointer is returned on an
\s-1EOF\s0
or error.
.SH BUGS
.P
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.
