Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gethostbyname(3n) — Ultrix WS 1.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ypclnt(3yp)

hosts(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 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.

structhostent {
char*h_name;/* official name of host */
char**h_aliases;/* alias list */
inth_addrtype;/* address type */
inth_length;/* length of address */
char*h_addr;/* address */
};

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 reads the next line of the file, opening the file if necessary.

The sethostent subroutine opens and rewinds the file.  If the stayopen flag is nonzero, the host data base will not be closed after each call to gethostent (either directly, or indirectly through one of the other gethost calls).

The endhostent subroutine closes the file.

The gethostbyname and gethostbyaddr subroutines 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.

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, getgrent does not return the entries in any particular order.

RETURN VALUE

Null pointer (0) returned on EOF or error. 

FILES

/etc/hosts

SEE ALSO

ypclnt(3yp), hosts(5)

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