diff options
Diffstat (limited to 'src/lib/libc/net/gethostbyname.3')
-rw-r--r-- | src/lib/libc/net/gethostbyname.3 | 175 |
1 files changed, 98 insertions, 77 deletions
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 index bac0368296..d90ea55542 100644 --- a/src/lib/libc/net/gethostbyname.3 +++ b/src/lib/libc/net/gethostbyname.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $NetBSD: gethostbyname.3,v 1.6 1995/02/25 06:20:28 cgd Exp $ | 1 | .\" $OpenBSD: gethostbyname.3,v 1.17 2002/04/30 16:31:42 mpech Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,17 +31,17 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .\" @(#)gethostbyname.3 8.2 (Berkeley) 4/19/94 | 34 | .Dd March 13, 1997 |
35 | .\" | ||
36 | .Dd April 19, 1994 | ||
37 | .Dt GETHOSTBYNAME 3 | 35 | .Dt GETHOSTBYNAME 3 |
38 | .Os BSD 4.2 | 36 | .Os |
39 | .Sh NAME | 37 | .Sh NAME |
40 | .Nm gethostbyname , | 38 | .Nm gethostbyname , |
39 | .Nm gethostbyname2 , | ||
41 | .Nm gethostbyaddr , | 40 | .Nm gethostbyaddr , |
42 | .Nm gethostent , | 41 | .Nm gethostent , |
43 | .Nm sethostent , | 42 | .Nm sethostent , |
44 | .Nm endhostent , | 43 | .Nm endhostent , |
44 | .Nm hstrerror , | ||
45 | .Nm herror | 45 | .Nm herror |
46 | .Nd get network host entry | 46 | .Nd get network host entry |
47 | .Sh SYNOPSIS | 47 | .Sh SYNOPSIS |
@@ -50,30 +50,37 @@ | |||
50 | .Ft struct hostent * | 50 | .Ft struct hostent * |
51 | .Fn gethostbyname "const char *name" | 51 | .Fn gethostbyname "const char *name" |
52 | .Ft struct hostent * | 52 | .Ft struct hostent * |
53 | .Fn gethostbyaddr "const char *addr" "int len" "int type" | 53 | .Fn gethostbyname2 "const char *name" "int af" |
54 | .Ft struct hostent * | ||
55 | .Fn gethostbyaddr "const char *addr" "int len" "int af" | ||
54 | .Ft struct hostent * | 56 | .Ft struct hostent * |
55 | .Fn gethostent void | 57 | .Fn gethostent void |
58 | .Ft void | ||
56 | .Fn sethostent "int stayopen" | 59 | .Fn sethostent "int stayopen" |
60 | .Ft void | ||
57 | .Fn endhostent void | 61 | .Fn endhostent void |
58 | .Fn herror "char *string" | 62 | .Ft void |
63 | .Fn herror "const char *string" | ||
64 | .Ft const char * | ||
65 | .Fn hstrerror "int err" | ||
59 | .Sh DESCRIPTION | 66 | .Sh DESCRIPTION |
60 | The | 67 | The |
61 | .Fn gethostbyname | 68 | .Fn gethostbyname |
62 | and | 69 | and |
63 | .Fn gethostbyaddr | 70 | .Fn gethostbyaddr |
64 | functions | 71 | functions each return a pointer to an object with the following structure |
65 | each return a pointer to an object with the | 72 | describing an internet host referenced by name or by address, respectively. |
66 | following structure describing an internet host | 73 | This structure contains either information obtained from the name server (i.e., |
67 | referenced by name or by address, respectively. | 74 | .Xr resolver 3 |
68 | This structure contains either the information obtained from the name server, | 75 | and |
69 | .Xr named 8 , | 76 | .Xr named 8 ) , |
70 | broken-out fields from a line in | 77 | broken-out fields from a line in |
71 | .Pa /etc/hosts , | 78 | .Pa /etc/hosts , |
72 | or database entries supplied by the | 79 | or database entries supplied by the |
73 | .Xr yp 8 | 80 | .Xr yp 8 |
74 | system . | 81 | system. |
75 | If the local name server is not running these routines do a lookup in | 82 | .Xr resolv.conf 5 |
76 | .Pa /etc/hosts . | 83 | describes how the particular database is chosen. |
77 | .Bd -literal | 84 | .Bd -literal |
78 | struct hostent { | 85 | struct hostent { |
79 | char *h_name; /* official name of host */ | 86 | char *h_name; /* official name of host */ |
@@ -90,36 +97,48 @@ The members of this structure are: | |||
90 | .It Fa h_name | 97 | .It Fa h_name |
91 | Official name of the host. | 98 | Official name of the host. |
92 | .It Fa h_aliases | 99 | .It Fa h_aliases |
93 | A zero terminated array of alternate names for the host. | 100 | A zero-terminated array of alternate names for the host. |
94 | .It Fa h_addrtype | 101 | .It Fa h_addrtype |
95 | The type of address being returned; currently always | 102 | The type of address being returned. |
96 | .Dv AF_INET . | ||
97 | .It Fa h_length | 103 | .It Fa h_length |
98 | The length, in bytes, of the address. | 104 | The length, in bytes, of the address. |
99 | .It Fa h_addr_list | 105 | .It Fa h_addr_list |
100 | A zero terminated array of network addresses for the host. | 106 | A zero-terminated array of network addresses for the host. |
101 | Host addresses are returned in network byte order. | 107 | Host addresses are returned in network byte order. |
102 | .It Fa h_addr | 108 | .It Fa h_addr |
103 | The first address in | 109 | The first address in |
104 | .Fa h_addr_list ; | 110 | .Fa h_addr_list ; |
105 | this is for backward compatibility. | 111 | this is for backward compatibility. |
112 | .El | ||
106 | .Pp | 113 | .Pp |
107 | When using the nameserver, | 114 | The function |
108 | .Fn gethostbyname | 115 | .Fn gethostbyname |
109 | will search for the named host in the current domain and its parents | 116 | will search for the named host in the current domain and its parents |
110 | unless the name ends in a dot. | 117 | using the search lookup semantics detailed in |
111 | If the name contains no dot, and if the environment variable | 118 | .Xr resolv.conf 5 |
112 | .Dq Ev HOSTALIASES | 119 | and |
113 | contains the name of an alias file, the alias file will first be searched | 120 | .Xr hostname 7 . |
114 | for an alias matching the input name. | 121 | .Pp |
115 | See | 122 | .Fn gethostbyname2 |
116 | .Xr hostname 7 | 123 | is an advanced form of |
117 | for the domain search procedure and the alias file format. | 124 | .Fn gethostbyname |
125 | which allows lookups in address families other than | ||
126 | .Dv AF_INET , | ||
127 | for example | ||
128 | .Dv AF_INET6 . | ||
129 | .Pp | ||
130 | The | ||
131 | .Fn gethostbyaddr | ||
132 | function will search for the specified address of length | ||
133 | .Fa len | ||
134 | in the address family | ||
135 | .Fa af . | ||
136 | The only address family currently supported is | ||
137 | .Dv AF_INET . | ||
118 | .Pp | 138 | .Pp |
119 | The | 139 | The |
120 | .Fn sethostent | 140 | .Fn sethostent |
121 | function | 141 | function may be used to request the use of a connected |
122 | may be used to request the use of a connected | ||
123 | .Tn TCP | 142 | .Tn TCP |
124 | socket for queries. | 143 | socket for queries. |
125 | If the | 144 | If the |
@@ -127,7 +146,7 @@ If the | |||
127 | flag is non-zero, | 146 | flag is non-zero, |
128 | this sets the option to send all queries to the name server using | 147 | this sets the option to send all queries to the name server using |
129 | .Tn TCP | 148 | .Tn TCP |
130 | and to retain the connection after each call to | 149 | and to retain the connection after each call to |
131 | .Fn gethostbyname | 150 | .Fn gethostbyname |
132 | or | 151 | or |
133 | .Fn gethostbyaddr . | 152 | .Fn gethostbyaddr . |
@@ -137,17 +156,33 @@ datagrams. | |||
137 | .Pp | 156 | .Pp |
138 | The | 157 | The |
139 | .Fn endhostent | 158 | .Fn endhostent |
140 | function | 159 | function closes the |
141 | closes the | ||
142 | .Tn TCP | 160 | .Tn TCP |
143 | connection. | 161 | connection. |
162 | .Pp | ||
163 | The | ||
164 | .Fn herror | ||
165 | function prints an error message describing the failure. | ||
166 | If its argument | ||
167 | .Fa string | ||
168 | is non-null, | ||
169 | it is prepended to the message string and separated from it by a colon | ||
170 | .Pq Ql \&: | ||
171 | and a space. | ||
172 | The error message is printed with a trailing newline. | ||
173 | The contents of the error message is the same as that returned by | ||
174 | .Fn hstrerror | ||
175 | with argument | ||
176 | .Fa h_errno . | ||
144 | .Sh FILES | 177 | .Sh FILES |
145 | .Bl -tag -width /etc/hosts -compact | 178 | .Bl -tag -width /etc/resolv.conf -compact |
146 | .It Pa /etc/hosts | 179 | .It Pa /etc/hosts |
180 | .It Pa /etc/resolv.conf | ||
147 | .El | 181 | .El |
148 | .Sh DIAGNOSTICS | 182 | .Sh DIAGNOSTICS |
149 | Error return status from | 183 | Error return status from |
150 | .Fn gethostbyname | 184 | .Fn gethostbyname , |
185 | .Fn gethostbyname2 , | ||
151 | and | 186 | and |
152 | .Fn gethostbyaddr | 187 | .Fn gethostbyaddr |
153 | is indicated by return of a null pointer. | 188 | is indicated by return of a null pointer. |
@@ -155,15 +190,6 @@ The external integer | |||
155 | .Va h_errno | 190 | .Va h_errno |
156 | may then be checked to see whether this is a temporary failure | 191 | may then be checked to see whether this is a temporary failure |
157 | or an invalid or unknown host. | 192 | or an invalid or unknown host. |
158 | The routine | ||
159 | .Fn herror | ||
160 | can be used to print an error message describing the failure. | ||
161 | If its argument | ||
162 | .Fa string | ||
163 | is | ||
164 | .Pf non Dv -NULL , | ||
165 | it is printed, followed by a colon and a space. | ||
166 | The error message is printed with a trailing newline. | ||
167 | .Pp | 193 | .Pp |
168 | The variable | 194 | The variable |
169 | .Va h_errno | 195 | .Va h_errno |
@@ -180,8 +206,8 @@ A retry at some later time may succeed. | |||
180 | Some unexpected server failure was encountered. | 206 | Some unexpected server failure was encountered. |
181 | This is a non-recoverable error. | 207 | This is a non-recoverable error. |
182 | .It Dv NO_DATA | 208 | .It Dv NO_DATA |
183 | The requested name is valid but does not have an IP address; | 209 | The requested name is valid but does not have an IP address; |
184 | this is not a temporary error. | 210 | this is not a temporary error. |
185 | This means that the name is known to the name server but there is no address | 211 | This means that the name is known to the name server but there is no address |
186 | associated with this name. | 212 | associated with this name. |
187 | Another type of request to the name server using this domain name | 213 | Another type of request to the name server using this domain name |
@@ -190,52 +216,42 @@ for example, a mail-forwarder may be registered for this domain. | |||
190 | .El | 216 | .El |
191 | .Sh SEE ALSO | 217 | .Sh SEE ALSO |
192 | .Xr resolver 3 , | 218 | .Xr resolver 3 , |
219 | .Xr getaddrinfo 3 , | ||
220 | .Xr getnameinfo 3 , | ||
193 | .Xr hosts 5 , | 221 | .Xr hosts 5 , |
222 | .Xr resolv.conf 5 , | ||
194 | .Xr hostname 7 , | 223 | .Xr hostname 7 , |
195 | .Xr named 8 | 224 | .Xr named 8 |
196 | .Sh CAVEAT | 225 | .Sh CAVEATS |
197 | The | 226 | If the search routines in |
198 | .Fn gethostent | 227 | .Xr resolv.conf 5 |
199 | function | 228 | decide to read the |
200 | is defined, and | ||
201 | .Fn sethostent | ||
202 | and | ||
203 | .Fn endhostent | ||
204 | are redefined, | ||
205 | when | ||
206 | .Xr libc 3 | ||
207 | is built to use only the routines to lookup in | ||
208 | .Pa /etc/hosts | 229 | .Pa /etc/hosts |
209 | and not the name server. | 230 | file, |
210 | .Pp | ||
211 | The | ||
212 | .Fn gethostent | 231 | .Fn gethostent |
213 | function | 232 | and other functions will |
214 | reads the next line of | 233 | read the next line of the file, |
215 | .Pa /etc/hosts , | 234 | re-opening the file if necessary. |
216 | opening the file if necessary. | ||
217 | .Pp | 235 | .Pp |
218 | The | 236 | The |
219 | .Fn sethostent | 237 | .Fn sethostent |
220 | function | 238 | function opens and/or rewinds the file |
221 | opens and/or rewinds the file | ||
222 | .Pa /etc/hosts . | 239 | .Pa /etc/hosts . |
223 | If the | 240 | If the |
224 | .Fa stayopen | 241 | .Fa stayopen |
225 | argument is non-zero, | 242 | argument is non-zero, the file will not be closed after each call to |
226 | the file will not be closed after each call to | 243 | .Fn gethostbyname , |
227 | .Fn gethostbyname | 244 | .Fn gethostbyname2 , |
228 | or | 245 | or |
229 | .Fn gethostbyaddr . | 246 | .Fn gethostbyaddr . |
230 | .Pp | 247 | .Pp |
231 | The | 248 | The |
232 | .Fn endhostent | 249 | .Fn endhostent |
233 | function | 250 | function closes the file. |
234 | closes the file. | ||
235 | .Sh HISTORY | 251 | .Sh HISTORY |
236 | The | 252 | The |
237 | .Fn herror | 253 | .Fn herror |
238 | function appeared in | 254 | function appeared in |
239 | .Bx 4.3 . | 255 | .Bx 4.3 . |
240 | The | 256 | The |
241 | .Fn endhostent , | 257 | .Fn endhostent , |
@@ -251,4 +267,9 @@ These functions use static data storage; | |||
251 | if the data is needed for future use, it should be | 267 | if the data is needed for future use, it should be |
252 | copied before any subsequent calls overwrite it. | 268 | copied before any subsequent calls overwrite it. |
253 | Only the Internet | 269 | Only the Internet |
254 | address format is currently understood. | 270 | address formats are currently understood. |
271 | .Pp | ||
272 | YP does not support any address families other than | ||
273 | .Dv AF_INET | ||
274 | and uses | ||
275 | the traditional database format. | ||