Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Apropos / Subsearch:
optional field

GETHOSTENT(3N)                                                  GETHOSTENT(3N)

       gethostent,  gethostbyaddr, gethostbyname, sethostent, endhostent - get
       network host entry

       #include <&lt;sys/types.h>&gt;
       #include <&lt;sys/socket.h>&gt;
       #include <&lt;netdb.h>&gt;

       struct hostent *gethostent()

       struct hostent *gethostbyname(name)
       char *name;

       struct hostent *gethostbyaddr(addr, len, type)
       char *addr;
       int len, type;

       int stayopen

       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:

       h_name              Official name of the host.

       h_aliases           A zero terminated array of alternate names for  the

       h_addrtype          The  type  of  address  being  returned;  currently
                           always AF_INET.

       h_length            The length, in bytes, of the address.

       h_addr_list         A pointer to a list of network  addresses  for  the
                           named host.  Host addresses are returned in network
                           byte order.

       gethostent() reads the next line of the file, opening the file if  nec-

       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  gethos-
       tent()  (either directly, or indirectly through one of the other "geth-
       ost" calls).

       endhostent() closes the file.

       gethostbyname() and gethostbyaddr() sequentially search from the begin-
       ning  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.


       hosts(5), ypserv(8)

       A NULL pointer is returned on end-of-file or error.

       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

                               7 September 1988                 GETHOSTENT(3N)