summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjmc <>2004-12-06 10:46:35 +0000
committerjmc <>2004-12-06 10:46:35 +0000
commit66534e214cbc90c8e166a81ed98f302243b70cc6 (patch)
treeea86aaac3c406d60b42be5951c5e6cb337c5d9ed /src/lib
parentd215df80389dbae81d8b3a3e210e6a1be96479ca (diff)
downloadopenbsd-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.inc16
-rw-r--r--src/lib/libc/net/gai_strerror.3118
-rw-r--r--src/lib/libc/net/getaddrinfo.3264
-rw-r--r--src/lib/libc/net/getnameinfo.3105
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
31MAN+= byteorder.3 ethers.3 getaddrinfo.3 gethostbyname.3 getifaddrs.3 \ 31MAN+= 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
38MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ 38MLINKS+=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
45MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ 45MLINKS+=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
47MLINKS+= getaddrinfo.3 freeaddrinfo.3 getaddrinfo.3 gai_strerror.3 47MLINKS+=getaddrinfo.3 freeaddrinfo.3
48MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ 48MLINKS+=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
46To aid applications in printing error messages based on the
47.Dv EAI_xxx
48codes returned by
49.Xr getaddrinfo 3
50and
51.Xr getnameinfo 3 ,
52.Fn gai_strerror
53is defined.
54The argument is one of the
55.Dv EAI_xxx
56values detailed below
57and the return value points to a string describing the error.
58If the argument is not one of the
59.Dv EAI_xxx
60values,
61the function still returns a pointer to a string whose contents
62indicate an unknown error.
63.Pp
64The error return status from
65.Xr getaddrinfo 3
66and
67.Xr getnameinfo 3
68is zero on success and non-zero on errors.
69Non-zero error codes are defined in
70.Aq Pa netdb.h ,
71and are as follows:
72.Pp
73.Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact
74.It Dv EAI_ADDRFAMILY
75Address family for
76.Fa nodename
77not supported.
78.It Dv EAI_AGAIN
79Temporary failure in name resolution.
80.It Dv EAI_BADFLAGS
81Invalid value for
82.Fa ai_flags .
83.It Dv EAI_BADHINTS
84Invalid value for hints.
85.It Dv EAI_FAIL
86Non-recoverable failure in name resolution.
87.It Dv EAI_FAMILY
88.Fa ai_family
89not supported.
90.It Dv EAI_MEMORY
91Memory allocation failure.
92.It Dv EAI_NODATA
93No address associated with
94.Fa nodename .
95.It Dv EAI_NONAME
96.Fa nodename
97nor
98.Fa servname
99provided, or not known.
100.It Dv EAI_PROTOCOL
101Resolved protocol is unknown.
102.It Dv EAI_SERVICE
103.Fa servname
104not supported for
105.Fa ai_socktype .
106.It Dv EAI_SOCKTYPE
107.Fa ai_socktype
108not supported.
109.It Dv EAI_SYSTEM
110System error returned in
111.Va errno .
112.El
113.\"
114.Sh SEE ALSO
115.Xr getaddrinfo 3 ,
116.Xr getnameinfo 3
117.Sh HISTORY
118The 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
56The 53The
@@ -62,6 +59,67 @@ and
62.Xr getservbyname 3 , 59.Xr getservbyname 3 ,
63but in a more sophisticated manner. 60but in a more sophisticated manner.
64.Pp 61.Pp
62All of the information returned by
63.Fn getaddrinfo
64is dynamically allocated:
65the
66.Li addrinfo
67structures, the socket address structures, and canonical node name
68strings pointed to by the addrinfo structures.
69To return this information to the system the function
70.Fn freeaddrinfo
71is called.
72The
73.Fa addrinfo
74structure pointed to by the
75.Fa ai
76argument is freed,
77along with any dynamic storage pointed to by the structure.
78This operation is repeated until a
79.Dv NULL
80.Fa ai_next
81pointer is encountered.
82.Pp
83To aid applications in printing error messages based on the
84.Dv EAI_xxx
85codes returned by
86.Fn getaddrinfo ,
87.Fn gai_strerror
88is defined.
89See
90.Xr gai_strerror 3
91for more information.
92.Pp
93The implementation allows experimental numeric IPv6 address notation with
94scope identifier.
95By appending the percent character and scope identifier to addresses,
96you can fill the
97.Li sin6_scope_id
98field for addresses.
99This would make management of scoped address easier,
100and allows cut-and-paste input of scoped address.
101.Pp
102At this moment the code supports only link-local addresses with the format.
103Scope identifier is hardcoded to the name of the hardware interface associated
104with the link
105.Po
106such as
107.Li ne0
108.Pc .
109An example is
110.Dq Li fe80::1%ne0 ,
111which means
112.Do
113.Li fe80::1
114on the link associated with the
115.Li ne0
116interface
117.Dc .
118.Pp
119The IPv6 implementation is still very experimental and non-standard.
120The current implementation assumes a one-to-one relationship between
121the interface and link, which is not necessarily true from the specification.
122.Pp
65The 123The
66.Li addrinfo 124.Li addrinfo
67structure is defined as a result of including the 125structure is defined as a result of including the
@@ -168,7 +226,7 @@ structure the three members
168and 226and
169.Fa ai_protocol 227.Fa ai_protocol
170are the corresponding arguments for a call to the 228are the corresponding arguments for a call to the
171.Fn socket 229.Xr socket 2
172function. 230function.
173In each 231In each
174.Li addrinfo 232.Li addrinfo
@@ -179,15 +237,17 @@ specified by the
179.Fa ai_addrlen 237.Fa ai_addrlen
180member. 238member.
181.Pp 239.Pp
240The
241.Fa ai_flags
242argument can be set to any of the following values, OR'd together:
243.Bl -tag -width "AI_NUMERICHOSTXX"
244.It AI_PASSIVE
182If the 245If the
183.Dv AI_PASSIVE 246.Dv AI_PASSIVE
184bit is set in the 247bit is set,
185.Fa ai_flags 248the caller plans to use the returned socket address
186member of the
187.Fa hints
188structure, then the caller plans to use the returned socket address
189structure in a call to 249structure in a call to
190.Fn bind . 250.Xr bind 2 .
191In this case, if the 251In this case, if the
192.Fa nodename 252.Fa nodename
193argument is a null pointer, then the IP address portion of the socket 253argument is a null pointer, then the IP address portion of the socket
@@ -199,73 +259,64 @@ for an IPv6 address.
199.Pp 259.Pp
200If the 260If the
201.Dv AI_PASSIVE 261.Dv AI_PASSIVE
202bit is not set in the 262bit is not set,
203.Fa ai_flags 263the returned socket address structure will be ready for a
204member of the
205.Fa hints
206structure, then the returned socket address structure will be ready for a
207call to 264call to
208.Fn connect 265.Xr connect 2
209.Pq for a connection-oriented protocol 266.Pq for a connection-oriented protocol
210or either 267or either
211.Fn connect , 268.Xr connect 2 ,
212.Fn sendto , 269.Xr sendto 2 ,
213or 270or
214.Fn sendmsg 271.Xr sendmsg 2
215.Pq for a connectionless protocol . 272.Pq for a connectionless protocol .
216In this case, if the 273In this case, if the
217.Fa nodename 274.Fa nodename
218argument is a null pointer, then the IP address portion of the 275argument is a null pointer, then the IP address portion of the
219socket address structure will be set to the loopback address. 276socket address structure will be set to the loopback address.
220.Pp 277.It AI_CANONNAME
221If the 278If the
222.Dv AI_CANONNAME 279.Dv AI_CANONNAME
223bit is set in the 280bit is set,
224.Fa ai_flags 281then upon successful return the
225member of the
226.Fa hints
227structure, then upon successful return the
228.Fa ai_canonname 282.Fa ai_canonname
229member of the first 283member of the first
230.Li addrinfo 284.Li addrinfo
231structure in the linked list will point to a NUL-terminated string 285structure in the linked list will point to a NUL-terminated string
232containing the canonical name of the specified 286containing the canonical name of the specified
233.Fa nodename . 287.Fa nodename .
234.Pp 288.It AI_NUMERICHOST
235If the 289If the
236.Dv AI_NUMERICHOST 290.Dv AI_NUMERICHOST
237bit is set in the 291bit is set,
238.Fa ai_flags 292then a non-null
239member of the
240.Fa hints
241structure, then a non-null
242.Fa nodename 293.Fa nodename
243string must be a numeric host address string. 294string must be a numeric host address string.
244Otherwise an error of 295Otherwise an error of
245.Dv EAI_NONAME 296.Dv EAI_NONAME
246is returned. 297is returned.
247This flag prevents any type of name resolution service (e.g., the DNS) 298This flag prevents any type of name resolution service,
299such as DNS,
248from being called. 300from being called.
249.Pp 301.It AI_NUMERICSERV
250If the 302If the
251.Dv AI_NUMERICSERV 303.Dv AI_NUMERICSERV
252bit is set in the 304bit is set,
253.Fa ai_flags 305then a non-null
254member of the
255.Fa hints
256structure, then a non-null
257.Fa servname 306.Fa servname
258string must be a numeric port string. 307string must be a numeric port string.
259Otherwise an error of 308Otherwise an error of
260.Dv EAI_NONAME 309.Dv EAI_NONAME
261is returned. 310is returned.
262This flag prevents any type of name resolution service (e.g., the NIS) 311This flag prevents any type of name resolution service,
312such as NIS,
263from being called. 313from being called.
314.El
264.Pp 315.Pp
265The arguments to 316The arguments to
266.Fn getaddrinfo 317.Fn getaddrinfo
267must sufficiently be consistent and unambiguous. 318must be sufficiently consistent and unambiguous.
268Here are pitfall cases you may encounter: 319Issues 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
323is not allowed to glob the argument in such case. 374is not allowed to glob the argument in such case.
324.El 375.El
325.Pp
326All of the information returned by
327.Fn getaddrinfo
328is dynamically allocated:
329the
330.Li addrinfo
331structures, the socket address structures, and canonical node name
332strings pointed to by the addrinfo structures.
333To return this information to the system the function
334.Fn freeaddrinfo
335is called.
336The
337.Fa addrinfo
338structure pointed to by the
339.Fa ai argument
340is freed, along with any dynamic storage pointed to by the structure.
341This operation is repeated until a
342.Dv NULL
343.Fa ai_next
344pointer is encountered.
345.Pp
346To aid applications in printing error messages based on the
347.Dv EAI_xxx
348codes returned by
349.Fn getaddrinfo ,
350.Fn gai_strerror
351is defined.
352The argument is one of the
353.Dv EAI_xxx
354values defined earlier and the return value points to a string describing
355the error.
356If the argument is not one of the
357.Dv EAI_xxx
358values, the function still returns a pointer to a string whose contents
359indicate an unknown error.
360.\" 376.\"
361.Ss Extension for scoped IPv6 address 377.Sh RETURN VALUES
362The implementation allows experimental numeric IPv6 address notation with 378.Fn getaddrinfo
363scope identifier. 379returns zero on success, and non-zero on errors.
364By appending the percent character and scope identifier to addresses, 380See
365you can fill the 381.Xr gai_strerror 3
366.Li sin6_scope_id 382for a description of the non-zero error codes.
367field for addresses.
368This would make management of scoped address easier,
369and allows cut-and-paste input of scoped address.
370.Pp
371At this moment the code supports only link-local addresses with the format.
372Scope identifier is hardcoded to the name of the hardware interface associated
373with the link.
374.Po
375such as
376.Li ne0
377.Pc .
378An example is
379.Dq Li fe80::1%ne0 ,
380which means
381.Do
382.Li fe80::1
383on the link associated with the
384.Li ne0
385interface
386.Dc .
387.Pp
388The implementation is still very experimental and non-standard.
389The current implementation assumes a one-to-one relationship between
390the interface and link, which is not necessarily true from the specification.
391.\" 383.\"
392.Sh EXAMPLES 384.Sh EXAMPLES
393The following code tries to connect to 385The following code tries to connect to
@@ -489,60 +481,8 @@ if (nsock == 0) {
489freeaddrinfo(res0); 481freeaddrinfo(res0);
490.Ed 482.Ed
491.\" 483.\"
492.Sh DIAGNOSTICS
493Error return status from
494.Fn getaddrinfo
495is zero on success and non-zero on errors.
496Non-zero error codes are defined in
497.Aq Pa netdb.h ,
498and as follows:
499.Pp
500.Bl -tag -width EAI_ADDRFAMILY -compact
501.It Dv EAI_ADDRFAMILY
502Address family for
503.Fa nodename
504not supported.
505.It Dv EAI_AGAIN
506Temporary failure in name resolution.
507.It Dv EAI_BADFLAGS
508Invalid value for
509.Fa ai_flags .
510.It Dv EAI_FAIL
511Non-recoverable failure in name resolution.
512.It Dv EAI_FAMILY
513.Fa ai_family
514not supported.
515.It Dv EAI_MEMORY
516Memory allocation failure.
517.It Dv EAI_NODATA
518No address associated with
519.Fa nodename .
520.It Dv EAI_NONAME
521.Fa nodename
522nor
523.Fa servname
524provided, or not known.
525.It Dv EAI_SERVICE
526.Fa servname
527not supported for
528.Fa ai_socktype .
529.It Dv EAI_SOCKTYPE
530.Fa ai_socktype
531not supported.
532.It Dv EAI_SYSTEM
533System error returned in
534.Va errno .
535.El
536.Pp
537If called with proper argument,
538.Fn gai_strerror
539returns a pointer to a string describing the given error code.
540If the argument is not one of the
541.Dv EAI_xxx
542values, the function still returns a pointer to a string whose contents
543indicate 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
591The current implementation is not thread-safe. 531The current implementation is not thread-safe.
592.Pp
593The 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.
64The function indicates successful completion by a zero return value; 64The function indicates successful completion by a zero return value;
65a non-zero return value indicates failure. 65a non-zero return value indicates failure.
66.Pp 66.Pp
67To aid applications in printing error messages based on the
68.Dv EAI_xxx
69codes returned by
70.Fn getnameinfo ,
71.Fn gai_strerror
72is defined.
73See
74.Xr gai_strerror 3
75for more information.
76.Pp
77The implementation allows experimental numeric IPv6 address notation with
78scope identifier.
79IPv6 link-local address will appear as a string like
80.Dq Li fe80::1%ne0 .
81Refer to
82.Xr getaddrinfo 3
83for the notation.
84.Pp
67The first argument, 85The first argument,
68.Fa sa , 86.Fa sa ,
69points to either a 87points to either a
@@ -106,7 +124,7 @@ maximum size of either a fully-qualified domain name or a service name.
106Therefore to aid the application in allocating buffers for these two 124Therefore to aid the application in allocating buffers for these two
107returned strings the following constants are defined in 125returned 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.
122The final argument is a 140The final argument is a
123.Fa flag 141.Fa flag
124that changes the default actions of this function. 142that changes the default actions of this function.
143The flags are defined in
144.Aq Pa netdb.h
145and are as follows:
146.Bl -tag -width "NI_NUMERICHOSTXX"
147.It Dv NI_NOFQDN
125By default the fully-qualified domain name (FQDN) for the host is 148By default the fully-qualified domain name (FQDN) for the host is
126looked up in the DNS and returned. 149looked up using DNS and returned.
127If the flag bit 150If the flag bit
128.Dv NI_NOFQDN 151.Dv NI_NOFQDN
129is set, only the nodename portion of the FQDN is returned for local hosts. 152is set, only the nodename portion of the FQDN is returned for local hosts.
130.Pp 153.It Dv NI_NUMERICHOST
131If the 154If the
132.Fa flag 155.Fa flag
133bit 156bit
134.Dv NI_NUMERICHOST 157.Dv NI_NUMERICHOST
135is set, or if the host's name cannot be located in the DNS, 158is set, or if the host's name cannot be located using DNS,
136the numeric form of the host's address is returned instead of its name 159the numeric form of the host's address is returned instead of its name
137.Po 160.Po
138e.g., by calling 161e.g., by calling
139.Fn inet_ntop 162.Xr inet_ntop 3
140instead of 163instead of
141.Fn gethostbyaddr 164.Xr gethostbyaddr 3
142.Pc . 165.Pc .
166The two
167.Dv NI_NUMERICxxx
168flags are required to support the
169.Fl n
170flag that many commands provide.
171.It Dv NI_NAMEREQD
143If the 172If the
144.Fa flag 173.Fa flag
145bit 174bit
146.Dv NI_NAMEREQD 175.Dv NI_NAMEREQD
147is set, an error is returned if the host's name cannot be located in the DNS. 176is set, an error is returned if the host's name cannot be located using DNS.
148.Pp 177.It Dv NI_NUMERICSERV
149If the flag bit 178If the flag bit
150.Dv NI_NUMERICSERV 179.Dv NI_NUMERICSERV
151is set, the numeric form of the service address is returned 180is set, the numeric form of the service address is returned
@@ -156,35 +185,29 @@ The two
156flags are required to support the 185flags are required to support the
157.Fl n 186.Fl n
158flag that many commands provide. 187flag that many commands provide.
159.Pp 188.It Dv NI_DGRAM
160A fifth flag bit, 189A fifth flag bit,
161.Dv NI_DGRAM , 190.Dv NI_DGRAM ,
162specifies that the service is a datagram service, and causes 191specifies that the service is a datagram service, and causes
163.Fn getservbyport 192.Xr getservbyport 3
164to be called with a second argument of 193to be called with a second argument of
165.Qq udp 194.Qq udp
166instead of its default of 195instead of its default of
167.Qq tcp . 196.Qq tcp .
168This is required for the few ports (512-514) 197This is required for the few ports (512-514)
169that have different services for UDP and TCP. 198that have different services for UDP and TCP.
170.Pp 199.El
171These
172.Dv NI_xxx
173flags are defined in
174.Aq Pa netdb.h .
175.\" 200.\"
176.Ss Extension for scoped IPv6 address 201.Sh RETURN VALUES
177The implementation allows experimental numeric IPv6 address notation with 202.Fn getnameinfo
178scope identifier. 203returns zero on success, and non-zero on errors.
179IPv6 link-local address will appear as a string like 204See
180.Dq Li fe80::1%ne0 . 205.Xr gai_strerror 3
181Refer to 206for a description of the non-zero error codes.
182.Xr getaddrinfo 3
183for the notation.
184.\" 207.\"
185.Sh EXAMPLES 208.Sh EXAMPLES
186The following code tries to get a numeric hostname, and service name, 209The following code tries to get a numeric hostname, and service name,
187for given socket address. 210for a given socket address.
188Observe that there is no hardcoded reference to a particular address family. 211Observe that there is no hardcoded reference to a particular address family.
189.Bd -literal -offset indent 212.Bd -literal -offset indent
190struct sockaddr *sa; /* input */ 213struct sockaddr *sa; /* input */
@@ -198,7 +221,7 @@ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
198printf("host=%s, serv=%s\en", hbuf, sbuf); 221printf("host=%s, serv=%s\en", hbuf, sbuf);
199.Ed 222.Ed
200.Pp 223.Pp
201The following version checks if the socket address has reverse address mapping. 224The following version checks if the socket address has reverse address mapping:
202.Bd -literal -offset indent 225.Bd -literal -offset indent
203struct sockaddr *sa; /* input */ 226struct sockaddr *sa; /* input */
204char hbuf[NI_MAXHOST]; 227char hbuf[NI_MAXHOST];
@@ -211,34 +234,8 @@ if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0,
211printf("host=%s\en", hbuf); 234printf("host=%s\en", hbuf);
212.Ed 235.Ed
213.\" 236.\"
214.Sh DIAGNOSTICS
215The function indicates successful completion by a zero return value;
216a non-zero return value indicates failure.
217Error codes are as below:
218.Bl -tag -width Er
219.It Dv EAI_AGAIN
220The name could not be resolved at this time.
221Future attempts may succeed.
222.It Dv EAI_BADFLAGS
223The flags had an invalid value.
224.It Dv EAI_FAIL
225A non-recoverable error occurred.
226.It Dv EAI_FAMILY
227The address family was not recognized or the address length was invalid
228for the specified family.
229.It Dv EAI_MEMORY
230There was a memory allocation failure.
231.It Dv EAI_NONAME
232The name does not resolve for the supplied parameters.
233.Dv NI_NAMEREQD
234is set and the host's name cannot be located,
235or both nodename and servname were null.
236.It Dv EAI_SYSTEM
237A system error occurred.
238The 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
341The current implementation is not thread-safe. 338The current implementation is not thread-safe.
342.Pp 339.Pp
343The text was shamelessly copied from RFC 2553.
344.Pp
345.Ox 340.Ox
346intentionally uses a different 341intentionally uses a different
347.Dv NI_MAXHOST 342.Dv NI_MAXHOST