Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ypclnt(3yp)

hosts(5)

svcorder(5)

gethostent(3n)

NAME

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

SYNTAX

#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

The gethostent, gethostbyname, and gethostbyaddr subroutines return a pointer to an object with the following structure containing the broken-out fields reflecting information obtained from either the /etc/hosts database, or one or the name services identified in the /etc/svcorder file:

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 */
#define  h_addr h_addr_list[0] /* address for backward compatibility */
};

The members of this structure are:

h_name Official name of the host. 

h_aliases A zero terminated array of alternate names for the host. 

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

h_length The length, in bytes, of the address. 

h_addr A pointer to the network address for the host.  Host addresses are returned in network byte order. 

The gethostent subroutine obtains the next entry from the selected database.

The sethostent subroutine initializes access to the selected database. If the stayopen flag is nonzero, the selected database will not be closed after each call to the gethostent subroutine (either directly, or indirectly through one of the other gethost calls).

The endhostent subroutine closes the selected name service.

The gethostbyname and gethostbyaddr subroutines search the selected name service until a matching host name or host address is found, or until EOF is encountered. Host addresses are supplied in network order.

The gethostbyname and gethostbyaddr subroutines query the /etc/hosts file by default. They will also query any other name services listed in the /etc/svcorder file, such as the BIND or Yellow Pages service.

RESTRICTIONS

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. 

If YP is running, gethostent does not return the entries in any particular order.

The BIND service does not support the sethostent, endhostent, and gethostent interfaces.

RETURN VALUE

Null pointer (0) returned on EOF or error. 

FILES

/etc/hosts

SEE ALSO

ypclnt(3yp), hosts(5), svcorder(5)

Subroutines

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026