BSD 4_4 development
[unix-history] / usr / share / man / cat3 / gethostbyaddr.0
GETHOSTBYNAME(3) BSD Programmer's Manual GETHOSTBYNAME(3)
N\bNA\bAM\bME\bE
g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be, g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br, g\bge\bet\bth\bho\bos\bst\bte\ben\bnt\bt, s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt, e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt, h\bhe\ber\brr\bro\bor\br
- get network host entry
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<n\bne\bet\btd\bdb\bb.\b.h\bh>\b>
e\bex\bxt\bte\ber\brn\bn s\bst\btr\bru\buc\bct\bt h\bh_\b_e\ber\brr\brn\bno\bo;\b;
_\bs_\bt_\br_\bu_\bc_\bt _\bh_\bo_\bs_\bt_\be_\bn_\bt _\b*
g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be(_\bc_\bh_\ba_\br _\b*_\bn_\ba_\bm_\be);
_\bs_\bt_\br_\bu_\bc_\bt _\bh_\bo_\bs_\bt_\be_\bn_\bt _\b*
g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br(_\bc_\bh_\ba_\br _\b*_\ba_\bd_\bd_\br, _\bi_\bn_\bt _\bl_\be_\bn, _\bi_\bn_\bt _\bt_\by_\bp_\be);
_\bs_\bt_\br_\bu_\bc_\bt _\bh_\bo_\bs_\bt_\be_\bn_\bt _\b*
g\bge\bet\bth\bho\bos\bst\bte\ben\bnt\bt(_\bv_\bo_\bi_\bd);
s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt(_\bi_\bn_\bt _\bs_\bt_\ba_\by_\bo_\bp_\be_\bn);
e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt(_\bv_\bo_\bi_\bd);
h\bhe\ber\brr\bro\bor\br(_\bc_\bh_\ba_\br _\b*_\bs_\bt_\br_\bi_\bn_\bg);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be() and g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br() functions each return a pointer
to an object with the following structure describing an internet host
referenced by name or by address, respectively. This structure contains
either the information obtained from the name server, named(8), or bro-
ken-out fields from a line in _\b/_\be_\bt_\bc_\b/_\bh_\bo_\bs_\bt_\bs. If the local name server is not
running these routines do a lookup in _\b/_\be_\bt_\bc_\b/_\bh_\bo_\bs_\bt_\bs.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host 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:
_\bh_\b__\bn_\ba_\bm_\be Official name of the host.
_\bh_\b__\ba_\bl_\bi_\ba_\bs_\be_\bs A zero terminated array of alternate names for the host.
_\bh_\b__\ba_\bd_\bd_\br_\bt_\by_\bp_\be The type of address being returned; currently always
AF_INET.
_\bh_\b__\bl_\be_\bn_\bg_\bt_\bh The length, in bytes, of the address.
_\bh_\b__\ba_\bd_\bd_\br_\b__\bl_\bi_\bs_\bt A zero terminated array of network addresses for the host.
Host addresses are returned in network byte order.
_\bh_\b__\ba_\bd_\bd_\br The first address in _\bh_\b__\ba_\bd_\bd_\br_\b__\bl_\bi_\bs_\bt; this is for backward com-
patiblity.
When using the nameserver, g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be() will search for
the named host in the current domain and its parents unless
the name ends in a dot. If the name contains no dot, and if
the environment variable ``HOSTALIASES'' contains the name
of an alias file, the alias file will first be searched for
an alias matching the input name. See hostname(7) for the
domain search procedure and the alias file format.
The s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt() function may be used to request the use of
a connected TCP socket for queries. If the _\bs_\bt_\ba_\by_\bo_\bp_\be_\bn flag is
non-zero, this sets the option to send all queries to the
name server using TCP and to retain the connection after
each call to g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be() or g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br(). Otherwise,
queries are performed using UDP datagrams.
The e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt() function closes the TCP connection.
F\bFI\bIL\bLE\bES\bS
/etc/hosts
D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS
Error return status from g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be() and g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br() is indicated
by return of a null pointer. The external integer _\bh_\b__\be_\br_\br_\bn_\bo may then be
checked to see whether this is a temporary failure or an invalid or un-
known host. The routine h\bhe\ber\brr\bro\bor\br() can be used to print an error message
describing the failure. If its argument _\bs_\bt_\br_\bi_\bn_\bg is non-NULL, it is print-
ed, followed by a colon and a space. The error message is printed with a
trailing newline.
The variable _\bh_\b__\be_\br_\br_\bn_\bo can have the following values:
HOST_NOT_FOUND No such host is known.
TRY_AGAIN This is usually a temporary error and means that the lo-
cal server did not receive a response from an authorita-
tive server. A retry at some later time may succeed.
NO_RECOVERY Some unexpected server failure was encountered. This is
a non-recoverable error.
NO_DATA The requested name is valid but does not have an IP ad-
dress; this is not a temporary error. This means that
the name is known to the name server but there is no ad-
dress associated with this name. Another type of request
to the name server using this domain name will result in
an answer; for example, a mail-forwarder may be regis-
tered for this domain.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
resolver(3), hosts(5), hostname(7), named(8)
C\bCA\bAV\bVE\bEA\bAT\bT
The g\bge\bet\bth\bho\bos\bst\bte\ben\bnt\bt() function is defined, and s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt() and e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt()
are redefined, when libc(3) is built to use only the routines to lookup
in _\b/_\be_\bt_\bc_\b/_\bh_\bo_\bs_\bt_\bs and not the name server.
The g\bge\bet\bth\bho\bos\bst\bte\ben\bnt\bt() function reads the next line of _\b/_\be_\bt_\bc_\b/_\bh_\bo_\bs_\bt_\bs, opening the
file if necessary.
The s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt() function opens and/or rewinds the file _\b/_\be_\bt_\bc_\b/_\bh_\bo_\bs_\bt_\bs. If
the _\bs_\bt_\ba_\by_\bo_\bp_\be_\bn argument is non-zero, the file will not be closed after each
call to g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be() or g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br().
The e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt() function closes the file.
H\bHI\bIS\bST\bTO\bOR\bRY\bY
The h\bhe\ber\brr\bro\bor\br() function appeared in 4.3BSD. The e\ben\bnd\bdh\bho\bos\bst\bte\ben\bnt\bt(),
g\bge\bet\bth\bho\bos\bst\btb\bby\bya\bad\bdd\bdr\br(), g\bge\bet\bth\bho\bos\bst\btb\bby\byn\bna\bam\bme\be(), g\bge\bet\bth\bho\bos\bst\bte\ben\bnt\bt(), and s\bse\bet\bth\bho\bos\bst\bte\ben\bnt\bt() func-
tions appeared in 4.2BSD.
B\bBU\bUG\bGS\bS
These functions use static data storage; if the data is needed for future
use, it should be copied before any subsequent calls overwrite it. Only
the Internet address format is currently understood.
4.2 Berkeley Distribution June 4, 1993 3