diff options
Diffstat (limited to 'src/lib/libc/net/getnameinfo.3')
-rw-r--r-- | src/lib/libc/net/getnameinfo.3 | 105 |
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. | |||
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 |