gethostbyname(3) — Subroutines
OSF — Environment_Note_Added
NAME
gethostbyname − Gets network host entry by name
LIBRARY
Sockets Library (libc.a)
SYNOPSIS
#include <netdb.h>
struct hostent ∗gethostbyname (
char ∗name );
PARAMETERS
nameSpecifies the official network name or alias.
DESCRIPTION
The gethostbyname() function returns a pointer to a structure of type hostent. Its members specify data obtained from a name server specified in the /etc/resolv.conf file or from fields of a record line in the /etc/hosts network hostname database file. When the name server is not running, this function searches the hosts name file. The netdb.h header file defines the hostent structure.
The gethostbyname() function searches the hosts network hostname file sequentially until a match with the name parameter occurs. If the environment variable HOSTALIASES is set, the gethostbyname() function first searches the file named by HOSTALIASES. The name parameter must specify the host official name or an alias. When EOF (End-Of-File) is reached without a match, an error value is returned by this function.
Use the endhostent() function to close the /etc/hosts file.
NOTES
A return value points to static data, which is overwritten by any subsequently called functions using the same structure.
RETURN VALUES
Upon successful completion, a pointer to a hostent structure is returned. A null pointer is returned whenever the end of the hosts network hostname file is reached.
ERRORS
If the gethostbyname() function fails, h_errno may be set to one of the following values:
[TRY_AGAIN]
This is a soft error that indicates that the local server did not receive a response from an authoritative server. A retry at some later time may be successful.
[NO_RECOVERY]
This is a nonrecoverable error.
[HOST_NOT_FOUND]
The name you have used is not an official hostname or alias; this is not a soft error, another type of name server request may be successful.
[NO_ADDRESS]
The requested name is valid but does not have an Internet address at the name server.
FILES
/etc/hostsThe DARPA Internet network hostname database. Each record in the file occupies a single line and has three fields consisting of the host address, official hostname, and aliases.
/etc/resolv.conf
Contains the name server and domain name.
ENVIRONMENT NOTES
This section describes system features that are not generic to OSF/1 but that are provided in this OSF/1 implementation.
Digital Extensions
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.
RELATED INFORMATION
Functions: gethostent(3), gethostbyaddr(3), endhostent(3)
Files: hostname(5)