1 GETHOSTBYNAME(3) BSD Library Functions Manual GETHOSTBYNAME(3)
4 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
5 - get network host entry
7 S
\bSY
\bYN
\bNO
\bOP
\bPS
\bSI
\bIS
\bS
8 #
\b#i
\bin
\bnc
\bcl
\blu
\bud
\bde
\be <
\b<n
\bne
\bet
\btd
\bdb
\bb.
\b.h
\bh>
\b>
10 _
\be_
\bx_
\bt_
\be_
\br_
\bn _
\bi_
\bn_
\bt _
\bh_
\b__
\be_
\br_
\br_
\bn_
\bo;
12 _
\bs_
\bt_
\br_
\bu_
\bc_
\bt _
\bh_
\bo_
\bs_
\bt_
\be_
\bn_
\bt _
\b*
13 g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be(_
\bc_
\bh_
\ba_
\br _
\b*_
\bn_
\ba_
\bm_
\be);
15 _
\bs_
\bt_
\br_
\bu_
\bc_
\bt _
\bh_
\bo_
\bs_
\bt_
\be_
\bn_
\bt _
\b*
16 g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be2
\b2(_
\bc_
\bh_
\ba_
\br _
\b*_
\bn_
\ba_
\bm_
\be, _
\bi_
\bn_
\bt _
\ba_
\bf);
18 _
\bs_
\bt_
\br_
\bu_
\bc_
\bt _
\bh_
\bo_
\bs_
\bt_
\be_
\bn_
\bt _
\b*
19 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_
\b, _
\bt_
\by_
\bp_
\be);
21 _
\bs_
\bt_
\br_
\bu_
\bc_
\bt _
\bh_
\bo_
\bs_
\bt_
\be_
\bn_
\bt _
\b*
22 g
\bge
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt();
24 s
\bse
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt(_
\bi_
\bn_
\bt _
\bs_
\bt_
\ba_
\by_
\bo_
\bp_
\be_
\bn);
26 e
\ben
\bnd
\bdh
\bho
\bos
\bst
\bte
\ben
\bnt
\bt();
28 h
\bhe
\ber
\brr
\bro
\bor
\br(_
\bc_
\bh_
\ba_
\br _
\b*_
\bs_
\bt_
\br_
\bi_
\bn_
\bg);
30 D
\bDE
\bES
\bSC
\bCR
\bRI
\bIP
\bPT
\bTI
\bIO
\bON
\bN
31 G
\bGe
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be(), g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be2
\b2(), and g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\bya
\bad
\bdd
\bdr
\br() each return a
32 pointer to a _
\bh_
\bo_
\bs_
\bt_
\be_
\bn_
\bt structure (see below) describing an internet host
33 referenced by name or by address, as the function names indicate. This
34 structure contains either the information obtained from the name server,
35 or broken-out fields from a line in _
\b/_
\be_
\bt_
\bc_
\b/_
\bh_
\bo_
\bs_
\bt_
\bs. If the local name server
36 is not running, these routines do a lookup in _
\b/_
\be_
\bt_
\bc_
\b/_
\bh_
\bo_
\bs_
\bt_
\bs.
39 char *h_name; /* official name of host */
40 char **h_aliases; /* alias list */
41 int h_addrtype; /* host address type */
42 int h_length; /* length of address */
43 char **h_addr_list; /* list of addresses from name server */
46 #define h_addr h_addr_list[0] /* address, for backward compatibility */
48 The members of this structure are:
50 h_name Official name of the host.
52 h_aliases A zero-terminated array of alternate names for the host.
54 h_addrtype The type of address being returned; usually AF_INET.
56 h_length The length, in bytes, of the address.
58 h_addr_list A zero-terminated array of network addresses for the host.
59 Host addresses are returned in network byte order.
61 h_addr The first address in h_addr_list; this is for backward com‐
64 When using the nameserver, g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be() will search for the named host
65 in each parent domain given in the “search” directive of resolv.conf(5)
66 unless the name contains a dot (“.”). If the name contains no dot, and
67 if the environment variable HOSTALIASES contains the name of an alias
68 file, the alias file will first be searched for an alias matching the
69 input name. See hostname(7) for the domain search procedure and the
72 G
\bGe
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be2
\b2() is an evolution of g
\bge
\bet
\bth
\bho
\bos
\bst
\btb
\bby
\byn
\bna
\bam
\bme
\be() intended to allow
73 lookups in address families other than AF_INET, for example, AF_INET6.
74 Currently, the _
\ba_
\bf argument must be specified as AF_INET else the function
75 will return NULL after having set _
\bh_
\b__
\be_
\br_
\br_
\bn_
\bo to NETDB_INTERNAL.
77 S
\bSe
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() may be used to request the use of a connected TCP socket for
78 queries. If the _
\bs_
\bt_
\ba_
\by_
\bo_
\bp_
\be_
\bn flag is non-zero, this sets the option to send
79 all queries to the name server using TCP and to retain the connection
80 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,
81 queries are performed using UDP datagrams.
83 E
\bEn
\bnd
\bdh
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() closes the TCP connection.
85 E
\bEN
\bNV
\bVI
\bIR
\bRO
\bON
\bNM
\bME
\bEN
\bNT
\bT
86 HOSTALIASES Name of file containing (_
\bh_
\bo_
\bs_
\bt _
\ba_
\bl_
\bi_
\ba_
\bs, _
\bf_
\bu_
\bl_
\bl _
\bh_
\bo_
\bs_
\bt_
\bn_
\ba_
\bm_
\be) pairs.
89 /etc/hosts See hosts(5).
91 D
\bDI
\bIA
\bAG
\bGN
\bNO
\bOS
\bST
\bTI
\bIC
\bCS
\bS
92 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
93 by return of a null pointer. The external integer _
\bh_
\b__
\be_
\br_
\br_
\bn_
\bo may then be
94 checked to see whether this is a temporary failure or an invalid or
95 unknown host. The routine h
\bhe
\ber
\brr
\bro
\bor
\br() can be used to print an error message
96 describing the failure. If its argument _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is non-NULL, it is
97 printed, followed by a colon and a space. The error message is printed
98 with a trailing newline.
100 _
\bh_
\b__
\be_
\br_
\br_
\bn_
\bo can have the following values:
102 NETDB_INTERNAL This indicates an internal error in the library,
103 unrelated to the network or name service. _
\be_
\br_
\br_
\bn_
\bo
104 will be valid in this case; see perror.
106 HOST_NOT_FOUND No such host is known.
108 TRY_AGAIN This is usually a temporary error and means that
109 the local server did not receive a response from
110 an authoritative server. A retry at some later
113 NO_RECOVERY Some unexpected server failure was encountered.
114 This is a non-recoverable error, as one might
117 NO_DATA The requested name is valid but does not have an
118 IP address; this is not a temporary error. This
119 means that the name is known to the name server
120 but there is no address associated with this
121 name. Another type of request to the name server
122 using this domain name will result in an answer;
123 for example, a mail-forwarder may be registered
126 S
\bSE
\bEE
\bE A
\bAL
\bLS
\bSO
\bO
127 hosts(5), hostname(7), resolver(3), resolver(5).
129 C
\bCA
\bAV
\bVE
\bEA
\bAT
\bT
130 G
\bGe
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() 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,
131 when _
\bl_
\bi_
\bb_
\bc is built to use only the routines to lookup in _
\b/_
\be_
\bt_
\bc_
\b/_
\bh_
\bo_
\bs_
\bt_
\bs and
135 G
\bGe
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() reads the next line of _
\b/_
\be_
\bt_
\bc_
\b/_
\bh_
\bo_
\bs_
\bt_
\bs, opening the file if
138 S
\bSe
\bet
\bth
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() is redefined to open and rewind the file. If the
139 _
\bs_
\bt_
\ba_
\by_
\bo_
\bp_
\be_
\bn argument is non-zero, the hosts data base will not be
140 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().
142 E
\bEn
\bnd
\bdh
\bho
\bos
\bst
\bte
\ben
\bnt
\bt() is redefined to close the file.
145 All information is contained in a static area so it must be copied if it
146 is to be saved. Only the Internet address format is currently under‐
149 4th Berkeley Distribution June 23, 1990 4th Berkeley Distribution