#include <sys/types.h> #include <sys/socket.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()
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. In the case of gethostbyaddr(), addr is a pointer to the binary format address of length len (not a character string).
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_list; /* list of addresses from name server */ };
The members of this structure are:
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 end-of-file is encountered. Host addresses are supplied in network order.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97