summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getnameinfo.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getnameinfo.3')
-rw-r--r--src/lib/libc/net/getnameinfo.3105
1 files changed, 50 insertions, 55 deletions
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