diff options
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.3')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 264 |
1 files changed, 101 insertions, 163 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 index ed8b082970..e74fdf6ed7 100644 --- a/src/lib/libc/net/getaddrinfo.3 +++ b/src/lib/libc/net/getaddrinfo.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getaddrinfo.3,v 1.28 2004/04/14 10:06:03 jmc Exp $ | 1 | .\" $OpenBSD: getaddrinfo.3,v 1.29 2004/12/06 10:46:35 jmc Exp $ |
2 | .\" $KAME: getaddrinfo.3,v 1.29 2001/02/12 09:24:45 itojun Exp $ | 2 | .\" $KAME: getaddrinfo.3,v 1.29 2001/02/12 09:24:45 itojun Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 4 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
@@ -36,8 +36,7 @@ | |||
36 | .\" | 36 | .\" |
37 | .Sh NAME | 37 | .Sh NAME |
38 | .Nm getaddrinfo , | 38 | .Nm getaddrinfo , |
39 | .Nm freeaddrinfo , | 39 | .Nm freeaddrinfo |
40 | .Nm gai_strerror | ||
41 | .Nd nodename-to-address translation in protocol-independent manner | 40 | .Nd nodename-to-address translation in protocol-independent manner |
42 | .\" | 41 | .\" |
43 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
@@ -49,8 +48,6 @@ | |||
49 | "const struct addrinfo *hints" "struct addrinfo **res" | 48 | "const struct addrinfo *hints" "struct addrinfo **res" |
50 | .Ft void | 49 | .Ft void |
51 | .Fn freeaddrinfo "struct addrinfo *ai" | 50 | .Fn freeaddrinfo "struct addrinfo *ai" |
52 | .Ft "char *" | ||
53 | .Fn gai_strerror "int ecode" | ||
54 | .\" | 51 | .\" |
55 | .Sh DESCRIPTION | 52 | .Sh DESCRIPTION |
56 | The | 53 | The |
@@ -62,6 +59,67 @@ and | |||
62 | .Xr getservbyname 3 , | 59 | .Xr getservbyname 3 , |
63 | but in a more sophisticated manner. | 60 | but in a more sophisticated manner. |
64 | .Pp | 61 | .Pp |
62 | All of the information returned by | ||
63 | .Fn getaddrinfo | ||
64 | is dynamically allocated: | ||
65 | the | ||
66 | .Li addrinfo | ||
67 | structures, the socket address structures, and canonical node name | ||
68 | strings pointed to by the addrinfo structures. | ||
69 | To return this information to the system the function | ||
70 | .Fn freeaddrinfo | ||
71 | is called. | ||
72 | The | ||
73 | .Fa addrinfo | ||
74 | structure pointed to by the | ||
75 | .Fa ai | ||
76 | argument is freed, | ||
77 | along with any dynamic storage pointed to by the structure. | ||
78 | This operation is repeated until a | ||
79 | .Dv NULL | ||
80 | .Fa ai_next | ||
81 | pointer is encountered. | ||
82 | .Pp | ||
83 | To aid applications in printing error messages based on the | ||
84 | .Dv EAI_xxx | ||
85 | codes returned by | ||
86 | .Fn getaddrinfo , | ||
87 | .Fn gai_strerror | ||
88 | is defined. | ||
89 | See | ||
90 | .Xr gai_strerror 3 | ||
91 | for more information. | ||
92 | .Pp | ||
93 | The implementation allows experimental numeric IPv6 address notation with | ||
94 | scope identifier. | ||
95 | By appending the percent character and scope identifier to addresses, | ||
96 | you can fill the | ||
97 | .Li sin6_scope_id | ||
98 | field for addresses. | ||
99 | This would make management of scoped address easier, | ||
100 | and allows cut-and-paste input of scoped address. | ||
101 | .Pp | ||
102 | At this moment the code supports only link-local addresses with the format. | ||
103 | Scope identifier is hardcoded to the name of the hardware interface associated | ||
104 | with the link | ||
105 | .Po | ||
106 | such as | ||
107 | .Li ne0 | ||
108 | .Pc . | ||
109 | An example is | ||
110 | .Dq Li fe80::1%ne0 , | ||
111 | which means | ||
112 | .Do | ||
113 | .Li fe80::1 | ||
114 | on the link associated with the | ||
115 | .Li ne0 | ||
116 | interface | ||
117 | .Dc . | ||
118 | .Pp | ||
119 | The IPv6 implementation is still very experimental and non-standard. | ||
120 | The current implementation assumes a one-to-one relationship between | ||
121 | the interface and link, which is not necessarily true from the specification. | ||
122 | .Pp | ||
65 | The | 123 | The |
66 | .Li addrinfo | 124 | .Li addrinfo |
67 | structure is defined as a result of including the | 125 | structure is defined as a result of including the |
@@ -168,7 +226,7 @@ structure the three members | |||
168 | and | 226 | and |
169 | .Fa ai_protocol | 227 | .Fa ai_protocol |
170 | are the corresponding arguments for a call to the | 228 | are the corresponding arguments for a call to the |
171 | .Fn socket | 229 | .Xr socket 2 |
172 | function. | 230 | function. |
173 | In each | 231 | In each |
174 | .Li addrinfo | 232 | .Li addrinfo |
@@ -179,15 +237,17 @@ specified by the | |||
179 | .Fa ai_addrlen | 237 | .Fa ai_addrlen |
180 | member. | 238 | member. |
181 | .Pp | 239 | .Pp |
240 | The | ||
241 | .Fa ai_flags | ||
242 | argument can be set to any of the following values, OR'd together: | ||
243 | .Bl -tag -width "AI_NUMERICHOSTXX" | ||
244 | .It AI_PASSIVE | ||
182 | If the | 245 | If the |
183 | .Dv AI_PASSIVE | 246 | .Dv AI_PASSIVE |
184 | bit is set in the | 247 | bit is set, |
185 | .Fa ai_flags | 248 | the caller plans to use the returned socket address |
186 | member of the | ||
187 | .Fa hints | ||
188 | structure, then the caller plans to use the returned socket address | ||
189 | structure in a call to | 249 | structure in a call to |
190 | .Fn bind . | 250 | .Xr bind 2 . |
191 | In this case, if the | 251 | In this case, if the |
192 | .Fa nodename | 252 | .Fa nodename |
193 | argument is a null pointer, then the IP address portion of the socket | 253 | argument is a null pointer, then the IP address portion of the socket |
@@ -199,73 +259,64 @@ for an IPv6 address. | |||
199 | .Pp | 259 | .Pp |
200 | If the | 260 | If the |
201 | .Dv AI_PASSIVE | 261 | .Dv AI_PASSIVE |
202 | bit is not set in the | 262 | bit is not set, |
203 | .Fa ai_flags | 263 | the returned socket address structure will be ready for a |
204 | member of the | ||
205 | .Fa hints | ||
206 | structure, then the returned socket address structure will be ready for a | ||
207 | call to | 264 | call to |
208 | .Fn connect | 265 | .Xr connect 2 |
209 | .Pq for a connection-oriented protocol | 266 | .Pq for a connection-oriented protocol |
210 | or either | 267 | or either |
211 | .Fn connect , | 268 | .Xr connect 2 , |
212 | .Fn sendto , | 269 | .Xr sendto 2 , |
213 | or | 270 | or |
214 | .Fn sendmsg | 271 | .Xr sendmsg 2 |
215 | .Pq for a connectionless protocol . | 272 | .Pq for a connectionless protocol . |
216 | In this case, if the | 273 | In this case, if the |
217 | .Fa nodename | 274 | .Fa nodename |
218 | argument is a null pointer, then the IP address portion of the | 275 | argument is a null pointer, then the IP address portion of the |
219 | socket address structure will be set to the loopback address. | 276 | socket address structure will be set to the loopback address. |
220 | .Pp | 277 | .It AI_CANONNAME |
221 | If the | 278 | If the |
222 | .Dv AI_CANONNAME | 279 | .Dv AI_CANONNAME |
223 | bit is set in the | 280 | bit is set, |
224 | .Fa ai_flags | 281 | then upon successful return the |
225 | member of the | ||
226 | .Fa hints | ||
227 | structure, then upon successful return the | ||
228 | .Fa ai_canonname | 282 | .Fa ai_canonname |
229 | member of the first | 283 | member of the first |
230 | .Li addrinfo | 284 | .Li addrinfo |
231 | structure in the linked list will point to a NUL-terminated string | 285 | structure in the linked list will point to a NUL-terminated string |
232 | containing the canonical name of the specified | 286 | containing the canonical name of the specified |
233 | .Fa nodename . | 287 | .Fa nodename . |
234 | .Pp | 288 | .It AI_NUMERICHOST |
235 | If the | 289 | If the |
236 | .Dv AI_NUMERICHOST | 290 | .Dv AI_NUMERICHOST |
237 | bit is set in the | 291 | bit is set, |
238 | .Fa ai_flags | 292 | then a non-null |
239 | member of the | ||
240 | .Fa hints | ||
241 | structure, then a non-null | ||
242 | .Fa nodename | 293 | .Fa nodename |
243 | string must be a numeric host address string. | 294 | string must be a numeric host address string. |
244 | Otherwise an error of | 295 | Otherwise an error of |
245 | .Dv EAI_NONAME | 296 | .Dv EAI_NONAME |
246 | is returned. | 297 | is returned. |
247 | This flag prevents any type of name resolution service (e.g., the DNS) | 298 | This flag prevents any type of name resolution service, |
299 | such as DNS, | ||
248 | from being called. | 300 | from being called. |
249 | .Pp | 301 | .It AI_NUMERICSERV |
250 | If the | 302 | If the |
251 | .Dv AI_NUMERICSERV | 303 | .Dv AI_NUMERICSERV |
252 | bit is set in the | 304 | bit is set, |
253 | .Fa ai_flags | 305 | then a non-null |
254 | member of the | ||
255 | .Fa hints | ||
256 | structure, then a non-null | ||
257 | .Fa servname | 306 | .Fa servname |
258 | string must be a numeric port string. | 307 | string must be a numeric port string. |
259 | Otherwise an error of | 308 | Otherwise an error of |
260 | .Dv EAI_NONAME | 309 | .Dv EAI_NONAME |
261 | is returned. | 310 | is returned. |
262 | This flag prevents any type of name resolution service (e.g., the NIS) | 311 | This flag prevents any type of name resolution service, |
312 | such as NIS, | ||
263 | from being called. | 313 | from being called. |
314 | .El | ||
264 | .Pp | 315 | .Pp |
265 | The arguments to | 316 | The arguments to |
266 | .Fn getaddrinfo | 317 | .Fn getaddrinfo |
267 | must sufficiently be consistent and unambiguous. | 318 | must be sufficiently consistent and unambiguous. |
268 | Here are pitfall cases you may encounter: | 319 | Issues to watch out for are: |
269 | .Bl -bullet | 320 | .Bl -bullet |
270 | .It | 321 | .It |
271 | .Fn getaddrinfo | 322 | .Fn getaddrinfo |
@@ -322,72 +373,13 @@ does not identify any socket type, and | |||
322 | .Fn getaddrinfo | 373 | .Fn getaddrinfo |
323 | is not allowed to glob the argument in such case. | 374 | is not allowed to glob the argument in such case. |
324 | .El | 375 | .El |
325 | .Pp | ||
326 | All of the information returned by | ||
327 | .Fn getaddrinfo | ||
328 | is dynamically allocated: | ||
329 | the | ||
330 | .Li addrinfo | ||
331 | structures, the socket address structures, and canonical node name | ||
332 | strings pointed to by the addrinfo structures. | ||
333 | To return this information to the system the function | ||
334 | .Fn freeaddrinfo | ||
335 | is called. | ||
336 | The | ||
337 | .Fa addrinfo | ||
338 | structure pointed to by the | ||
339 | .Fa ai argument | ||
340 | is freed, along with any dynamic storage pointed to by the structure. | ||
341 | This operation is repeated until a | ||
342 | .Dv NULL | ||
343 | .Fa ai_next | ||
344 | pointer is encountered. | ||
345 | .Pp | ||
346 | To aid applications in printing error messages based on the | ||
347 | .Dv EAI_xxx | ||
348 | codes returned by | ||
349 | .Fn getaddrinfo , | ||
350 | .Fn gai_strerror | ||
351 | is defined. | ||
352 | The argument is one of the | ||
353 | .Dv EAI_xxx | ||
354 | values defined earlier and the return value points to a string describing | ||
355 | the error. | ||
356 | If the argument is not one of the | ||
357 | .Dv EAI_xxx | ||
358 | values, the function still returns a pointer to a string whose contents | ||
359 | indicate an unknown error. | ||
360 | .\" | 376 | .\" |
361 | .Ss Extension for scoped IPv6 address | 377 | .Sh RETURN VALUES |
362 | The implementation allows experimental numeric IPv6 address notation with | 378 | .Fn getaddrinfo |
363 | scope identifier. | 379 | returns zero on success, and non-zero on errors. |
364 | By appending the percent character and scope identifier to addresses, | 380 | See |
365 | you can fill the | 381 | .Xr gai_strerror 3 |
366 | .Li sin6_scope_id | 382 | for a description of the non-zero error codes. |
367 | field for addresses. | ||
368 | This would make management of scoped address easier, | ||
369 | and allows cut-and-paste input of scoped address. | ||
370 | .Pp | ||
371 | At this moment the code supports only link-local addresses with the format. | ||
372 | Scope identifier is hardcoded to the name of the hardware interface associated | ||
373 | with the link. | ||
374 | .Po | ||
375 | such as | ||
376 | .Li ne0 | ||
377 | .Pc . | ||
378 | An example is | ||
379 | .Dq Li fe80::1%ne0 , | ||
380 | which means | ||
381 | .Do | ||
382 | .Li fe80::1 | ||
383 | on the link associated with the | ||
384 | .Li ne0 | ||
385 | interface | ||
386 | .Dc . | ||
387 | .Pp | ||
388 | The implementation is still very experimental and non-standard. | ||
389 | The current implementation assumes a one-to-one relationship between | ||
390 | the interface and link, which is not necessarily true from the specification. | ||
391 | .\" | 383 | .\" |
392 | .Sh EXAMPLES | 384 | .Sh EXAMPLES |
393 | The following code tries to connect to | 385 | The following code tries to connect to |
@@ -489,60 +481,8 @@ if (nsock == 0) { | |||
489 | freeaddrinfo(res0); | 481 | freeaddrinfo(res0); |
490 | .Ed | 482 | .Ed |
491 | .\" | 483 | .\" |
492 | .Sh DIAGNOSTICS | ||
493 | Error return status from | ||
494 | .Fn getaddrinfo | ||
495 | is zero on success and non-zero on errors. | ||
496 | Non-zero error codes are defined in | ||
497 | .Aq Pa netdb.h , | ||
498 | and as follows: | ||
499 | .Pp | ||
500 | .Bl -tag -width EAI_ADDRFAMILY -compact | ||
501 | .It Dv EAI_ADDRFAMILY | ||
502 | Address family for | ||
503 | .Fa nodename | ||
504 | not supported. | ||
505 | .It Dv EAI_AGAIN | ||
506 | Temporary failure in name resolution. | ||
507 | .It Dv EAI_BADFLAGS | ||
508 | Invalid value for | ||
509 | .Fa ai_flags . | ||
510 | .It Dv EAI_FAIL | ||
511 | Non-recoverable failure in name resolution. | ||
512 | .It Dv EAI_FAMILY | ||
513 | .Fa ai_family | ||
514 | not supported. | ||
515 | .It Dv EAI_MEMORY | ||
516 | Memory allocation failure. | ||
517 | .It Dv EAI_NODATA | ||
518 | No address associated with | ||
519 | .Fa nodename . | ||
520 | .It Dv EAI_NONAME | ||
521 | .Fa nodename | ||
522 | nor | ||
523 | .Fa servname | ||
524 | provided, or not known. | ||
525 | .It Dv EAI_SERVICE | ||
526 | .Fa servname | ||
527 | not supported for | ||
528 | .Fa ai_socktype . | ||
529 | .It Dv EAI_SOCKTYPE | ||
530 | .Fa ai_socktype | ||
531 | not supported. | ||
532 | .It Dv EAI_SYSTEM | ||
533 | System error returned in | ||
534 | .Va errno . | ||
535 | .El | ||
536 | .Pp | ||
537 | If called with proper argument, | ||
538 | .Fn gai_strerror | ||
539 | returns a pointer to a string describing the given error code. | ||
540 | If the argument is not one of the | ||
541 | .Dv EAI_xxx | ||
542 | values, the function still returns a pointer to a string whose contents | ||
543 | indicate an unknown error. | ||
544 | .\" | ||
545 | .Sh SEE ALSO | 484 | .Sh SEE ALSO |
485 | .Xr gai_strerror 3 , | ||
546 | .Xr gethostbyname 3 , | 486 | .Xr gethostbyname 3 , |
547 | .Xr getnameinfo 3 , | 487 | .Xr getnameinfo 3 , |
548 | .Xr getservbyname 3 , | 488 | .Xr getservbyname 3 , |
@@ -589,5 +529,3 @@ The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. | |||
589 | .\" | 529 | .\" |
590 | .Sh BUGS | 530 | .Sh BUGS |
591 | The current implementation is not thread-safe. | 531 | The current implementation is not thread-safe. |
592 | .Pp | ||
593 | The text was shamelessly copied from RFC 2553. | ||