OSDN Git Service

(split) Apply minor changes from v3.32 to v3.35 in the upstream.
[linuxjm/LDP_man-pages.git] / draft / man3 / getaddrinfo.3
1 .\" Copyright (c) 2007, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (c) 2006 Ulrich Drepper <drepper@redhat.com>
3 .\" A few pieces of an earlier version remain:
4 .\" Copyright 2000, Sam Varshavchik <mrsam@courier-mta.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" References: RFC 2553
27 .\"
28 .\" 2005-08-09, mtk, added AI_ALL, AI_ADDRCONFIG, AI_V4MAPPED,
29 .\"                     and AI_NUMERICSERV.
30 .\" 2006-11-25, Ulrich Drepper <drepper@redhat.com>
31 .\"     Add text describing Internationalized Domain Name extensions.
32 .\" 2007-06-08, mtk: added example programs
33 .\" 2008-02-26, mtk; clarify discussion of NULL 'hints' argument; other
34 .\"     minor rewrites.
35 .\" 2008-06-18, mtk: many parts rewritten
36 .\" 2008-12-04, Petr Baudis <pasky@suse.cz>
37 .\"     Describe results ordering and reference /etc/gai.conf.
38 .\" FIXME . glibc's 2.9 NEWS file documents DCCP and UDP-lite support
39 .\"           and is SCTP support now also there?
40 .\"
41 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
42 .\" Translated Sun Jan 14 2001 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
43 .\" Updated 2005-10-09 by Kentaro Shirakata <argrath@ub32.org>
44 .\" Updated 2007-01-01 by Kentaro Shirakata <argrath@ub32.org>
45 .\" Updated 2007-06-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.55
46 .\" Updated 2008-04-04, Akihiro MOTOKI, LDP v2.79
47 .\" Updated 2008-08-11, Akihiro MOTOKI, LDP v3.05
48 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
49 .\" Updated 2008-12-26, Akihiro MOTOKI, LDP v3.15
50 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
51 .\"
52 .\"WORD:        null pointer    ¥Ì¥ë¡¦¥Ý¥¤¥ó¥¿
53 .\"
54 .TH GETADDRINFO 3 2010-09-27 "GNU" "Linux Programmer's Manual"
55 .\"O .SH NAME
56 .\"O getaddrinfo, freeaddrinfo, gai_strerror \- network address and
57 .\"O service translation
58 .SH Ì¾Á°
59 getaddrinfo, freeaddrinfo, gai_strerror \-
60 ¥Í¥Ã¥È¥ï¡¼¥¯¤Î¥¢¥É¥ì¥¹¤È¥µ¡¼¥Ó¥¹¤òÊÑ´¹¤¹¤ë
61 .\"O .SH SYNOPSIS
62 .SH ½ñ¼°
63 .nf
64 .B #include <sys/types.h>
65 .B #include <sys/socket.h>
66 .B #include <netdb.h>
67 .sp
68 .BI "int getaddrinfo(const char *" "node" ", const char *" "service" ,
69 .BI "                const struct addrinfo *" "hints" ,
70 .BI "                struct addrinfo **" "res" );
71 .sp
72 .BI "void freeaddrinfo(struct addrinfo *" "res" );
73 .sp
74 .BI "const char *gai_strerror(int " "errcode" );
75 .fi
76 .sp
77 .in -4n
78 .\"O Feature Test Macro Requirements for glibc (see
79 .\"O .BR feature_test_macros (7)):
80 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
81 .RB ( feature_test_macros (7)
82 »²¾È):
83 .ad l
84 .in
85 .sp
86 .BR getaddrinfo (),
87 .BR freeaddrinfo (),
88 .BR gai_strerror ():
89 .RS 4
90 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
91 .RE
92 .ad b
93 .\"O .SH DESCRIPTION
94 .SH ÀâÌÀ
95 .\"O Given
96 .\"O .I node
97 .\"O and
98 .\"O .IR service ,
99 .\"O which identify an Internet host and a service,
100 .\"O .BR getaddrinfo ()
101 .\"O returns one or more
102 .\"O .I addrinfo
103 .\"O structures, each of which contains an Internet address
104 .\"O that can be specified in a call to
105 .\"O .BR bind (2)
106 .\"O or
107 .\"O .BR connect (2).
108 .BR getaddrinfo ()
109 ¤Ï¡¢(¥¤¥ó¥¿¡¼¥Í¥Ã¥È¤Î¥Û¥¹¥È¤È¥µ¡¼¥Ó¥¹¤ò¼±Ê̤¹¤ë)
110 .I node
111 ¤È
112 .I service
113 ¤òÅϤ¹¤È¡¢°ì¤Ä°Ê¾å¤Î
114 .I addrinfo
115 ¹½Â¤ÂΤòÊÖ¤¹¡£¤½¤ì¤¾¤ì¤Î
116 .I addrinfo
117 ¹½Â¤ÂΤˤϡ¢
118 .BR bind (2)
119 ¤ä
120 .BR connect (2)
121 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë»ØÄê¤Ç¤­¤ë¥¤¥ó¥¿¡¼¥Í¥Ã¥È¥¢¥É¥ì¥¹¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë¡£
122 .\"O The
123 .\"O .BR getaddrinfo ()
124 .\"O function combines the functionality provided by the
125 .\"O .\" .BR getipnodebyname (3),
126 .\"O .\" .BR getipnodebyaddr (3),
127 .\"O .BR getservbyname (3)
128 .\"O and
129 .\"O .BR getservbyport (3)
130 .\"O functions into a single interface, but unlike the latter functions,
131 .\"O .BR getaddrinfo ()
132 .\"O is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies.
133 .BR getaddrinfo ()
134 ´Ø¿ô¤Ï¡¢
135 .\" .BR getipnodebyname (3),
136 .\" .BR getipnodebyaddr (3),
137 .BR getservbyname (3)
138 ¤È
139 .BR getservbyport (3)
140 ¤Îµ¡Ç½¤ò¤Þ¤È¤á¤Æ°ì¤Ä¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¤·¤¿¤â¤Î¤Ç¤¢¤ë¤¬¡¢
141 ¤³¤ì¤é¤Î´Ø¿ô¤È°ã¤¤¡¢
142 .BR getaddrinfo ()
143 ¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤¢¤ê¡¢
144 .BR getaddrinfo ()
145 ¤ò»È¤¦¤³¤È¤Ç¥×¥í¥°¥é¥à¤Ï IPv4 ¤È IPv6 ¤Î°ã¤¤¤Ë´Ø¤¹¤ë°Í¸´Ø·¸¤ò
146 ¤Ê¤¯¤¹¤³¤È¤¬¤Ç¤­¤ë¡£
147 .PP
148 .\"O The
149 .\"O .I addrinfo
150 .\"O structure used by
151 .\"O .BR getaddrinfo ()
152 .\"O contains the following fields:
153 .BR getaddrinfo ()
154 ¤¬ÍѤ¤¤ë
155 .I addrinfo
156 ¹½Â¤ÂΤϰʲ¼¤Î¥Õ¥£¡¼¥ë¥É¤ò´Þ¤à¡£
157 .sp
158 .in +4n
159 .nf
160 struct addrinfo {
161     int              ai_flags;
162     int              ai_family;
163     int              ai_socktype;
164     int              ai_protocol;
165     size_t           ai_addrlen;
166     struct sockaddr *ai_addr;
167     char            *ai_canonname;
168     struct addrinfo *ai_next;
169 };
170 .fi
171 .in
172 .PP
173 .\"O The
174 .\"O .I hints
175 .\"O argument points to an
176 .\"O .I addrinfo
177 .\"O structure that specifies criteria for selecting the socket address
178 .\"O structures returned in the list pointed to by
179 .\"O .IR res .
180 .\"O If
181 .\"O .I hints
182 .\"O is not NULL it points to an
183 .\"O .I addrinfo
184 .\"O structure whose
185 .\"O .IR ai_family ,
186 .\"O .IR ai_socktype ,
187 .\"O and
188 .\"O .I ai_protocol
189 .\"O specify criteria that limit the set of socket addresses returned by
190 .\"O .BR getaddrinfo (),
191 .\"O as follows:
192 .I hints
193 °ú¤­¿ô¤Ï
194 .I addrinfo
195 ¹½Â¤ÂΤò»Ø¤·¼¨¤·¡¢¤³¤Î¹½Â¤ÂΤòÍѤ¤¤Æ
196 .I res
197 ¤¬»Ø¤¹¥ê¥¹¥È¤ËÆþ¤ì¤ÆÊÖ¤¹¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¹½Â¤ÂΤòÁªÂò¤¹¤ë¤¿¤á¤Î´ð½à¤ò»ØÄꤹ¤ë¡£
198 .I hints
199 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
200 .I hints
201 ¤Ï
202 .I addrinfo
203 ¹½Â¤ÂΤò»Ø¤·¼¨¤·¡¢¤½¤Î¹½Â¤ÂΤΥե£¡¼¥ë¥É
204 .IR ai_family ,
205 .IR ai_socktype ,
206 .I ai_protocol
207 ¤Ç
208 .BR getaddrinfo ()
209 ¤¬ÊÖ¤¹¥½¥±¥Ã¥È¥¢¥É¥ì¥¹½¸¹ç¤ËÂФ¹¤ë´ð½à¤ò»ØÄꤹ¤ë¡£
210 .TP 12
211 .I ai_family
212 .\"O This field specifies the desired address family for the returned addresses.
213 .\"O Valid values for this field include
214 .\"O .BR AF_INET
215 .\"O and
216 .\"O .BR AF_INET6 .
217 .\"O The value
218 .\"O .B AF_UNSPEC
219 .\"O indicates that
220 .\"O .BR getaddrinfo ()
221 .\"O should return socket addresses for any address family
222 .\"O (either IPv4 or IPv6, for example) that can be used with
223 .\"O .I node
224 .\"O and
225 .\"O .IR service .
226 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÏÊÖ¤µ¤ì¤ë¥¢¥É¥ì¥¹¤Î´õ˾¤Î¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ò»ØÄꤹ¤ë¡£
227 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë»ØÄê¤Ç¤­¤ëÍ­¸ú¤ÊÃͤȤ·¤Æ¤Ï
228 .B AF_INET
229 ¤È
230 .B AF_INET6
231 ¤¬¤¢¤ë¡£
232 ¤Þ¤¿¡¢ÃÍ
233 .B AF_UNSPEC
234 ¤ò»ØÄꤹ¤ë¤È¡¢
235 .BR getaddrinfo ()
236 ¤Ï
237 .I node
238 ¤È
239 .I service
240 ¤Ç»ÈÍѤǤ­¤ë¤¤¤º¤ì¤«¤Î¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼ (Î㤨¤Ð IPv4 ¤« IPv6) ¤Î
241 ¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤òÊÖ¤¹¤³¤È¤òµá¤á¤é¤ì¤ë¡£
242 .TP
243 .I ai_socktype
244 .\"O This field specifies the preferred socket type, for example
245 .\"O .BR SOCK_STREAM
246 .\"O or
247 .\"O .BR SOCK_DGRAM .
248 .\"O Specifying 0 in this field indicates that socket addresses of any type
249 .\"O can be returned by
250 .\"O .BR getaddrinfo ().
251 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¿ä¾©¤Î¥½¥±¥Ã¥È·¿ (Î㤨¤Ð
252 .B SOCK_STREAM
253 ¤ä
254 .BR SOCK_DGRAM )
255 ¤ò»ØÄꤹ¤ë¡£
256 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤ò»ØÄꤹ¤ë¤È¡¢Ç¤°Õ¤Î¥½¥±¥Ã¥È·¿¤Î¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ò
257 .BR getaddrinfo ()
258 ¤¬ÊÖ¤·¤Æ¤è¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
259 .TP
260 .I ai_protocol
261 .\"O This field specifies the protocol for the returned socket addresses.
262 .\"O Specifying 0 in this field indicates that socket addresses with
263 .\"O any protocol can be returned by
264 .\"O .BR getaddrinfo ().
265 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÏÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Î¥×¥í¥È¥³¥ë¤ò»ØÄꤹ¤ë¡£
266 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤ò»ØÄꤹ¤ë¤È¡¢Ç¤°Õ¤Î¥×¥í¥È¥³¥ë¤Î¤Î¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ò
267 .BR getaddrinfo ()
268 ¤¬ÊÖ¤·¤Æ¤è¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
269 .TP
270 .I ai_flags
271 .\"O This field specifies additional options, described below.
272 .\"O Multiple flags are specified by bitwise OR-ing them together.
273 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¡¢ÄɲäΥª¥×¥·¥ç¥ó (²¼µ­) ¤ò»ØÄꤹ¤ë¡£
274 Ê£¿ô¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ëºÝ¤Ë¤Ï¡¢¤½¤ì¤é¤Î¥Ó¥Ã¥Èñ°Ì¤Î OR ¤ò¤È¤Ã¤Æ»ØÄꤹ¤ë¡£
275 .PP
276 .\"O All the other fields in the structure pointed to by
277 .\"O .I hints
278 .\"O must contain either 0 or a NULL pointer, as appropriate.
279 .I hints
280 ¤¬»Ø¤·¼¨¤¹¹½Â¤ÂΤξ¤Î¤¹¤Ù¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤Ë¤Ï
281 0 ¤« NULL ¥Ý¥¤¥ó¥¿¤òŬÀÚ¤ËÆþ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
282 .\"O Specifying
283 .\"O .I hints
284 .\"O as NULL is equivalent to setting
285 .\"O .I ai_socktype
286 .\"O and
287 .\"O .I ai_protocol
288 .\"O to 0;
289 .\"O .I ai_family
290 .\"O to
291 .\"O .BR AF_UNSPEC ;
292 .\"O and
293 .\"O .I ai_flags
294 .\"O to
295 .\"O .BR "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)" .
296 .I hints
297 ¤Ë NULL ¤ò»ØÄꤹ¤ë¤Î¤Ï¡¢
298 .I ai_socktype
299 ¤È
300 .I ai_protocol
301 ¤Ë 0 ¤ò¡¢
302 .I ai_family
303 ¤Ë
304 .B AF_UNSPEC
305 ¤ò¡¢
306 .I ai_flags
307 ¤Ë
308 .B "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)"
309 ¤òÀßÄꤹ¤ë¤Î¤ÈÅù²Á¤Ç¤¢¤ë¡£
310
311 .\"O .I node
312 .\"O specifies either a numerical network address
313 .\"O (for IPv4, numbers-and-dots notation as supported by
314 .\"O .BR inet_aton (3);
315 .\"O for IPv6, hexadecimal string format as supported by
316 .\"O .BR inet_pton (3)),
317 .\"O or a network hostname, whose network addresses are looked up and resolved.
318 .\"O If
319 .\"O .I hints.ai_flags
320 .\"O contains the
321 .\"O .B AI_NUMERICHOST
322 .\"O flag then
323 .\"O .I node
324 .\"O must be a numerical network address.
325 .\"O The
326 .\"O .B AI_NUMERICHOST
327 .\"O flag suppresses any potentially lengthy network host address lookups.
328 .I node
329 ¤Ë¤Ï¡¢¿ôÃÍ·Á¼°¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹
330 (IPv4 ¤Î¾ì¹ç¤Ï
331 .BR inet_aton (3)
332 ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»ú¤Ë¤è¤ëɽµ­¡¢
333 IPv6 ¤Î¾ì¹ç¤Ï
334 .BR inet_pton (3)
335 ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë 16 ¿Ê¿ô¤Îʸ»úÎó·Á¼°) ¤â¤·¤¯¤Ï
336 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È̾¤ò»ØÄꤹ¤ë¡£
337 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È̾¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤Ï¡¢¤½¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¸¡º÷¤µ¤ì¡¢
338 ̾Á°²ò·è¤¬¹Ô¤Ê¤ï¤ì¤ë¡£
339 .I hints.ai_flags
340 ¤Ë
341 .B AI_NUMERICHOST
342 ¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢
343 .I node
344 ¤Ï¿ôÃÍ·Á¼°¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
345 .B AI_NUMERICHOST
346 ¥Õ¥é¥°¤ò»È¤¦¤È¡¢»þ´Ö¤Î³Ý¤«¤ë²ÄǽÀ­¤Î¤¢¤ë¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¥¢¥É¥ì¥¹¤Î¸¡º÷¤Ï
347 ¤¹¤Ù¤ÆÍÞÀ©¤µ¤ì¤ë¡£
348 .PP
349 .\"O If the
350 .\"O .B AI_PASSIVE
351 .\"O flag is specified in
352 .\"O .IR hints.ai_flags ,
353 .\"O and
354 .\"O .I node
355 .\"O is NULL,
356 .\"O then the returned socket addresses will be suitable for
357 .\"O .BR bind (2)ing
358 .\"O a socket that will
359 .\"O .BR accept (2)
360 .\"O connections.
361 .\"O The returned socket address will contain the "wildcard address"
362 .\"O .RB ( INADDR_ANY
363 .\"O for IPv4 addresses,
364 .\"O .BR IN6ADDR_ANY_INIT
365 .\"O for IPv6 address).
366 .\"O The wildcard address is used by applications (typically servers)
367 .\"O that intend to accept connections on any of the hosts's network addresses.
368 .\"O If
369 .\"O .I node
370 .\"O is not NULL, then the
371 .\"O .B AI_PASSIVE
372 .\"O flag is ignored.
373 .IR hints.ai_flags
374 ¤Ë
375 .B AI_PASSIVE
376 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¡¢¤«¤Ä
377 .I node
378 ¤¬ NULL ¤Î¾ì¹ç¡¢
379 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ï
380 ¥³¥Í¥¯¥·¥ç¥ó¤ò
381 .BR accept (2)
382 ¤¹¤ë¤¿¤á¤Î¥½¥±¥Ã¥È¤ò
383 .BR bind (2)
384 ¤¹¤ë¤Î¤ËŬ¤·¤¿¤â¤Î¤È¤Ê¤ë¡£
385 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ë¤Ï¡Ö¥ï¥¤¥ë¥É¥«¡¼¥É¡¦¥¢¥É¥ì¥¹¡×
386 (IPv4 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
387 .BR INADDR_ANY ¡¢
388 IPv6 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
389 .BR IN6ADDR_ANY_INIT )
390 ¤¬Æþ¤ë¡£
391 ¥ï¥¤¥ë¥É¥«¡¼¥É¡¦¥¢¥É¥ì¥¹¤Ï¡¢Ç¤°Õ¤Î¥Û¥¹¥È¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤ÇÀܳ¤ò
392 ¼õ¤±ÉÕ¤±¤è¤¦¤È¤¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó (Ä̾ï¤Ï¥µ¡¼¥Ð¡¼) ¤ÇÍѤ¤¤é¤ì¤ë¡£
393 .I node
394 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
395 .B AI_PASSIVE
396 ¥Õ¥é¥°¤Ï̵»ë¤µ¤ì¤ë¡£
397 .PP
398 .\"O If the
399 .\"O .B AI_PASSIVE
400 .\"O flag is not set in
401 .\"O .IR hints.ai_flags ,
402 .\"O then the returned socket addresses will be suitable for use with
403 .\"O .BR connect (2),
404 .\"O .BR sendto (2),
405 .\"O or
406 .\"O .BR sendmsg (2).
407 .\"O If
408 .\"O .I node
409 .\"O is NULL,
410 .\"O then the network address will be set to the loopback interface address
411 .\"O .RB ( INADDR_LOOPBACK
412 .\"O for IPv4 addresses,
413 .\"O .BR IN6ADDR_LOOPBACK_INIT
414 .\"O for IPv6 address);
415 .\"O this is used by applications that intend to communicate
416 .\"O with peers running on the same host.
417 .I hints.ai_flags
418 ¤Ë
419 .B AI_PASSIVE
420 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
421 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ï
422 .BR connect (2),
423 .BR sendto (2),
424 .BR sendmsg (2)
425 ¤Ç¤Î»ÈÍѤËŬ¤·¤¿¤â¤Î¤È¤Ê¤ë¡£
426 .I node
427 ¤¬ NULL ¤Î¾ì¹ç¡¢¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ë¤Ï¥ë¡¼¥×¥Ð¥Ã¥¯¡¦¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Î
428 ¥¢¥É¥ì¥¹ (IPv4 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
429 .BR INADDR_LOOPBACK
430 IPv6 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
431 .BR IN6ADDR_LOOPBACK_INIT ) ¤¬ÀßÄꤵ¤ì¤ë¡£
432 ¤³¤ì¤ÏƱ¤¸¥Û¥¹¥È¾å¤ÇÆ°ºî¤·¤Æ¤¤¤ëÀܳÁê¼ê¤ÈÄÌ¿®¤¹¤ë¤è¤¦¤Ê
433 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÇÍѤ¤¤é¤ì¤ë¡£
434 .PP
435 .\"O .I service
436 .\"O sets the port in each returned address structure.
437 .\"O If this argument is a service name (see
438 .\"O .BR services (5)),
439 .\"O it is translated to the corresponding port number.
440 .\"O This argument can also be specified as a decimal number,
441 .\"O which is simply converted to binary.
442 .I service
443 ¤Ë¤è¤ê¡¢ÊÖ¤µ¤ì¤ë³Æ¥¢¥É¥ì¥¹¹½Â¤ÂΤΥݡ¼¥ÈÈֹ椬·è¤Þ¤ë¡£
444 ¤³¤Î°ú¤­¿ô¤¬¥µ¡¼¥Ó¥¹Ì¾
445 .RB ( services (5)
446 »²¾È) ¤Î¾ì¹ç¡¢Âбþ¤¹¤ë¥Ý¡¼¥ÈÈÖ¹æ¤ËËÝÌõ¤µ¤ì¤ë¡£
447 ¤³¤Î°ú¤­¿ô¤Ë¤Ï 10 ¿Ê¿ô¤â»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¡¢
448 ¤³¤Î¾ì¹ç¤Ë¤Ï¥Ð¥¤¥Ê¥ê¤Ø¤ÎÊÑ´¹¤À¤±¤¬¹Ô¤ï¤ì¤ë¡£
449 .\"O If
450 .\"O .I service
451 .\"O is NULL, then the port number of the returned socket addresses
452 .\"O will be left uninitialized.
453 .I service
454 ¤¬ NULL ¤Î¾ì¹ç¡¢ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Î¥Ý¡¼¥ÈÈÖ¹æ¤Ï
455 ½é´ü²½¤µ¤ì¤Ê¤¤¤Þ¤Þ¤È¤Ê¤ë¡£
456 .\"O If
457 .\"O .B AI_NUMERICSERV
458 .\"O is specified in
459 .\"O .I hints.ai_flags
460 .\"O and
461 .\"O .I service
462 .\"O is not NULL, then
463 .\"O .I service
464 .\"O must point to a string containing a numeric port number.
465 .I hints.ai_flags
466 ¤Ë
467 .B AI_NUMERICSERV
468 ¤¬»ØÄꤵ¤ì¡¢¤«¤Ä
469 .I service
470 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
471 .I service
472 ¤Ï¿ôÃͤΥݡ¼¥ÈÈÖ¹æ¤ò´Þ¤àʸ»úÎó¤ò»Ø¤·¼¨¤µ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
473 .\"O This flag is used to inhibit the invocation of a name resolution service
474 .\"O in cases where it is known not to be required.
475 ¤³¤Î¥Õ¥é¥°¤Ï¡¢Ì¾Á°²ò·è¥µ¡¼¥Ó¥¹¤¬ÉÔÍפǤ¢¤ë¤³¤È¤¬Ê¬¤«¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¡¢
476 ¥µ¡¼¥Ó¥¹¤Îµ¯Æ°¤òÍÞÀ©¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
477 .PP
478 .\"O Either
479 .\"O .I node
480 .\"O or
481 .\"O .IR service ,
482 .\"O but not both, may be NULL.
483 .I node
484 ¤È
485 .I service
486 ¤Î¤É¤Á¤é¤«¤Ï NULL ¤Ë¤·¤Æ¤è¤¤¤¬¡¢Î¾ÊýƱ»þ¤Ë NULL ¤Ë¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
487 .PP
488 .\"O The
489 .\"O .BR getaddrinfo ()
490 .\"O function allocates and initializes a linked list of
491 .\"O .I addrinfo
492 .\"O structures, one for each network address that matches
493 .\"O .I node
494 .\"O and
495 .\"O .IR service ,
496 .\"O subject to any restrictions imposed by
497 .\"O .IR hints ,
498 .\"O and returns a pointer to the start of the list in
499 .\"O .IR res .
500 .\"O The items in the linked list are linked by the
501 .\"O .I ai_next
502 .\"O field.
503 .BR getaddrinfo ()
504 ´Ø¿ô¤Ï¡¢
505 .I addrinfo
506 ¹½Â¤ÂΤΥá¥â¥ê³ÎÊݤò¹Ô¤¤¡¢
507 .I addrinfo
508 ¹½Â¤ÂΤΥê¥ó¥¯¥ê¥¹¥È¤ò½é´ü²½¤·¡¢
509 .I res
510 ¤Ë¥ê¥¹¥È¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÆþ¤ì¤ÆÊÖ¤¹¡£
511 ¤³¤Î¤È¤­¡¢³Æ¹½Â¤ÂΤΥͥåȥ¥¯¥¢¥É¥ì¥¹¤Ï
512 .I node
513 ¤È
514 .I service
515 ¤Ë°ìÃפ·¡¢
516 .I hints
517 ¤Ç²Ý¤µ¤ì¤¿¤¹¤Ù¤Æ¤ÎÀ©¸Â¤òËþ¤¿¤¹¤â¤Î¤È¤Ê¤ë¡£
518 ¥ê¥ó¥¯¥ê¥¹¥È¤ÎÍ×ÁǤÏ
519 .I ai_next
520 ¥Õ¥£¡¼¥ë¥É¤Ë¤è¤êÏ¢·ë¤µ¤ì¤ë¡£
521
522 .\"O There are several reasons why
523 .\"O the linked list may have more than one
524 .\"O .I addrinfo
525 .\"O structure, including: the network host is multihomed, accessible
526 .\"O over multiple protocols (e.g. both
527 .\"O .BR AF_INET
528 .\"O and
529 .\"O .BR AF_INET6 );
530 .\"O or the same service is available from multiple socket types (one
531 .\"O .B SOCK_STREAM
532 .\"O address and another
533 .\"O .B SOCK_DGRAM
534 .\"O address, for example).
535 ¥ê¥ó¥¯¥ê¥¹¥È¤Î
536 .I addrinfo
537 ¹½Â¤ÂΤÏÊ£¿ô¸Ä¤Ë¤Ê¤ë¤³¤È¤â¤¢¤ê¡¢¤½¤ÎÍýͳ¤Ï¤¤¤¯¤Ä¤«¤¢¤ë¡£
538 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤¬¥Þ¥ë¥Á¥Û¡¼¥à¤Ç¤¢¤ë¡¢
539 Ê£¿ô¤Î¥×¥í¥È¥³¥ë¤Ç¥¢¥¯¥»¥¹¤Ç¤­¤ë (Î㤨¤Ð
540 .B AF_INET
541 ¤È
542 .B AF_INET6
543 ¤ÎξÊý) ¡¢
544 Ê£¿ô¤Î¥½¥±¥Ã¥È¼ïÊ̤ÇƱ¤¸¥µ¡¼¥Ó¥¹¤¬ÍøÍѤǤ­¤ë
545 (Î㤨¤Ð¡¢¤Ò¤È¤Ä¤¬
546 .B SOCK_STREM
547 ¥¢¥É¥ì¥¹¤Ç¡¢¤â¤¦¤Ò¤È¤Ä¤¬
548 .B SOCK_DGRAM
549 ¥¢¥É¥ì¥¹¤Ç¤¢¤ë)¡¢¤¬¤¢¤ë¡£
550 .\"O Normally, the application should try
551 .\"O using the addresses in the order in which they are returned.
552 .\"O The sorting function used within
553 .\"O .BR getaddrinfo ()
554 .\"O is defined in RFC\ 3484; the order can be tweaked for a particular
555 .\"O system by editing
556 .\"O .IR /etc/gai.conf
557 .\"O (available since glibc 2.5).
558 Ä̾ï¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÏÊÖ¤µ¤ì¤¿½ç½ø¤Ç¥¢¥É¥ì¥¹¤ò»î¤¹¤Ù¤­¤Ç¤¢¤ë¡£
559 .BR getaddrinfo ()
560 ¤ÎÃæ¤Ç»ÈÍѤµ¤ì¤ëʤÙÂؤ¨´Ø¿ô¤Ï RFC\ 3484 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
561 Æüì¤Ê¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
562 .I /etc/gai.conf
563 ¤òÊÔ½¸¤¹¤ë¤³¤È¤Ç¡¢¤³¤Î½ç½ø¤òÈùÄ´À°¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë
564 .RI ( /etc/gai.conf
565 ¤Ï glibc 2.5 °Ê¹ß¤ÇÍøÍѤǤ­¤ë)¡£
566 .PP
567 .\"O If
568 .\"O .I hints.ai_flags
569 .\"O includes the
570 .\"O .B AI_CANONNAME
571 .\"O flag, then the
572 .\"O .I ai_canonname
573 .\"O field of the first of the
574 .\"O .I addrinfo
575 .\"O structures in the returned list is set to point to the
576 .\"O official name of the host.
577 .I hints.ai_flags
578 ¤Ë
579 .B AI_CANONNAME
580 ¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢ÊÖ¤µ¤ì¤ë¥ê¥¹¥È¤ÎºÇ½é¤Î
581 .I addrinfo
582 ¹½Â¤ÂΤÎ
583 .I ai_canonname
584 ¥Õ¥£¡¼¥ë¥É¤Ï¥Û¥¹¥È¤Î¸ø¼°¤Ê̾Á°¤ò»Ø¤¹¤è¤¦¤ËÀßÄꤵ¤ì¤ë¡£
585 .\" In glibc prior to 2.3.4, the ai_canonname of each addrinfo
586 .\" structure was set pointing to the canonical name; that was
587 .\" more than POSIX.1-2001 specified, or other implementations provided.
588 .\" MTK, Aug 05
589
590 .\"O The remaining fields of each returned
591 .\"O .I addrinfo
592 .\"O structure are initialized as follows:
593 ÊÖ¤µ¤ì¤ë³Æ¡¹¤Î
594 .I addrinfo
595 ¹½Â¤ÂΤλĤê¤Î¥Õ¥£¡¼¥ë¥É¤Ï°Ê²¼¤Î¤è¤¦¤Ë½é´ü²½¤µ¤ì¤ë¡£
596 .IP * 2
597 .\"O The
598 .\"O .IR ai_family ,
599 .\"O .IR ai_socktype ,
600 .\"O and
601 .\"O .I ai_protocol
602 .\"O fields return the socket creation parameters (i.e., these fields have
603 .\"O the same meaning as the corresponding arguments of
604 .\"O .BR socket (2)).
605 .IR ai_family ,
606 .IR ai_socktype ,
607 .I ai_protocol
608 ¥Õ¥£¡¼¥ë¥É¤Ï¥½¥±¥Ã¥ÈÀ¸À®¥Ñ¥é¥á¡¼¥¿¤òÊÖ¤¹
609 (¤³¤ì¤é¤Î¥Õ¥£¡¼¥ë¥É¤Î°ÕÌ£¤Ï
610 .BR socket (2)
611 ¤ÎƱ¤¸Ì¾Á°¤Î°ú¤­¿ô¤ÈƱ¤¸¤Ç¤¢¤ë)¡£
612 .\"O For example,
613 .\"O .I ai_family
614 .\"O might return
615 .\"O .B AF_INET
616 .\"O or
617 .\"O .BR AF_INET6 ;
618 .\"O .I ai_socktype
619 .\"O might return
620 .\"O .B SOCK_DGRAM
621 .\"O or
622 .\"O .BR SOCK_STREAM ;
623 .\"O and
624 .\"O .I ai_protocol
625 .\"O returns the protocol for the socket.
626 Î㤨¤Ð¡¢
627 .I ai_family
628 ¤Ï
629 .B AF_INET
630 ¤ä
631 .B AF_INET6
632 ¤òÊÖ¤·¡¢
633 .I ai_socktype
634 ¤Ï
635 .B SOCK_DGRAM
636 ¤ä
637 .BR SOCK_STREAM
638 ¤òÊÖ¤·¡¢
639 .I ai_protocol
640 ¤Ï¤½¤Î¥½¥±¥Ã¥È¤Î¥×¥í¥È¥³¥ë¤òÊÖ¤¹¡£
641 .IP *
642 .\"O A pointer to the socket address is placed in the
643 .\"O .I ai_addr
644 .\"O field, and the length of the socket address, in bytes,
645 .\"O is placed in the
646 .\"O .I ai_addrlen
647 .\"O field.
648 .I ai_addr
649 ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬½ñ¤­¹þ¤Þ¤ì¡¢
650 .I ai_addrlen
651 ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ÎŤµ¤¬¥Ð¥¤¥Èñ°Ì¤Ç½ñ¤­¹þ¤Þ¤ì¤ë¡£
652 .PP
653 .\"O If
654 .\"O .I hints.ai_flags
655 .\"O includes the
656 .\"O .B AI_ADDRCONFIG
657 .\"O flag, then IPv4 addresses are returned in the list pointed to by
658 .\"O .I res
659 .\"O only if the local system has at least one
660 .\"O IPv4 address configured, and IPv6 addresses are only returned
661 .\"O if the local system has at least one IPv6 address configured.
662 .I hints.ai_flags
663 ¤¬
664 .B AI_ADDRCONFIG
665 ¤ò´Þ¤à¾ì¹ç¡¢
666 .I res
667 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï¡¢
668 ¥í¡¼¥«¥ë¥·¥¹¥Æ¥à¤ËºÇÄã°ì¤Ä¤Î IPv4 ¥¢¥É¥ì¥¹¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï
669 IPv4 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¡¢
670 ¥í¡¼¥«¥ë¥·¥¹¥Æ¥à¤ËºÇÄã°ì¤Ä¤Î IPv6 ¥¢¥É¥ì¥¹¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï
671 IPv6 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¤ë¡£
672 .PP
673 .\"O If
674 .\"O .I hint.ai_flags
675 .\"O specifies the
676 .\"O .B AI_V4MAPPED
677 .\"O flag, and
678 .\"O .I hints.ai_family
679 .\"O was specified as
680 .\"O .BR AF_INET6 ,
681 .\"O and no matching IPv6 addresses could be found,
682 .\"O then return IPv4-mapped IPv6 addresses in the list pointed to by
683 .\"O .IR res .
684 .I hint.ai_flags
685 ¤Ë
686 .B AI_V4MAPPED
687 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
688 .I hints.ai_family
689 ¤Ë
690 .B AF_INET6
691 ¤¬»ØÄꤵ¤ì¡¢
692 ¥Þ¥Ã¥Á¤¹¤ë IPv6 ¥¢¥É¥ì¥¹¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
693 .I res
694 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï IPv4-mapped IPv6 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¤ë¡£
695 .\"O If both
696 .\"O .B AI_V4MAPPED
697 .\"O and
698 .\"O .B AI_ALL
699 .\"O are specified in
700 .\"O .IR hints.ai_flags ,
701 .\"O then return both IPv6 and IPv4-mapped IPv6 addresses
702 .\"O in the list pointed to by
703 .\"O .IR res .
704 .I hints.ai_flags
705 ¤Ë
706 .B AI_V4MAPPED
707 ¤È
708 .B AI_ALL
709 ¤ÎξÊý¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
710 .I res
711 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï IPv6 ¥¢¥É¥ì¥¹¤È IPv4-mapped IPv6 ¥¢¥É¥ì¥¹¤Î
712 ξÊý¤¬ÊÖ¤µ¤ì¤ë¡£
713 .\"O .B AI_ALL
714 .\"O is ignored if
715 .\"O .B AI_V4MAPPED
716 .\"O is not also specified.
717 .B AI_V4MAPPED
718 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
719 .B AI_ALL
720 ¤Ï̵»ë¤µ¤ì¤ë¡£
721 .PP
722 .\"O The
723 .\"O .BR freeaddrinfo ()
724 .\"O function frees the memory that was allocated
725 .\"O for the dynamically allocated linked list
726 .\"O .IR res .
727 .BR freeaddrinfo ()
728 ´Ø¿ô¤Ï¡¢
729 ¥ê¥ó¥¯¥ê¥¹¥È
730 .I res
731 ¤ËÂФ·¤ÆưŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë¡£
732 .\"O .SS "Extensions to getaddrinfo() for Internationalized Domain Names"
733 .SS "¹ñºÝ²½¥É¥á¥¤¥ó̾¤Î¤¿¤á¤Î getaddrinfo() ¤Î³ÈÄ¥"
734 .PP
735 .\"O Starting with glibc 2.3.4,
736 .\"O .BR getaddrinfo ()
737 .\"O has been extended to selectively allow the incoming and outgoing
738 .\"O hostnames to be transparently converted to and from the
739 .\"O Internationalized Domain Name (IDN) format (see RFC 3490,
740 .\"O .IR "Internationalizing Domain Names in Applications (IDNA)" ).
741 .\"O Four new flags are defined:
742 glibc 2.3.4 ¤«¤é¡¢
743 .BR getaddrinfo ()
744 ¤ÏÆþ½ÐÎϤ¹¤ë¥Û¥¹¥È̾¤òÆ©²áŪ¤Ë¹ñºÝ²½¥É¥á¥¤¥ó̾ (IDN) ·Á¼° (RFC 3490 ¤Î
745 .I "Internationalizing Domain Names in Applications (IDNA)"
746 ¤ò»²¾È¤Î¤³¤È) ¤ÈÊÑ´¹¤¹¤ë¤³¤È¤òÁªÂòŪ¤Ëǧ¤á¤ë¤è¤¦¤Ë³ÈÄ¥¤µ¤ì¤Æ¤¤¤ë¡£
747 4 ¤Ä¤Î¿·¤·¤¤¥Õ¥é¥°¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
748 .TP
749 .B AI_IDN
750 .\"O If this flag is specified, then the node name given in
751 .\"O .I node
752 .\"O is converted to IDN format if necessary.
753 .\"O The source encoding is that of the current locale.
754 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢
755 .I node
756 ¤ÇÍ¿¤¨¤é¤ì¤¿¥Î¡¼¥É̾¤ÏɬÍפ¬¤¢¤ì¤Ð IDN ·Á¼°¤ËÊÑ´¹¤µ¤ì¤ë¡£
757 ¥½¡¼¥¹Éä¹æ²½·Á¼°¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤Î¤â¤Î¤Ç¤¢¤ë¡£
758
759 .\"O If the input name contains non-ASCII characters, then the IDN encoding
760 .\"O is used.
761 .\"O Those parts of the node name (delimited by dots) that contain
762 .\"O non-ASCII characters are encoded using ASCII Compatible Encoding (ACE)
763 .\"O before being passed to the name resolution functions.
764 ÆþÎÏ̾¤ËÈó ASCII Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
765 IDN Éä¹æ²½·Á¼°¤¬»È¤ï¤ì¤ë¡£
766 Èó ASCII Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë(¥Ô¥ê¥ª¥É¤Ç¶èÀÚ¤é¤ì¤ë)Éôʬ¥Î¡¼¥É̾¤Ï¡¢
767 ̾Á°²ò·èµ¡Ç½¤ËÅϤµ¤ì¤ëÁ°¤Ë ASCII ¸ß´¹Éä¹æ²½·Á¼° (ACE) ¤ò»È¤Ã¤Æ
768 Éä¹æ²½¤µ¤ì¤ë¡£
769 .\" Implementation Detail:
770 .\" To minimize effects on system performance the implementation might
771 .\" want to check whether the input string contains any non-ASCII
772 .\" characters.  If there are none the IDN step can be skipped completely.
773 .\" On systems which allow not-ASCII safe encodings for a locale this
774 .\" might be a problem.
775 .TP
776 .B AI_CANONIDN
777 .\"O After a successful name lookup, and if the
778 .\"O .B AI_CANONNAME
779 .\"O flag was specified,
780 .\"O .BR getaddrinfo ()
781 .\"O will return the canonical name of the
782 .\"O node corresponding to the
783 .\"O .I addrinfo
784 .\"O structure value passed back.
785 .\"O The return value is an exact copy of the value returned by the name
786 .\"O resolution function.
787 .B AI_CANONNAME
788 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
789 .BR getaddrinfo ()
790 ¤Ï̾Á°¤Î¸¡º÷¤ËÀ®¸ù¤·¤¿¸å¡¢
791 ÊÖ¤µ¤ì¤¿
792 .I addrinfo
793 ¹½Â¤ÂΤËÂбþ¤¹¤ë¥Î¡¼¥É¤ÎÀµµ¬Ì¾¤òÊÖ¤¹¡£
794 ÊÖ¤êÃͤÏ̾Á°²ò·èµ¡Ç½¤«¤éÊÖ¤µ¤ì¤¿ÃͤÎÀµ³Î¤Ê¥³¥Ô¡¼¤Ç¤¢¤ë¡£
795
796 .\"O If the name is encoded using ACE, then it will contain the
797 .\"O .I xn\-\-
798 .\"O prefix for one or more components of the name.
799 .\"O To convert these components into a readable form the
800 .B AI_CANONIDN
801 .\"O flag can be passed in addition to
802 .\"O .BR AI_CANONNAME .
803 .\"O The resulting string is encoded using the current locale's encoding.
804 ̾Á°¤¬ ACE ¤ÇÉä¹æ²½¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢°ì¤Ä¤Þ¤¿¤ÏÊ£¿ô¤Î̾Á°¤Î¹½À®Í×ÁǤÎÀèƬ¤Ë
805 .I xn\-\-
806 ¤ò´Þ¤ó¤Ç¤¤¤ë¡£
807 ¤³¤ì¤é¤Î¹½À®Í×ÁǤòÆɤ߹þ¤ß²Äǽ¤Ê·Á¤ËÊÑ´¹¤¹¤ë¤¿¤á¤Ë¡¢
808 .B AI_CANONNAME
809 ¤È¶¦¤Ë
810 .B AI_CANONIDN
811 ¥Õ¥é¥°¤òÅϤ¹¤³¤È¤â½ÐÍè¤ë¡£
812 ÊÖ¤µ¤ì¤ëʸ»úÎó¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤ÎÉä¹æ²½·Á¼°¤ÇÉä¹æ²½¤µ¤ì¤Æ¤¤¤ë¡£
813 .\"
814 .\"Implementation Detail:
815 .\"If no component of the returned name starts with xn\-\- the IDN
816 .\"step can be skipped, therefore avoiding unnecessary slowdowns.
817 .TP
818 .BR AI_IDN_ALLOW_UNASSIGNED ", " AI_IDN_USE_STD3_ASCII_RULES
819 .\"O Setting these flags will enable the
820 .\"O IDNA_ALLOW_UNASSIGNED (allow unassigned Unicode code points) and
821 .\"O IDNA_USE_STD3_ASCII_RULES (check output to make sure it is a STD3
822 .\"O conforming hostname)
823 .\"O flags respectively to be used in the IDNA handling.
824 ¤³¤ì¤é¤Î¥Õ¥é¥°¤¬ÀßÄꤵ¤ì¤ë¤È¡¢
825 IDNA ¥Ï¥ó¥É¥ê¥ó¥°¤ò»È¤¦¤È¤­¤Ë¤½¤ì¤¾¤ì
826 IDNA_ALLOW_UNASSIGNED (Èó³ä¤êÅö¤Æ Unicode ¥³¡¼¥É¥Ý¥¤¥ó¥È¤òµö²Ä¤¹¤ë) ¤È
827 IDNA_USE_STD3_ASCII_RULES (½ÐÎϤ¬ STD3 ½àµò¥Û¥¹¥È̾¤Ç¤¢¤ë¤³¤È¤ò³Îǧ¤¹¤ë)
828 ¥Õ¥é¥°¤¬Í­¸ú¤Ë¤Ê¤ë¡£
829
830 .\"O .SH "RETURN VALUE"
831 .SH ÊÖ¤êÃÍ
832 .\" FIXME glibc defines the following additional errors, some which
833 .\" can probably be returned by getaddrinfo(); they need to
834 .\" be documented.
835 .\" #ifdef __USE_GNU
836 .\" #define EAI_INPROGRESS  -100  /* Processing request in progress.  */
837 .\" #define EAI_CANCELED    -101  /* Request canceled.  */
838 .\" #define EAI_NOTCANCELED -102  /* Request not canceled.  */
839 .\" #define EAI_ALLDONE     -103  /* All requests done.  */
840 .\" #define EAI_INTR        -104  /* Interrupted by a signal.  */
841 .\" #define EAI_IDN_ENCODE  -105  /* IDN encoding failed.  */
842 .\" #endif
843 .\"O .BR getaddrinfo ()
844 .\"O returns 0 if it succeeds, or one of the following nonzero error codes:
845 .BR getaddrinfo ()
846 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢¼ºÇÔ¤¹¤ë¤È°Ê²¼¤ÎÈó 0 ¤Î¥¨¥é¡¼¥³¡¼¥É¤Î¤¤¤º¤ì¤«¤òÊÖ¤¹¡£
847 .TP
848 .B EAI_ADDRFAMILY
849 .\" Not in SUSv3
850 .\"O The specified network host does not have any network addresses in the
851 .\"O requested address family.
852 »ØÄꤵ¤ì¤¿¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤Ë¤Ï¡¢
853 Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¤Ê¤¤¡£
854 .TP
855 .B EAI_AGAIN
856 .\"O The name server returned a temporary failure indication.
857 .\"O Try again later.
858 ¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤«¤é°ì»þŪ¤Ê¼ºÇÔ (temporary failure)
859 ¤ò°ÕÌ£¤¹¤ëÊÖ»ö¤¬ÊÖ¤µ¤ì¤¿¡£¸å¤Ç¤â¤¦°ìÅٻ¤Æ¤ß¤è¡£
860 .TP
861 .B EAI_BADFLAGS
862 .\"O .I hints.ai_flags
863 .\"O contains invalid flags; or,
864 .\"O .I hints.ai_flags
865 .\"O included
866 .\"O .B AI_CANONNAME
867 .\"O and
868 .\"O .I name
869 .\"O was NULL.
870 .I hints.ai_flags
871 ¤Î¥Õ¥é¥°¤ËÉÔÀµ¤Ê¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¡£¤Þ¤¿¤Ï¡¢
872 .I hints.ai_flags
873 ¤Ë
874 .B AI_CANONNAME
875 ¤¬´Þ¤Þ¤ì¤Æ¤¤¤Æ¡¢¤«¤Ä
876 .I name
877 ¤¬ NULL ¤Ç¤¢¤Ã¤¿¡£
878 .TP
879 .B EAI_FAIL
880 .\"O The name server returned a permanent failure indication.
881 ¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤«¤é¹±µ×Ū¤Ê¼ºÇÔ (permanent failure)
882 ¤ò°ÕÌ£¤¹¤ëÊÖ»ö¤¬ÊÖ¤µ¤ì¤¿¡£
883 .TP
884 .B EAI_FAMILY
885 .\"O The requested address family is not supported.
886 Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
887 .TP
888 .B EAI_MEMORY
889 .\"O Out of memory.
890 ¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
891 .TP
892 .B EAI_NODATA
893 .\" Not in SUSv3
894 .\"O The specified network host exists, but does not have any
895 .\"O network addresses defined.
896 »ØÄꤵ¤ì¤¿¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤Ï¸ºß¤¹¤ë¤¬¡¢
897 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¤Ò¤È¤Ä¤âÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
898 .TP
899 .B EAI_NONAME
900 .\"O The
901 .\"O .I node
902 .\"O or
903 .\"O .I service
904 .\"O is not known; or both
905 .\"O .I node
906 .\"O and
907 .\"O .I service
908 .\"O are NULL; or
909 .\"O .B AI_NUMERICSERV
910 .\"O was specified in
911 .\"O .I hints.ai_flags
912 .\"O and
913 .\"O .I service
914 .\"O was not a numeric port-number string.
915 .I node
916 ¤È
917 .I service
918 ¤Î¤É¤Á¤é¤«¤¬ÉÔÌÀ¡¢¤Þ¤¿¤Ï
919 .I node
920 ¤È
921 .I service
922 ¤ÎξÊý¤¬ NULL ¤À¤Ã¤¿¾ì¹ç¡¢¤Þ¤¿¤Ï
923 .B AI_NUMERICSERV
924 ¤¬
925 .I hints.ai_flags
926 ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
927 .I hints.ai_flags
928 ¤È
929 .I service
930 ¤¬¿ôÃͤΥݡ¼¥ÈÈÖ¹æ¤Îʸ»úÎó¤Ç¤Ê¤¤¡£
931 .TP
932 .B EAI_SERVICE
933 .\"O The requested service is not available for the requested socket type.
934 .\"O It may be available through another socket type.
935 Í׵ᤵ¤ì¤¿¥µ¡¼¥Ó¥¹¤Ï¡¢Í׵ᤵ¤ì¤¿¥½¥±¥Ã¥È¥¿¥¤¥×¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤¡£
936 ¾¤Î¥½¥±¥Ã¥È¥¿¥¤¥×¤Ç¤Ê¤éÍøÍѲÄǽ¤«¤â¤·¤ì¤Ê¤¤¡£
937 .\"O For example, this error could occur if
938 .\"O .I service
939 .\"O was "shell" (a service only available on stream sockets), and either
940 .\"O .I hints.ai_protocol
941 .\"O was
942 .\"O .BR IPPROTO_UDP ,
943 .\"O or
944 .\"O .I hints.ai_socktype
945 .\"O was
946 .\"O .BR SOCK_DGRAM ;
947 .\"O or the error could occur if
948 .\"O .I service
949 .\"O was not NULL, and
950 .\"O .I hints.ai_socktype
951 .\"O was
952 .\"O .BR SOCK_RAW
953 .\"O (a socket type that does not support the concept of services).
954 ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ëÎã¤È¤·¤Æ¤Ï¡¢
955 .I service
956 ¤¬ "shell" (¥¹¥È¥ê¡¼¥à¡¦¥½¥±¥Ã¥È¤Ç¤Î¤ßÍøÍѤǤ­¤ë¥µ¡¼¥Ó¥¹) ¤Ç¡¢
957 .I hints.ai_protocol
958 ¤Ë
959 .B IPPROTO_UDP
960 ¤¬»ØÄꤵ¤ì¤¿¤ê¡¢
961 .I hints.ai_socktype
962 ¤Ë
963 .B SOCK_DGRAM
964 ¤¬»ØÄꤵ¤ì¤¿¤ê¤·¤¿¾ì¹ç¤¬¤¢¤ë¡£
965 ¤Þ¤¿¡¢
966 .I service
967 ¤¬ NULL °Ê³°¤Ç¡¢
968 .I hints.ai_socktype
969 ¤Ë
970 .B SOCK_RAW
971 (¥µ¡¼¥Ó¥¹¤Î¹Í¤¨Êý¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥½¥±¥Ã¥È¼ïÊÌ)
972 ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤â¡¢¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¡£
973 .TP
974 .B EAI_SOCKTYPE
975 .\"O The requested socket type is not supported.
976 Í׵ᤵ¤ì¤¿¥½¥±¥Ã¥È¥¿¥¤¥×¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
977 .\"O This could occur, for example, if
978 .\"O .I hints.ai_socktype
979 .\"O and
980 .\"O .I hints.ai_protocol
981 .\"O are inconsistent (e.g.,
982 .\"O .BR SOCK_DGRAM
983 .\"O and
984 .\"O .BR IPPROTO_TCP ,
985 .\"O respectively).
986 ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ëÎã¤È¤·¤Æ¤Ï¡¢
987 .I hints.ai_socktype
988 ¤È
989 .I hints.ai_protocol
990 ¤¬Ì·½â¤·¤Æ¤¤¤ë¾ì¹ç (Î㤨¤Ð
991 .I hints.ai_socktype
992 ¤¬
993 .B SOCK_DGRAM
994 ¤Ç
995 .I hints.ai_protocol
996 ¤¬
997 .BR IPPROTO_TCP )
998 ¤¬¤¢¤ë¡£
999 .TP
1000 .B EAI_SYSTEM
1001 .\"O Other system error, check
1002 .\"O .I errno
1003 .\"O for details.
1004 ¤½¤Î¾¤Î¥·¥¹¥Æ¥à¥¨¥é¡¼¡£¾Ü¤·¤¯¤Ï
1005 .I errno
1006 ¤òÄ´¤Ù¤ë¤³¤È¡£
1007 .PP
1008 .\"O The
1009 .\"O .BR gai_strerror ()
1010 .\"O function translates these error codes to a human readable string,
1011 .\"O suitable for error reporting.
1012 .BR gai_strerror ()
1013 ´Ø¿ô¤òÍѤ¤¤ë¤È¡¢¤³¤ì¤é¤Î¥¨¥é¡¼¥³¡¼¥É¤ò¿Í´Ö¤Ë²ÄÆɤÊʸ»úÎó¤ËÊÑ´¹¤Ç¤­¤ë¤Î¤Ç¡¢
1014 ¥¨¥é¡¼Êó¹ð¤ËŬ¤¹¤ë¤À¤í¤¦¡£
1015 .\"O .SH "FILES"
1016 .SH ¥Õ¥¡¥¤¥ë
1017 .I /etc/gai.conf
1018 .\"O .SH "CONFORMING TO"
1019 .SH ½àµò
1020 .\"O POSIX.1-2001.
1021 .\"O The
1022 .\"O .BR getaddrinfo ()
1023 .\"O function is documented in RFC\ 2553.
1024 POSIX.1-2001.
1025 .BR getaddrinfo ()
1026 ´Ø¿ô¤Ï RFC 2553 ¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë¡£
1027 .\"O .SH "NOTES"
1028 .SH Ãí°Õ
1029 .\"O .BR getaddrinfo ()
1030 .\"O supports the
1031 .\"O .IB address % scope-id
1032 .\"O notation for specifying the IPv6 scope-ID.
1033 .BR getaddrinfo ()
1034 ¤Ï¡¢IPv6 scope-ID ¤ò»ØÄꤹ¤ë¤¿¤á¤Ë
1035 .IB address % scope-id
1036 µ­Ë¡¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
1037
1038 .\"O .BR AI_ADDRCONFIG ,
1039 .\"O .BR AI_ALL ,
1040 .\"O and
1041 .\"O .B AI_V4MAPPED
1042 .\"O are available since glibc 2.3.3.
1043 .\"O .B AI_NUMERICSERV
1044 .\"O is available since glibc 2.3.4.
1045 .BR AI_ADDRCONFIG ,
1046 .BR AI_ALL ,
1047 .B AI_V4MAPPED
1048 ¤Ï glibc 2.3.3 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
1049 .B AI_NUMERICSERV
1050 ¤Ï glibc 2.3.4 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
1051
1052 .\"O According to POSIX.1-2001, specifying
1053 .\"O .I hints
1054 .\"O as NULL should cause
1055 .\"O .I ai_flags
1056 .\"O to be assumed as 0.
1057 .\"O The GNU C library instead assumes a value of
1058 .\"O .BR "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)"
1059 .\"O for this case,
1060 .\"O since this value is considered an improvement on the specification.
1061 POSIX.1-2001 ¤Ë¤è¤ë¤È¡¢
1062 .I hints
1063 ¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
1064 .I ai_flags
1065 ¤ò 0 ¤È¤ß¤Ê¤¹¤Ù¤­¤È¤µ¤ì¤Æ¤¤¤ë¡£
1066 GNU C ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¡¢Âå¤ï¤ê¤Ë
1067 .I ai_flags
1068 ¤ò
1069 .BR "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)"
1070 ¤È¤ß¤Ê¤¹¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
1071 ¤³¤ÎÃͤÎÊý¤¬É¸½àµ¬³Ê¤Î²þÁ±¤Ë¤Ê¤ë¤È¹Í¤¨¤é¤ì¤Æ¤¤¤ë¤«¤é¤Ç¤¢¤ë¡£
1072 .\"O .SH EXAMPLE
1073 .SH Îã
1074 .\" getnameinfo.3 refers to this example
1075 .\" socket.2 refers to this example
1076 .\" bind.2 refers to this example
1077 .\" connect.2 refers to this example
1078 .\" recvfrom.2 refers to this example
1079 .\" sendto.2 refers to this example
1080 .\"O The following programs demonstrate the use of
1081 .\"O .BR getaddrinfo (),
1082 .\"O .BR gai_strerror (),
1083 .\"O .BR freeaddrinfo (),
1084 .\"O and
1085 .\"O .BR getnameinfo (3).
1086 .\"O The programs are an echo server and client for UDP datagrams.
1087 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢
1088 .BR getaddrinfo (),
1089 .BR gai_strerror (),
1090 .BR freeaddrinfo (),
1091 .BR getnameinfo (3)
1092 ¤Î»È¤¤Êý¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
1093 ¥×¥í¥°¥é¥à¤Ï UDP ¥Ç¡¼¥¿¥°¥é¥à¤Î echo ¥µ¡¼¥Ð¤È¥¯¥é¥¤¥¢¥ó¥È¤Ç¤¢¤ë¡£
1094 .\"O .SS Server program
1095 .SS ¥µ¡¼¥Ð¤Î¥×¥í¥°¥é¥à
1096 \&
1097 .nf
1098 #include <sys/types.h>
1099 #include <stdio.h>
1100 #include <stdlib.h>  
1101 #include <unistd.h>
1102 #include <string.h>
1103 #include <sys/socket.h>
1104 #include <netdb.h>
1105
1106 #define BUF_SIZE 500
1107
1108 int
1109 main(int argc, char *argv[])
1110 {
1111     struct addrinfo hints;
1112     struct addrinfo *result, *rp;
1113     int sfd, s;
1114     struct sockaddr_storage peer_addr;
1115     socklen_t peer_addr_len;
1116     ssize_t nread;
1117     char buf[BUF_SIZE];
1118
1119     if (argc != 2) {
1120         fprintf(stderr, "Usage: %s port\\n", argv[0]);
1121         exit(EXIT_FAILURE);
1122     }
1123
1124     memset(&hints, 0, sizeof(struct addrinfo));
1125     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
1126     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
1127     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
1128     hints.ai_protocol = 0;          /* Any protocol */
1129     hints.ai_canonname = NULL;
1130     hints.ai_addr = NULL;
1131     hints.ai_next = NULL;
1132
1133     s = getaddrinfo(NULL, argv[1], &hints, &result);
1134     if (s != 0) {
1135         fprintf(stderr, "getaddrinfo: %s\\n", gai_strerror(s));
1136         exit(EXIT_FAILURE);
1137     }
1138
1139     /* getaddrinfo() returns a list of address structures.
1140        Try each address until we successfully bind(2).
1141        If socket(2) (or bind(2)) fails, we (close the socket
1142        and) try the next address. */
1143
1144     for (rp = result; rp != NULL; rp = rp\->ai_next) {
1145         sfd = socket(rp\->ai_family, rp\->ai_socktype, 
1146                 rp\->ai_protocol);
1147         if (sfd == \-1)
1148             continue;
1149
1150         if (bind(sfd, rp\->ai_addr, rp\->ai_addrlen) == 0)
1151             break;                  /* Success */
1152
1153         close(sfd);
1154     }
1155
1156     if (rp == NULL) {               /* No address succeeded */
1157         fprintf(stderr, "Could not bind\\n");
1158         exit(EXIT_FAILURE);
1159     }
1160
1161     freeaddrinfo(result);           /* No longer needed */
1162
1163     /* Read datagrams and echo them back to sender */
1164
1165     for (;;) {
1166         peer_addr_len = sizeof(struct sockaddr_storage);
1167         nread = recvfrom(sfd, buf, BUF_SIZE, 0,
1168                 (struct sockaddr *) &peer_addr, &peer_addr_len);
1169         if (nread == \-1)
1170             continue;               /* Ignore failed request */
1171
1172         char host[NI_MAXHOST], service[NI_MAXSERV];
1173
1174         s = getnameinfo((struct sockaddr *) &peer_addr,
1175                         peer_addr_len, host, NI_MAXHOST,
1176                         service, NI_MAXSERV, NI_NUMERICSERV);
1177        if (s == 0)
1178             printf("Received %ld bytes from %s:%s\\n",
1179                     (long) nread, host, service);
1180         else
1181             fprintf(stderr, "getnameinfo: %s\\n", gai_strerror(s));
1182
1183         if (sendto(sfd, buf, nread, 0,
1184                     (struct sockaddr *) &peer_addr,
1185                     peer_addr_len) != nread)
1186             fprintf(stderr, "Error sending response\\n");
1187     }
1188 }
1189 .fi
1190 .\"O .SS Client program
1191 .SS ¥¯¥é¥¤¥¢¥ó¥È¤Î¥×¥í¥°¥é¥à
1192 \&
1193 .nf
1194 #include <sys/types.h>
1195 #include <sys/socket.h>
1196 #include <netdb.h>
1197 #include <stdio.h>
1198 #include <stdlib.h>
1199 #include <unistd.h>
1200 #include <string.h>
1201
1202 #define BUF_SIZE 500
1203
1204 int
1205 main(int argc, char *argv[])
1206 {
1207     struct addrinfo hints;
1208     struct addrinfo *result, *rp;
1209     int sfd, s, j;
1210     size_t len;
1211     ssize_t nread;
1212     char buf[BUF_SIZE];
1213
1214     if (argc < 3) {
1215         fprintf(stderr, "Usage: %s host port msg...\\n", argv[0]);
1216         exit(EXIT_FAILURE);
1217     }
1218
1219     /* Obtain address(es) matching host/port */
1220
1221     memset(&hints, 0, sizeof(struct addrinfo));
1222     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
1223     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
1224     hints.ai_flags = 0;
1225     hints.ai_protocol = 0;          /* Any protocol */
1226
1227     s = getaddrinfo(argv[1], argv[2], &hints, &result);
1228     if (s != 0) {
1229         fprintf(stderr, "getaddrinfo: %s\\n", gai_strerror(s));
1230         exit(EXIT_FAILURE);
1231     }
1232
1233     /* getaddrinfo() returns a list of address structures.
1234        Try each address until we successfully connect(2).
1235        If socket(2) (or connect(2)) fails, we (close the socket
1236        and) try the next address. */
1237
1238     for (rp = result; rp != NULL; rp = rp\->ai_next) {
1239         sfd = socket(rp\->ai_family, rp\->ai_socktype,
1240                      rp\->ai_protocol);
1241         if (sfd == \-1)
1242             continue;
1243
1244         if (connect(sfd, rp\->ai_addr, rp\->ai_addrlen) != \-1)
1245             break;                  /* Success */
1246
1247         close(sfd);
1248     }
1249
1250     if (rp == NULL) {               /* No address succeeded */
1251         fprintf(stderr, "Could not connect\\n");
1252         exit(EXIT_FAILURE);
1253     }
1254
1255     freeaddrinfo(result);           /* No longer needed */
1256
1257     /* Send remaining command\-line arguments as separate 
1258        datagrams, and read responses from server */
1259
1260     for (j = 3; j < argc; j++) {
1261         len = strlen(argv[j]) + 1;
1262                 /* +1 for terminating null byte */
1263
1264         if (len + 1 > BUF_SIZE) {
1265             fprintf(stderr,
1266                     "Ignoring long message in argument %d\\n", j);
1267             continue;
1268         }
1269
1270         if (write(sfd, argv[j], len) != len) {
1271             fprintf(stderr, "partial/failed write\\n");
1272             exit(EXIT_FAILURE);
1273         }
1274
1275         nread = read(sfd, buf, BUF_SIZE);
1276         if (nread == \-1) {
1277             perror("read");
1278             exit(EXIT_FAILURE);
1279         }
1280
1281         printf("Received %ld bytes: %s\\n", (long) nread, buf);
1282     }
1283
1284     exit(EXIT_SUCCESS);
1285 }
1286 .fi
1287 .\"O .SH "SEE ALSO"
1288 .SH ´ØÏ¢¹àÌÜ
1289 .\" .BR getipnodebyaddr (3),
1290 .\" .BR getipnodebyname (3)
1291 .BR getaddrinfo_a (3),
1292 .BR gethostbyname (3),
1293 .BR getnameinfo (3),
1294 .BR inet (3),
1295 .BR hostname (7),
1296 .BR ip (7)