Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gethostent_r(3) — OSF/1 3.0 αXP

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

endhostent(3)

gethostbyaddr(3)

gethostbyname(3)

gethostent(3)  —  Subroutines

NAME

gethostent, gethostent_r, sethostent, sethostent_r − Opens network host file

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <netdb.h>

struct hostent ∗gethostent(void);

int gethostent_r(
        struct hostent ∗host,
        struct hostent_data ∗host_data);

int sethostent(
        int stay_open);

int sethostent_r(
        int stay_open,
        struct hostent_data ∗host_data);

PARAMETERS

hostPoints to the hostent structure. 

host_dataIs data for the hosts database. 

stay_openContains a value used to indicate when to close the host file.  Specifying a value of 0 (zero) closes the /etc/hosts file after each call to the gethostbyname() or gethostbyaddr() function.  Specifying a nonzero value allows the /etc/hosts file to remain open after each call. 

DESCRIPTION

The gethostent() (get host entry) function reads the next line of the /etc/hosts file, opening it if necessary. 

The sethostent() (set host entry) function opens the /etc/hosts file and resets the file marker to the beginning of the file. 

Passing a nonzero value to the stay_open parameter establishes a connection with a name server and allows a client process to retrieve one entry at a time from the /etc/hosts file.  The client process can close the connection with the endhostent() function. 

The gethostent_r() and sethostent_r() functions are reentrant versions of the gethostent() and sethostent() functions.  When gethostent_r() completes successfully, host points to the returned structure. 

The system searches either the local /etc/hosts file or one of the files distributed by BIND or NIS for the requested information.  To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file. 

NOTES

When you first call the sethostent_r() function, you must zero fill the hostent_data structure. The netdb.h header file defines the hostent and hostent_data structures. 

If the system is configured to access the hosts database through NIS, the gethostent_r()  function may not produce correct results if called from multiple threads. 

RETURN VALUES

If an error occurs or if the end of the file is reached, the sethostent() function returns a null pointer to the calling program and an error code, indicating the specific error, is moved into the h_errno variable.  The calling program must examine h_errno to determine the error. 

ERRORS

If the sethostent() function fails, h_errno may be set to the following value:

[NO_RECOVERY]
This error code indicates an unrecoverable error. If the following condition occurs, the sethostent_r() function sets errno to the corresponding value:

[EINVAL]The host_data parameter is invalid. 

In addition, the sethostent() and sethostent_r() functions can fail to open the file.  In this case errno will be set to the failure. 

If the following condition occurs, the gethostent_r() function sets errno to the corresponding value:

[EINVAL]The host or host_data parameter is invalid. 

FILES

/etc/hostsContains the hostname database. 

/etc/resolv.conf
Contains the name server and domain name.

RELATED INFORMATION

Functions: endhostent(3), gethostbyaddr(3), gethostbyname(3)

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