GETHOSTENT(3N) — Series 300 and 800 Only
NAME
gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent − get network host entry
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#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()
DESCRIPTION
Gethostent, gethostbyname, and gethostbyaddr each return a pointer to a structure of type hostent containing the broken-out fields of a line in the network host data base, /etc/hosts.
The members of this structure are:
h_name Official name of the host.
h_aliases A null-terminated array of alternate names for the host.
h_addrtype The type of address being returned; always AF_INET.
h_length The length, in bytes, of the address.
h_addr A pointer to the network address for the host.
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 sequentially searches from the beginning of the file until a host name (among either the official names or the aliases) matching its parameter name is found, or until EOF is encountered.
Gethostbyaddr sequentially searches from the beginning of the file until an internet address matching its parameter addr is found, or until EOF is encountered. The parameter addr must point to an internet address in network order. The parameter len must be the number of bytes in an internet address, that is, sizeof (struct in_addr). The parameter type must be the constant AF_INET. Host addresses are supplied in network order.(See byteorder(3N).)
If the system is running Yellow Pages (NFS), gethostbyname and gethostbyaddr get the host information from the YP server. See ypserv(1M) and ypfiles(4).
RETURN VALUE
Gethostent, gethostbyname and gethostbyaddr return a null pointer (0) on EOF or when they are unable to open /etc/hosts. Gethostbyaddr also returns a null pointer if either its addr or len parameter is invalid.
WARNINGS
All information is contained in a static area so it must be copied if it is to be saved.
DEPENDENCIES
Implemented on Series 300 and 800 only.
AUTHOR
UCB (University of California at Berkeley)
FILES
/etc/hosts
SEE ALSO
ypserv(1M), hosts(4), ypfiles(4).
INTERNATIONAL SUPPORT
8-bit data, messages.
Hewlett-Packard Company — May 11, 2021