diff options
author | jmc <> | 2004-12-06 10:46:35 +0000 |
---|---|---|
committer | jmc <> | 2004-12-06 10:46:35 +0000 |
commit | 66534e214cbc90c8e166a81ed98f302243b70cc6 (patch) | |
tree | ea86aaac3c406d60b42be5951c5e6cb337c5d9ed /src/lib | |
parent | d215df80389dbae81d8b3a3e210e6a1be96479ca (diff) | |
download | openbsd-66534e214cbc90c8e166a81ed98f302243b70cc6.tar.gz openbsd-66534e214cbc90c8e166a81ed98f302243b70cc6.tar.bz2 openbsd-66534e214cbc90c8e166a81ed98f302243b70cc6.zip |
move gai_strerror into its own page, and make the get* pages more readable;
prompted by henning;
ok henning@ itojun@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/Makefile.inc | 16 | ||||
-rw-r--r-- | src/lib/libc/net/gai_strerror.3 | 118 | ||||
-rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 264 | ||||
-rw-r--r-- | src/lib/libc/net/getnameinfo.3 | 105 |
4 files changed, 277 insertions, 226 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index 8b34f57926..79bfbb6b91 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.34 2004/10/26 17:20:36 espie Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.35 2004/12/06 10:46:35 jmc Exp $ |
2 | 2 | ||
3 | # net sources | 3 | # net sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net |
@@ -28,12 +28,12 @@ SRCS+= ip6opt.c rthdr.c vars6.c | |||
28 | 28 | ||
29 | .include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" | 29 | .include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" |
30 | 30 | ||
31 | MAN+= byteorder.3 ethers.3 getaddrinfo.3 gethostbyname.3 getifaddrs.3 \ | 31 | MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ |
32 | getnameinfo.3 getnetent.3 getprotoent.3 getservent.3 inet.3 \ | 32 | getifaddrs.3 getnameinfo.3 getnetent.3 getprotoent.3 \ |
33 | if_indextoname.3 inet_net.3 link_addr.3 ns.3 ipx.3 \ | 33 | getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ |
34 | rcmd.3 rcmdsh.3 resolver.3 net_addrcmp.3 \ | 34 | inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ |
35 | inet6_option_space.3 inet6_rthdr_space.3 \ | 35 | ipx.3 link_addr.3 net_addrcmp.3 ns.3 \ |
36 | getrrsetbyname.3 | 36 | rcmd.3 rcmdsh.3 resolver.3 |
37 | 37 | ||
38 | MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ | 38 | MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ |
39 | byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ | 39 | byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ |
@@ -44,7 +44,7 @@ MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ | |||
44 | byteorder.3 swap64.3 | 44 | byteorder.3 swap64.3 |
45 | MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ | 45 | MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ |
46 | ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 ethers.3 ether_addr.3 | 46 | ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 ethers.3 ether_addr.3 |
47 | MLINKS+= getaddrinfo.3 freeaddrinfo.3 getaddrinfo.3 gai_strerror.3 | 47 | MLINKS+=getaddrinfo.3 freeaddrinfo.3 |
48 | MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ | 48 | MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ |
49 | gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ | 49 | gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ |
50 | gethostbyname.3 herror.3 gethostbyname.3 gethostbyname2.3 \ | 50 | gethostbyname.3 herror.3 gethostbyname.3 gethostbyname2.3 \ |
diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 new file mode 100644 index 0000000000..75eb1517f4 --- /dev/null +++ b/src/lib/libc/net/gai_strerror.3 | |||
@@ -0,0 +1,118 @@ | |||
1 | .\" $OpenBSD: gai_strerror.3,v 1.1 2004/12/06 10:46:35 jmc Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1983, 1987, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. Neither the name of the University nor the names of its contributors | ||
15 | .\" may be used to endorse or promote products derived from this software | ||
16 | .\" without specific prior written permission. | ||
17 | .\" | ||
18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
28 | .\" SUCH DAMAGE. | ||
29 | .\" | ||
30 | .Dd December 3, 2004 | ||
31 | .Dt GAI_STRERROR 3 | ||
32 | .Os | ||
33 | .\" | ||
34 | .Sh NAME | ||
35 | .Nm gai_strerror | ||
36 | .Nd return EAI_xxx error message | ||
37 | .\" | ||
38 | .Sh SYNOPSIS | ||
39 | .Fd #include <sys/types.h> | ||
40 | .Fd #include <sys/socket.h> | ||
41 | .Fd #include <netdb.h> | ||
42 | .Ft "char *" | ||
43 | .Fn gai_strerror "int ecode" | ||
44 | .\" | ||
45 | .Sh DESCRIPTION | ||
46 | To aid applications in printing error messages based on the | ||
47 | .Dv EAI_xxx | ||
48 | codes returned by | ||
49 | .Xr getaddrinfo 3 | ||
50 | and | ||
51 | .Xr getnameinfo 3 , | ||
52 | .Fn gai_strerror | ||
53 | is defined. | ||
54 | The argument is one of the | ||
55 | .Dv EAI_xxx | ||
56 | values detailed below | ||
57 | and the return value points to a string describing the error. | ||
58 | If the argument is not one of the | ||
59 | .Dv EAI_xxx | ||
60 | values, | ||
61 | the function still returns a pointer to a string whose contents | ||
62 | indicate an unknown error. | ||
63 | .Pp | ||
64 | The error return status from | ||
65 | .Xr getaddrinfo 3 | ||
66 | and | ||
67 | .Xr getnameinfo 3 | ||
68 | is zero on success and non-zero on errors. | ||
69 | Non-zero error codes are defined in | ||
70 | .Aq Pa netdb.h , | ||
71 | and are as follows: | ||
72 | .Pp | ||
73 | .Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact | ||
74 | .It Dv EAI_ADDRFAMILY | ||
75 | Address family for | ||
76 | .Fa nodename | ||
77 | not supported. | ||
78 | .It Dv EAI_AGAIN | ||
79 | Temporary failure in name resolution. | ||
80 | .It Dv EAI_BADFLAGS | ||
81 | Invalid value for | ||
82 | .Fa ai_flags . | ||
83 | .It Dv EAI_BADHINTS | ||
84 | Invalid value for hints. | ||
85 | .It Dv EAI_FAIL | ||
86 | Non-recoverable failure in name resolution. | ||
87 | .It Dv EAI_FAMILY | ||
88 | .Fa ai_family | ||
89 | not supported. | ||
90 | .It Dv EAI_MEMORY | ||
91 | Memory allocation failure. | ||
92 | .It Dv EAI_NODATA | ||
93 | No address associated with | ||
94 | .Fa nodename . | ||
95 | .It Dv EAI_NONAME | ||
96 | .Fa nodename | ||
97 | nor | ||
98 | .Fa servname | ||
99 | provided, or not known. | ||
100 | .It Dv EAI_PROTOCOL | ||
101 | Resolved protocol is unknown. | ||
102 | .It Dv EAI_SERVICE | ||
103 | .Fa servname | ||
104 | not supported for | ||
105 | .Fa ai_socktype . | ||
106 | .It Dv EAI_SOCKTYPE | ||
107 | .Fa ai_socktype | ||
108 | not supported. | ||
109 | .It Dv EAI_SYSTEM | ||
110 | System error returned in | ||
111 | .Va errno . | ||
112 | .El | ||
113 | .\" | ||
114 | .Sh SEE ALSO | ||
115 | .Xr getaddrinfo 3 , | ||
116 | .Xr getnameinfo 3 | ||
117 | .Sh HISTORY | ||
118 | The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit. | ||
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. | ||
diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 index 3b3a0fd290..c01646c8a7 100644 --- a/src/lib/libc/net/getnameinfo.3 +++ b/src/lib/libc/net/getnameinfo.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getnameinfo.3,v 1.27 2003/08/28 10:16:38 jmc Exp $ | 1 | .\" $OpenBSD: getnameinfo.3,v 1.28 2004/12/06 10:46:35 jmc Exp $ |
2 | .\" $KAME: getnameinfo.3,v 1.20 2001/01/05 13:37:37 itojun Exp $ | 2 | .\" $KAME: getnameinfo.3,v 1.20 2001/01/05 13:37:37 itojun Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 4 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
@@ -64,6 +64,24 @@ strings for both in buffers provided by the caller. | |||
64 | The function indicates successful completion by a zero return value; | 64 | The function indicates successful completion by a zero return value; |
65 | a non-zero return value indicates failure. | 65 | a non-zero return value indicates failure. |
66 | .Pp | 66 | .Pp |
67 | To aid applications in printing error messages based on the | ||
68 | .Dv EAI_xxx | ||
69 | codes returned by | ||
70 | .Fn getnameinfo , | ||
71 | .Fn gai_strerror | ||
72 | is defined. | ||
73 | See | ||
74 | .Xr gai_strerror 3 | ||
75 | for more information. | ||
76 | .Pp | ||
77 | The implementation allows experimental numeric IPv6 address notation with | ||
78 | scope identifier. | ||
79 | IPv6 link-local address will appear as a string like | ||
80 | .Dq Li fe80::1%ne0 . | ||
81 | Refer to | ||
82 | .Xr getaddrinfo 3 | ||
83 | for the notation. | ||
84 | .Pp | ||
67 | The first argument, | 85 | The first argument, |
68 | .Fa sa , | 86 | .Fa sa , |
69 | points to either a | 87 | points to either a |
@@ -106,7 +124,7 @@ maximum size of either a fully-qualified domain name or a service name. | |||
106 | Therefore to aid the application in allocating buffers for these two | 124 | Therefore to aid the application in allocating buffers for these two |
107 | returned strings the following constants are defined in | 125 | returned strings the following constants are defined in |
108 | .Aq Pa netdb.h : | 126 | .Aq Pa netdb.h : |
109 | .Bd -literal -offset | 127 | .Bd -literal -offset indent |
110 | #define NI_MAXHOST MAXHOSTNAMELEN | 128 | #define NI_MAXHOST MAXHOSTNAMELEN |
111 | #define NI_MAXSERV 32 | 129 | #define NI_MAXSERV 32 |
112 | .Ed | 130 | .Ed |
@@ -122,30 +140,41 @@ Assigned Numbers RFC. | |||
122 | The final argument is a | 140 | The final argument is a |
123 | .Fa flag | 141 | .Fa flag |
124 | that changes the default actions of this function. | 142 | that changes the default actions of this function. |
143 | The flags are defined in | ||
144 | .Aq Pa netdb.h | ||
145 | and are as follows: | ||
146 | .Bl -tag -width "NI_NUMERICHOSTXX" | ||
147 | .It Dv NI_NOFQDN | ||
125 | By default the fully-qualified domain name (FQDN) for the host is | 148 | By default the fully-qualified domain name (FQDN) for the host is |
126 | looked up in the DNS and returned. | 149 | looked up using DNS and returned. |
127 | If the flag bit | 150 | If the flag bit |
128 | .Dv NI_NOFQDN | 151 | .Dv NI_NOFQDN |
129 | is set, only the nodename portion of the FQDN is returned for local hosts. | 152 | is set, only the nodename portion of the FQDN is returned for local hosts. |
130 | .Pp | 153 | .It Dv NI_NUMERICHOST |
131 | If the | 154 | If the |
132 | .Fa flag | 155 | .Fa flag |
133 | bit | 156 | bit |
134 | .Dv NI_NUMERICHOST | 157 | .Dv NI_NUMERICHOST |
135 | is set, or if the host's name cannot be located in the DNS, | 158 | is set, or if the host's name cannot be located using DNS, |
136 | the numeric form of the host's address is returned instead of its name | 159 | the numeric form of the host's address is returned instead of its name |
137 | .Po | 160 | .Po |
138 | e.g., by calling | 161 | e.g., by calling |
139 | .Fn inet_ntop | 162 | .Xr inet_ntop 3 |
140 | instead of | 163 | instead of |
141 | .Fn gethostbyaddr | 164 | .Xr gethostbyaddr 3 |
142 | .Pc . | 165 | .Pc . |
166 | The two | ||
167 | .Dv NI_NUMERICxxx | ||
168 | flags are required to support the | ||
169 | .Fl n | ||
170 | flag that many commands provide. | ||
171 | .It Dv NI_NAMEREQD | ||
143 | If the | 172 | If the |
144 | .Fa flag | 173 | .Fa flag |
145 | bit | 174 | bit |
146 | .Dv NI_NAMEREQD | 175 | .Dv NI_NAMEREQD |
147 | is set, an error is returned if the host's name cannot be located in the DNS. | 176 | is set, an error is returned if the host's name cannot be located using DNS. |
148 | .Pp | 177 | .It Dv NI_NUMERICSERV |
149 | If the flag bit | 178 | If the flag bit |
150 | .Dv NI_NUMERICSERV | 179 | .Dv NI_NUMERICSERV |
151 | is set, the numeric form of the service address is returned | 180 | is set, the numeric form of the service address is returned |
@@ -156,35 +185,29 @@ The two | |||
156 | flags are required to support the | 185 | flags are required to support the |
157 | .Fl n | 186 | .Fl n |
158 | flag that many commands provide. | 187 | flag that many commands provide. |
159 | .Pp | 188 | .It Dv NI_DGRAM |
160 | A fifth flag bit, | 189 | A fifth flag bit, |
161 | .Dv NI_DGRAM , | 190 | .Dv NI_DGRAM , |
162 | specifies that the service is a datagram service, and causes | 191 | specifies that the service is a datagram service, and causes |
163 | .Fn getservbyport | 192 | .Xr getservbyport 3 |
164 | to be called with a second argument of | 193 | to be called with a second argument of |
165 | .Qq udp | 194 | .Qq udp |
166 | instead of its default of | 195 | instead of its default of |
167 | .Qq tcp . | 196 | .Qq tcp . |
168 | This is required for the few ports (512-514) | 197 | This is required for the few ports (512-514) |
169 | that have different services for UDP and TCP. | 198 | that have different services for UDP and TCP. |
170 | .Pp | 199 | .El |
171 | These | ||
172 | .Dv NI_xxx | ||
173 | flags are defined in | ||
174 | .Aq Pa netdb.h . | ||
175 | .\" | 200 | .\" |
176 | .Ss Extension for scoped IPv6 address | 201 | .Sh RETURN VALUES |
177 | The implementation allows experimental numeric IPv6 address notation with | 202 | .Fn getnameinfo |
178 | scope identifier. | 203 | returns zero on success, and non-zero on errors. |
179 | IPv6 link-local address will appear as a string like | 204 | See |
180 | .Dq Li fe80::1%ne0 . | 205 | .Xr gai_strerror 3 |
181 | Refer to | 206 | for a description of the non-zero error codes. |
182 | .Xr getaddrinfo 3 | ||
183 | for the notation. | ||
184 | .\" | 207 | .\" |
185 | .Sh EXAMPLES | 208 | .Sh EXAMPLES |
186 | The following code tries to get a numeric hostname, and service name, | 209 | The following code tries to get a numeric hostname, and service name, |
187 | for given socket address. | 210 | for a given socket address. |
188 | Observe that there is no hardcoded reference to a particular address family. | 211 | Observe that there is no hardcoded reference to a particular address family. |
189 | .Bd -literal -offset indent | 212 | .Bd -literal -offset indent |
190 | struct sockaddr *sa; /* input */ | 213 | struct sockaddr *sa; /* input */ |
@@ -198,7 +221,7 @@ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, | |||
198 | printf("host=%s, serv=%s\en", hbuf, sbuf); | 221 | printf("host=%s, serv=%s\en", hbuf, sbuf); |
199 | .Ed | 222 | .Ed |
200 | .Pp | 223 | .Pp |
201 | The following version checks if the socket address has reverse address mapping. | 224 | The following version checks if the socket address has reverse address mapping: |
202 | .Bd -literal -offset indent | 225 | .Bd -literal -offset indent |
203 | struct sockaddr *sa; /* input */ | 226 | struct sockaddr *sa; /* input */ |
204 | char hbuf[NI_MAXHOST]; | 227 | char hbuf[NI_MAXHOST]; |
@@ -211,34 +234,8 @@ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, | |||
211 | printf("host=%s\en", hbuf); | 234 | printf("host=%s\en", hbuf); |
212 | .Ed | 235 | .Ed |
213 | .\" | 236 | .\" |
214 | .Sh DIAGNOSTICS | ||
215 | The function indicates successful completion by a zero return value; | ||
216 | a non-zero return value indicates failure. | ||
217 | Error codes are as below: | ||
218 | .Bl -tag -width Er | ||
219 | .It Dv EAI_AGAIN | ||
220 | The name could not be resolved at this time. | ||
221 | Future attempts may succeed. | ||
222 | .It Dv EAI_BADFLAGS | ||
223 | The flags had an invalid value. | ||
224 | .It Dv EAI_FAIL | ||
225 | A non-recoverable error occurred. | ||
226 | .It Dv EAI_FAMILY | ||
227 | The address family was not recognized or the address length was invalid | ||
228 | for the specified family. | ||
229 | .It Dv EAI_MEMORY | ||
230 | There was a memory allocation failure. | ||
231 | .It Dv EAI_NONAME | ||
232 | The name does not resolve for the supplied parameters. | ||
233 | .Dv NI_NAMEREQD | ||
234 | is set and the host's name cannot be located, | ||
235 | or both nodename and servname were null. | ||
236 | .It Dv EAI_SYSTEM | ||
237 | A system error occurred. | ||
238 | The error code can be found in errno. | ||
239 | .El | ||
240 | .\" | ||
241 | .Sh SEE ALSO | 237 | .Sh SEE ALSO |
238 | .Xr gai_strerror 3 , | ||
242 | .Xr getaddrinfo 3 , | 239 | .Xr getaddrinfo 3 , |
243 | .Xr gethostbyaddr 3 , | 240 | .Xr gethostbyaddr 3 , |
244 | .Xr getservbyport 3 , | 241 | .Xr getservbyport 3 , |
@@ -340,8 +337,6 @@ if (error == 0) { | |||
340 | .Sh BUGS | 337 | .Sh BUGS |
341 | The current implementation is not thread-safe. | 338 | The current implementation is not thread-safe. |
342 | .Pp | 339 | .Pp |
343 | The text was shamelessly copied from RFC 2553. | ||
344 | .Pp | ||
345 | .Ox | 340 | .Ox |
346 | intentionally uses a different | 341 | intentionally uses a different |
347 | .Dv NI_MAXHOST | 342 | .Dv NI_MAXHOST |