xref: /csrg-svn/lib/libc/net/gethostbyname.3 (revision 27936)
Copyright (c) 1983 Regents of the University of California.
All rights reserved. The Berkeley software License Agreement
specifies the terms and conditions for redistribution.

@(#)gethostbyname.3 6.2 (Berkeley) 05/10/86

GETHOSTENT 3N ""
C 5
NAME
gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent, sethostfile - 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()

"sethostfile(name)

"char *name;

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:

\w'h_addrtype'u+2n h_name Official name of the host.

\w'h_addrtype'u+2n h_aliases A zero terminated array of alternate names for the host.

\w'h_addrtype'u+2n h_addrtype The type of address being returned; currently always AF_INET.

\w'h_addrtype'u+2n h_length The length, in bytes, of the address.

\w'h_addrtype'u+2n h_addr A pointer to the network address for the 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 gethosbyname or gethostbyaddr .

Endhostent closes the file.

Sethostfile changes the default host table file to name thus allowing these routines to be used with alternate host tables. Note that it does not close the previous file. If this is desired, endhostent should be called prior to it.

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
"SEE ALSO"
hosts(5), resolver(3), named(8)
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.

On sites configured to use the name server named (8) instead of /etc/hosts , gethostent is not available and sethostfile is a no-op.