OSDN Git Service

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