diff options
author | millert <> | 2004-12-20 21:13:00 +0000 |
---|---|---|
committer | millert <> | 2004-12-20 21:13:00 +0000 |
commit | 8d1da2e74a2ad861ec64a6439e30200a09d5db48 (patch) | |
tree | dcc3701cb2baeaf295852861f218fa322aed3f00 /src/lib | |
parent | e415ebc824a0a2e9b3a0b9aee96454fe90ffaf40 (diff) | |
download | openbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.tar.gz openbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.tar.bz2 openbsd-8d1da2e74a2ad861ec64a6439e30200a09d5db48.zip |
New getaddrinfo.3 man page, derived from the ISC version and fleshed
out a bit by me. Needs more work.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 new file mode 100644 index 0000000000..2209100c8b --- /dev/null +++ b/src/lib/libc/net/getaddrinfo.3 | |||
@@ -0,0 +1,300 @@ | |||
1 | .\" $OpenBSD: getaddrinfo.3,v 1.31 2004/12/20 21:13:00 millert Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | ||
4 | .\" Copyright (C) 2000, 2001 Internet Software Consortium. | ||
5 | .\" | ||
6 | .\" Permission to use, copy, modify, and distribute this software for any | ||
7 | .\" purpose with or without fee is hereby granted, provided that the above | ||
8 | .\" copyright notice and this permission notice appear in all copies. | ||
9 | .\" | ||
10 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | ||
11 | .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
12 | .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
13 | .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
14 | .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | ||
15 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
16 | .\" PERFORMANCE OF THIS SOFTWARE. | ||
17 | .\" | ||
18 | .Dd December 20, 2004 | ||
19 | .Dt GETADDRINFO 3 | ||
20 | .Os | ||
21 | .Sh NAME | ||
22 | .Nm getaddrinfo , | ||
23 | .Nm freeaddrinfo | ||
24 | .Nd socket address structure to host and service name | ||
25 | .Sh SYNOPSIS | ||
26 | .Fd #include <sys/types.h> | ||
27 | .Fd #include <sys/socket.h> | ||
28 | .Fd #include <netdb.h> | ||
29 | .Ft int | ||
30 | .Fn getaddrinfo "const char *hostname" "const char *servname" "const struct addrinfo *hints" "struct addrinfo **res" | ||
31 | .Ft void | ||
32 | .Fn freeaddrinfo "struct addrinfo *ai" | ||
33 | .Sh DESCRIPTION | ||
34 | .Fn getaddrinfo | ||
35 | is used to get a list of | ||
36 | .Dv IP | ||
37 | addresses and port numbers for host | ||
38 | .Fa hostname | ||
39 | and service | ||
40 | .Fa servname . | ||
41 | It is a replacement for and provides more flexibility than the | ||
42 | .Xr gethostbyname 3 | ||
43 | and | ||
44 | .Xr getservbyname 3 | ||
45 | functions. | ||
46 | .Pp | ||
47 | .Fa hostname | ||
48 | and | ||
49 | .Fa servname | ||
50 | are either pointers to NUL-terminated strings or the null pointer. | ||
51 | An acceptable value for | ||
52 | .Fa hostname | ||
53 | is either a host name or a numeric host address string consisting | ||
54 | of a dotted decimal IPv4 address or an IPv6 address. | ||
55 | The | ||
56 | .Fa servname | ||
57 | is either a decimal port number or a service name listed in | ||
58 | .Xr services 5 . | ||
59 | At least one of | ||
60 | .Fa hostname | ||
61 | and | ||
62 | .Fa servname | ||
63 | must be non-null. | ||
64 | .Pp | ||
65 | .Fa hints | ||
66 | is an optional pointer to a | ||
67 | .Li struct addrinfo , | ||
68 | as defined by | ||
69 | .Aq Pa netdb.h : | ||
70 | .Bd -literal | ||
71 | struct addrinfo { | ||
72 | int ai_flags; /* input flags */ | ||
73 | int ai_family; /* protocol family for socket */ | ||
74 | int ai_socktype; /* socket type */ | ||
75 | int ai_protocol; /* protocol for socket */ | ||
76 | socklen_t ai_addrlen; /* length of socket-address */ | ||
77 | struct sockaddr *ai_addr; /* socket-address for socket */ | ||
78 | char *ai_canonname; /* canonical name for service location */ | ||
79 | struct addrinfo *ai_next; /* pointer to next in list */ | ||
80 | }; | ||
81 | .Ed | ||
82 | .Pp | ||
83 | This structure can be used to provide hints concerning the type of socket | ||
84 | that the caller supports or wishes to use. | ||
85 | The caller can supply the following structure elements in | ||
86 | .Fa hints : | ||
87 | .Bl -tag -width "ai_socktypeXX" | ||
88 | .It Fa ai_family | ||
89 | The protocol family that should be used. | ||
90 | When | ||
91 | .Fa ai_family | ||
92 | is set to | ||
93 | .Dv PF_UNSPEC , | ||
94 | it means the caller will accept any protocol family supported by the | ||
95 | operating system. | ||
96 | .It Fa ai_socktype | ||
97 | Denotes the type of socket that is wanted: | ||
98 | .Dv SOCK_STREAM , | ||
99 | .Dv SOCK_DGRAM | ||
100 | or | ||
101 | .Dv SOCK_RAW . | ||
102 | When | ||
103 | .Fa ai_socktype | ||
104 | is zero the caller will accept any socket type. | ||
105 | .It Fa ai_protocol | ||
106 | Indicates which transport protocol is desired, | ||
107 | .Dv IPPROTO_UDP | ||
108 | or | ||
109 | .Dv IPPROTO_TCP . | ||
110 | If | ||
111 | .Fa ai_protocol | ||
112 | is zero the caller will accept any protocol. | ||
113 | .It Fa ai_flags | ||
114 | Flag bits. | ||
115 | .Bl -tag -width "AI_CANONNAMEXX" | ||
116 | .It Dv AI_CANONNAME | ||
117 | If the | ||
118 | .Dv AI_CANONNAME | ||
119 | bit is set, a successful call to | ||
120 | .Fn getaddrinfo | ||
121 | will return a NUL-terminated string containing the canonical name | ||
122 | of the specified hostname in the | ||
123 | .Fa ai_canonname | ||
124 | element of the first | ||
125 | .Li addrinfo | ||
126 | structure returned. | ||
127 | .It Dv AI_NUMERICHOST | ||
128 | If the | ||
129 | .Dv AI_NUMERICHOST | ||
130 | bit is set, it indicates that | ||
131 | .Fa hostname | ||
132 | should be treated as a numeric string defining an IPv4 or IPv6 address | ||
133 | and no name resolution should be attempted. | ||
134 | .It Dv AI_PASSIVE | ||
135 | If the | ||
136 | .Dv AI_PASSIVE | ||
137 | bit is set it indicates that the returned socket address structure | ||
138 | is intended for used in a call to | ||
139 | .Xr bind 2 . | ||
140 | In this case, if the | ||
141 | .Fa hostname | ||
142 | argument is a the null pointer, then the IP address portion of the | ||
143 | socket address structure will be set to | ||
144 | .Dv INADDR_ANY | ||
145 | for an IPv4 address or | ||
146 | .Dv IN6ADDR_ANY_INIT | ||
147 | for an IPv6 address. | ||
148 | .Pp | ||
149 | If the | ||
150 | .Dv AI_PASSIVE | ||
151 | bit is not set, the returned socket address structure will be ready | ||
152 | for use in a call to | ||
153 | .Xr connect 2 | ||
154 | for a connection-oriented protocol or | ||
155 | .Xr connect 2 , | ||
156 | .Xr sendto 2 | ||
157 | or | ||
158 | .Xr sendmsg 2 | ||
159 | if a connectionless protocol was chosen. | ||
160 | The | ||
161 | .Dv IP | ||
162 | address portion of the socket address structure will be set to the | ||
163 | loopback address if | ||
164 | .Fa hostname | ||
165 | is the null pointer and the | ||
166 | .Dv AI_PASSIVE | ||
167 | is not set. | ||
168 | .El | ||
169 | .El | ||
170 | .Pp | ||
171 | All other elements of the | ||
172 | .Li addrinfo | ||
173 | structure passed via | ||
174 | .Fa hints | ||
175 | must be zero or the null pointer. | ||
176 | .Pp | ||
177 | If | ||
178 | .Fa hints | ||
179 | is the null pointer, | ||
180 | .Fn getaddrinfo | ||
181 | behaves as if the caller provided a | ||
182 | .Li struct addrinfo | ||
183 | initialized to zero and with | ||
184 | .Fa ai_family | ||
185 | set to | ||
186 | .Dv PF_UNSPEC . | ||
187 | .Pp | ||
188 | After a successful call to | ||
189 | .Fn getaddrinfo , | ||
190 | .Fa *res | ||
191 | is a pointer to a linked list of one or more | ||
192 | .Li addrinfo | ||
193 | structures. | ||
194 | The list can be traversed by following the | ||
195 | .Fa ai_next | ||
196 | pointer in each | ||
197 | .Li addrinfo | ||
198 | structure until a null pointer is encountered. | ||
199 | The three members, | ||
200 | .Fa ai_family, | ||
201 | .Fa ai_socktype, | ||
202 | and | ||
203 | .Fa ai_protocol | ||
204 | in each returned | ||
205 | .Li addrinfo | ||
206 | structure are suitable for a call to | ||
207 | .Xr socket 2 . | ||
208 | For each | ||
209 | .Li addrinfo | ||
210 | structure in the list, the | ||
211 | .Fa ai_addr | ||
212 | member points to a filled-in socket address structure of length | ||
213 | .Fa ai_addrlen . | ||
214 | .Pp | ||
215 | All of the information returned by | ||
216 | .Fn getaddrinfo | ||
217 | is dynamically allocated: the | ||
218 | .Li addrinfo | ||
219 | structures themselves as well as the socket address structures and | ||
220 | the canonical host name strings included in the | ||
221 | .Li addrinfo | ||
222 | structures. | ||
223 | .Pp | ||
224 | Memory allocated for the dynamically allocated structures created by | ||
225 | a successful call to | ||
226 | .Fn getaddrinfo | ||
227 | is released by the | ||
228 | .Fn freeaddrinfo | ||
229 | function. | ||
230 | The | ||
231 | .Fa ai | ||
232 | pointer should be a | ||
233 | .Li addrinfo | ||
234 | structure created by a call to | ||
235 | .Fn getaddrinfo . | ||
236 | .Sh RETURN VALUES | ||
237 | .Fn getaddrinfo | ||
238 | returns zero on success or one of the error codes listed in | ||
239 | .Xr gai_strerror 3 | ||
240 | if an error occurs. | ||
241 | If both | ||
242 | .Fa hostname | ||
243 | and | ||
244 | .Fa servname | ||
245 | are | ||
246 | .Dv NULL , | ||
247 | .Fn getaddrinfo | ||
248 | returns | ||
249 | .Dv EAI_NONAME . | ||
250 | .Sh SEE ALSO | ||
251 | .Xr bind 2 , | ||
252 | .Xr connect 2 , | ||
253 | .Xr send 2 , | ||
254 | .Xr socket 2 , | ||
255 | .Xr gai_strerror 3 , | ||
256 | .Xr gethostbyname 3 , | ||
257 | .Xr getnameinfo 3 , | ||
258 | .Xr getservbyname 3 , | ||
259 | .Xr resolver 3 , | ||
260 | .Xr hosts 5 , | ||
261 | .Xr resolv.conf 5 , | ||
262 | .Xr services 5 , | ||
263 | .Xr hostname 7 , | ||
264 | .Xr named 8 | ||
265 | .Rs | ||
266 | .%A R. Gilligan | ||
267 | .%A S. Thomson | ||
268 | .%A J. Bound | ||
269 | .%A J. McCann | ||
270 | .%A W. Stevens | ||
271 | .%T Basic Socket Interface Extensions for IPv6 | ||
272 | .%R RFC 3493 | ||
273 | .%D February 2003 | ||
274 | .Re | ||
275 | .Rs | ||
276 | .%A Tatsuya Jinmei | ||
277 | .%A Atsushi Onoe | ||
278 | .%T "An Extension of Format for IPv6 Scoped Addresses" | ||
279 | .%R internet draft | ||
280 | .%N draft-ietf-ipngwg-scopedaddr-format-02.txt | ||
281 | .%O work in progress material | ||
282 | .Re | ||
283 | .Rs | ||
284 | .%A Craig Metz | ||
285 | .%T Protocol Independence Using the Sockets API | ||
286 | .%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" | ||
287 | .%D June 2000 | ||
288 | .Re | ||
289 | .Sh STANDARDS | ||
290 | The | ||
291 | .Fn getaddrinfo | ||
292 | function is defined by the | ||
293 | .St -p1003.1g-2000 | ||
294 | draft specification and documented in | ||
295 | .Dv "RFC 3493" , | ||
296 | .Dq Basic Socket Interface Extensions for IPv6 . | ||
297 | .Sh BUGS | ||
298 | Due to the use of dynamic allocation, | ||
299 | .Fn getaddrinfo | ||
300 | is not thread-safe. | ||