gethostent(3N) gethostent(3N)
NAME
gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent - get
host names
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
struct hostent *gethostent(void);
struct hostent *gethostbyaddr(const char *addr, int len, int type);
struct hostent *gethostbyname(const char *name);
void sethostent(int stayopen);
void endhostent(void);
DESCRIPTION
gethostbyaddr() and gethostbyname() each return a pointer to an object
with the structure hostent describing an internet host referenced by
name or by address, respectively. Depending on the listed dynamic
libraries in /etc/netconfig, this structure contains either the infor-
mation obtained from a DNS name server, named(1M) (resolv.so), or
broken-out fields from a line in /etc/hosts (tcpip.so). If a library
fails, the next one will be used.
gethostent() delivers the information from /etc/hosts.
gethostbyaddr() takes as the addr argument a pointer to the binary
format address of length len (not a character string) (see below).
Applications should be linked with the option -lsocket.
struct hostent {
char *hname; /* official name of host */
char **haliases; /* alias list */
int haddrtype; /* address type */
int hlength; /* length of address */
char **haddrlist; /* list of addresses */
};
#define haddr haddrlist[0] /* address, for backward compatibility */
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.
Page 1 Reliant UNIX 5.44 Printed 11/98
gethostent(3N) gethostent(3N)
hlength The length, in bytes, of the address.
haddrlist A pointer to a list of network addresses for the named
host. Host addresses are returned in network byte order.
When using the nameserver, gethostbyname() will search for the named
host in the current domain and its parents unless the name ends in a
dot. If the name contains no dot, and if the environment variable
HOSTALAIASES contains the name of an alias file, the alias file will
first be searched for an alias matching the input name.
gethostent() reads the next line of the file /etc/hosts, opening the
file if necessary. If the file has already been opened by a previous
read operation, the function supplies the next entry.
sethostent() opens and rewinds the file. If the stayopen flag is non-
zero, the file /etc/hosts will not be closed after each call to
gethostent() (either directly, or indirectly through one of the other
"gethost" calls).
endhostent() closes the file.
When using tcpip.so, gethostbyname() and gethostbyaddr() search the
/etc/hosts file sequentially (starting from the beginning of the
file), until a suitable host name or suitable host address has been
found, or until EOF has been reached. Host addresses are supplied in
network order.
gethostbyaddr() takes a pointer to an address structure. This struc-
ture is unique to each address of the type type. For an address of
type AFINET this is inaddr structure. See also <netinet/in.h>.
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.
FILES
/etc/hosts (/etc/inet/hosts)
/etc/netconfig
/usr/lib/libsocket.so
/usr/lib/resolv.so
/usr/lib/tcpip.so
Page 2 Reliant UNIX 5.44 Printed 11/98
gethostent(3N) gethostent(3N)
SEE ALSO
named(1M), resolver(3N), netconfig(4), hosts(4), in(5).
Page 3 Reliant UNIX 5.44 Printed 11/98