OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / release / 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 .SH Ì¾Á°
56 getaddrinfo, freeaddrinfo, gai_strerror \-
57 ¥Í¥Ã¥È¥ï¡¼¥¯¤Î¥¢¥É¥ì¥¹¤È¥µ¡¼¥Ó¥¹¤òÊÑ´¹¤¹¤ë
58 .SH ½ñ¼°
59 .nf
60 .B #include <sys/types.h>
61 .B #include <sys/socket.h>
62 .B #include <netdb.h>
63 .sp
64 .BI "int getaddrinfo(const char *" "node" ", const char *" "service" ,
65 .BI "                const struct addrinfo *" "hints" ,
66 .BI "                struct addrinfo **" "res" );
67 .sp
68 .BI "void freeaddrinfo(struct addrinfo *" "res" );
69 .sp
70 .BI "const char *gai_strerror(int " "errcode" );
71 .fi
72 .sp
73 .in -4n
74 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
75 .RB ( feature_test_macros (7)
76 »²¾È):
77 .ad l
78 .in
79 .sp
80 .BR getaddrinfo (),
81 .BR freeaddrinfo (),
82 .BR gai_strerror ():
83 .RS 4
84 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
85 .RE
86 .ad b
87 .SH ÀâÌÀ
88 .BR getaddrinfo ()
89 ¤Ï¡¢(¥¤¥ó¥¿¡¼¥Í¥Ã¥È¤Î¥Û¥¹¥È¤È¥µ¡¼¥Ó¥¹¤ò¼±Ê̤¹¤ë)
90 .I node
91 ¤È
92 .I service
93 ¤òÅϤ¹¤È¡¢°ì¤Ä°Ê¾å¤Î
94 .I addrinfo
95 ¹½Â¤ÂΤòÊÖ¤¹¡£¤½¤ì¤¾¤ì¤Î
96 .I addrinfo
97 ¹½Â¤ÂΤˤϡ¢
98 .BR bind (2)
99 ¤ä
100 .BR connect (2)
101 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë»ØÄê¤Ç¤­¤ë¥¤¥ó¥¿¡¼¥Í¥Ã¥È¥¢¥É¥ì¥¹¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë¡£
102 .BR getaddrinfo ()
103 ´Ø¿ô¤Ï¡¢
104 .\" .BR getipnodebyname (3),
105 .\" .BR getipnodebyaddr (3),
106 .BR getservbyname (3)
107 ¤È
108 .BR getservbyport (3)
109 ¤Îµ¡Ç½¤ò¤Þ¤È¤á¤Æ°ì¤Ä¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¤·¤¿¤â¤Î¤Ç¤¢¤ë¤¬¡¢
110 ¤³¤ì¤é¤Î´Ø¿ô¤È°ã¤¤¡¢
111 .BR getaddrinfo ()
112 ¤Ï¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤¢¤ê¡¢
113 .BR getaddrinfo ()
114 ¤ò»È¤¦¤³¤È¤Ç¥×¥í¥°¥é¥à¤Ï IPv4 ¤È IPv6 ¤Î°ã¤¤¤Ë´Ø¤¹¤ë°Í¸´Ø·¸¤ò
115 ¤Ê¤¯¤¹¤³¤È¤¬¤Ç¤­¤ë¡£
116 .PP
117 .BR getaddrinfo ()
118 ¤¬ÍѤ¤¤ë
119 .I addrinfo
120 ¹½Â¤ÂΤϰʲ¼¤Î¥Õ¥£¡¼¥ë¥É¤ò´Þ¤à¡£
121 .sp
122 .in +4n
123 .nf
124 struct addrinfo {
125     int              ai_flags;
126     int              ai_family;
127     int              ai_socktype;
128     int              ai_protocol;
129     size_t           ai_addrlen;
130     struct sockaddr *ai_addr;
131     char            *ai_canonname;
132     struct addrinfo *ai_next;
133 };
134 .fi
135 .in
136 .PP
137 .I hints
138 °ú¤­¿ô¤Ï
139 .I addrinfo
140 ¹½Â¤ÂΤò»Ø¤·¼¨¤·¡¢¤³¤Î¹½Â¤ÂΤòÍѤ¤¤Æ
141 .I res
142 ¤¬»Ø¤¹¥ê¥¹¥È¤ËÆþ¤ì¤ÆÊÖ¤¹¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¹½Â¤ÂΤòÁªÂò¤¹¤ë¤¿¤á¤Î´ð½à¤ò»ØÄꤹ¤ë¡£
143 .I hints
144 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
145 .I hints
146 ¤Ï
147 .I addrinfo
148 ¹½Â¤ÂΤò»Ø¤·¼¨¤·¡¢¤½¤Î¹½Â¤ÂΤΥե£¡¼¥ë¥É
149 .IR ai_family ,
150 .IR ai_socktype ,
151 .I ai_protocol
152 ¤Ç
153 .BR getaddrinfo ()
154 ¤¬ÊÖ¤¹¥½¥±¥Ã¥È¥¢¥É¥ì¥¹½¸¹ç¤ËÂФ¹¤ë´ð½à¤ò»ØÄꤹ¤ë¡£
155 .TP 12
156 .I ai_family
157 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÏÊÖ¤µ¤ì¤ë¥¢¥É¥ì¥¹¤Î´õ˾¤Î¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ò»ØÄꤹ¤ë¡£
158 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë»ØÄê¤Ç¤­¤ëÍ­¸ú¤ÊÃͤȤ·¤Æ¤Ï
159 .B AF_INET
160 ¤È
161 .B AF_INET6
162 ¤¬¤¢¤ë¡£
163 ¤Þ¤¿¡¢ÃÍ
164 .B AF_UNSPEC
165 ¤ò»ØÄꤹ¤ë¤È¡¢
166 .BR getaddrinfo ()
167 ¤Ï
168 .I node
169 ¤È
170 .I service
171 ¤Ç»ÈÍѤǤ­¤ë¤¤¤º¤ì¤«¤Î¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼ (Î㤨¤Ð IPv4 ¤« IPv6) ¤Î
172 ¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤òÊÖ¤¹¤³¤È¤òµá¤á¤é¤ì¤ë¡£
173 .TP
174 .I ai_socktype
175 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¿ä¾©¤Î¥½¥±¥Ã¥È·¿ (Î㤨¤Ð
176 .B SOCK_STREAM
177 ¤ä
178 .BR SOCK_DGRAM )
179 ¤ò»ØÄꤹ¤ë¡£
180 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤ò»ØÄꤹ¤ë¤È¡¢Ç¤°Õ¤Î¥½¥±¥Ã¥È·¿¤Î¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ò
181 .BR getaddrinfo ()
182 ¤¬ÊÖ¤·¤Æ¤è¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
183 .TP
184 .I ai_protocol
185 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤ÏÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Î¥×¥í¥È¥³¥ë¤ò»ØÄꤹ¤ë¡£
186 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ë 0 ¤ò»ØÄꤹ¤ë¤È¡¢Ç¤°Õ¤Î¥×¥í¥È¥³¥ë¤Î¤Î¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ò
187 .BR getaddrinfo ()
188 ¤¬ÊÖ¤·¤Æ¤è¤¤¤³¤È¤ò°ÕÌ£¤¹¤ë¡£
189 .TP
190 .I ai_flags
191 ¤³¤Î¥Õ¥£¡¼¥ë¥É¤Ï¡¢ÄɲäΥª¥×¥·¥ç¥ó (²¼µ­) ¤ò»ØÄꤹ¤ë¡£
192 Ê£¿ô¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ëºÝ¤Ë¤Ï¡¢¤½¤ì¤é¤Î¥Ó¥Ã¥Èñ°Ì¤Î OR ¤ò¤È¤Ã¤Æ»ØÄꤹ¤ë¡£
193 .PP
194 .I hints
195 ¤¬»Ø¤·¼¨¤¹¹½Â¤ÂΤξ¤Î¤¹¤Ù¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤Ë¤Ï
196 0 ¤« NULL ¥Ý¥¤¥ó¥¿¤òŬÀÚ¤ËÆþ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
197 .I hints
198 ¤Ë NULL ¤ò»ØÄꤹ¤ë¤Î¤Ï¡¢
199 .I ai_socktype
200 ¤È
201 .I ai_protocol
202 ¤Ë 0 ¤ò¡¢
203 .I ai_family
204 ¤Ë
205 .B AF_UNSPEC
206 ¤ò¡¢
207 .I ai_flags
208 ¤Ë
209 .B "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)"
210 ¤òÀßÄꤹ¤ë¤Î¤ÈÅù²Á¤Ç¤¢¤ë¡£
211
212 .I node
213 ¤Ë¤Ï¡¢¿ôÃÍ·Á¼°¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹
214 (IPv4 ¤Î¾ì¹ç¤Ï
215 .BR inet_aton (3)
216 ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»ú¤Ë¤è¤ëɽµ­¡¢
217 IPv6 ¤Î¾ì¹ç¤Ï
218 .BR inet_pton (3)
219 ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë 16 ¿Ê¿ô¤Îʸ»úÎó·Á¼°) ¤â¤·¤¯¤Ï
220 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È̾¤ò»ØÄꤹ¤ë¡£
221 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È̾¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤Ï¡¢¤½¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¸¡º÷¤µ¤ì¡¢
222 ̾Á°²ò·è¤¬¹Ô¤Ê¤ï¤ì¤ë¡£
223 .I hints.ai_flags
224 ¤Ë
225 .B AI_NUMERICHOST
226 ¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢
227 .I node
228 ¤Ï¿ôÃÍ·Á¼°¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
229 .B AI_NUMERICHOST
230 ¥Õ¥é¥°¤ò»È¤¦¤È¡¢»þ´Ö¤Î³Ý¤«¤ë²ÄǽÀ­¤Î¤¢¤ë¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¥¢¥É¥ì¥¹¤Î¸¡º÷¤Ï
231 ¤¹¤Ù¤ÆÍÞÀ©¤µ¤ì¤ë¡£
232 .PP
233 .IR hints.ai_flags
234 ¤Ë
235 .B AI_PASSIVE
236 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¡¢¤«¤Ä
237 .I node
238 ¤¬ NULL ¤Î¾ì¹ç¡¢
239 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ï
240 ¥³¥Í¥¯¥·¥ç¥ó¤ò
241 .BR accept (2)
242 ¤¹¤ë¤¿¤á¤Î¥½¥±¥Ã¥È¤ò
243 .BR bind (2)
244 ¤¹¤ë¤Î¤ËŬ¤·¤¿¤â¤Î¤È¤Ê¤ë¡£
245 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ë¤Ï¡Ö¥ï¥¤¥ë¥É¥«¡¼¥É¡¦¥¢¥É¥ì¥¹¡×
246 (IPv4 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
247 .BR INADDR_ANY ¡¢
248 IPv6 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
249 .BR IN6ADDR_ANY_INIT )
250 ¤¬Æþ¤ë¡£
251 ¥ï¥¤¥ë¥É¥«¡¼¥É¡¦¥¢¥É¥ì¥¹¤Ï¡¢Ç¤°Õ¤Î¥Û¥¹¥È¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤ÇÀܳ¤ò
252 ¼õ¤±ÉÕ¤±¤è¤¦¤È¤¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó (Ä̾ï¤Ï¥µ¡¼¥Ð¡¼) ¤ÇÍѤ¤¤é¤ì¤ë¡£
253 .I node
254 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
255 .B AI_PASSIVE
256 ¥Õ¥é¥°¤Ï̵»ë¤µ¤ì¤ë¡£
257 .PP
258 .I hints.ai_flags
259 ¤Ë
260 .B AI_PASSIVE
261 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
262 ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ï
263 .BR connect (2),
264 .BR sendto (2),
265 .BR sendmsg (2)
266 ¤Ç¤Î»ÈÍѤËŬ¤·¤¿¤â¤Î¤È¤Ê¤ë¡£
267 .I node
268 ¤¬ NULL ¤Î¾ì¹ç¡¢¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤Ë¤Ï¥ë¡¼¥×¥Ð¥Ã¥¯¡¦¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Î
269 ¥¢¥É¥ì¥¹ (IPv4 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
270 .BR INADDR_LOOPBACK
271 IPv6 ¥¢¥É¥ì¥¹¤Î¾ì¹ç¤Ï
272 .BR IN6ADDR_LOOPBACK_INIT ) ¤¬ÀßÄꤵ¤ì¤ë¡£
273 ¤³¤ì¤ÏƱ¤¸¥Û¥¹¥È¾å¤ÇÆ°ºî¤·¤Æ¤¤¤ëÀܳÁê¼ê¤ÈÄÌ¿®¤¹¤ë¤è¤¦¤Ê
274 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÇÍѤ¤¤é¤ì¤ë¡£
275 .PP
276 .I service
277 ¤Ë¤è¤ê¡¢ÊÖ¤µ¤ì¤ë³Æ¥¢¥É¥ì¥¹¹½Â¤ÂΤΥݡ¼¥ÈÈֹ椬·è¤Þ¤ë¡£
278 ¤³¤Î°ú¤­¿ô¤¬¥µ¡¼¥Ó¥¹Ì¾
279 .RB ( services (5)
280 »²¾È) ¤Î¾ì¹ç¡¢Âбþ¤¹¤ë¥Ý¡¼¥ÈÈÖ¹æ¤ËËÝÌõ¤µ¤ì¤ë¡£
281 ¤³¤Î°ú¤­¿ô¤Ë¤Ï 10 ¿Ê¿ô¤â»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¡¢
282 ¤³¤Î¾ì¹ç¤Ë¤Ï¥Ð¥¤¥Ê¥ê¤Ø¤ÎÊÑ´¹¤À¤±¤¬¹Ô¤ï¤ì¤ë¡£
283 .I service
284 ¤¬ NULL ¤Î¾ì¹ç¡¢ÊÖ¤µ¤ì¤ë¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Î¥Ý¡¼¥ÈÈÖ¹æ¤Ï
285 ½é´ü²½¤µ¤ì¤Ê¤¤¤Þ¤Þ¤È¤Ê¤ë¡£
286 .I hints.ai_flags
287 ¤Ë
288 .B AI_NUMERICSERV
289 ¤¬»ØÄꤵ¤ì¡¢¤«¤Ä
290 .I service
291 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¡¢
292 .I service
293 ¤Ï¿ôÃͤΥݡ¼¥ÈÈÖ¹æ¤ò´Þ¤àʸ»úÎó¤ò»Ø¤·¼¨¤µ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
294 ¤³¤Î¥Õ¥é¥°¤Ï¡¢Ì¾Á°²ò·è¥µ¡¼¥Ó¥¹¤¬ÉÔÍפǤ¢¤ë¤³¤È¤¬Ê¬¤«¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¡¢
295 ¥µ¡¼¥Ó¥¹¤Îµ¯Æ°¤òÍÞÀ©¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
296 .PP
297 .I node
298 ¤È
299 .I service
300 ¤Î¤É¤Á¤é¤«¤Ï NULL ¤Ë¤·¤Æ¤è¤¤¤¬¡¢Î¾ÊýƱ»þ¤Ë NULL ¤Ë¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
301 .PP
302 .BR getaddrinfo ()
303 ´Ø¿ô¤Ï¡¢
304 .I addrinfo
305 ¹½Â¤ÂΤΥá¥â¥ê³ÎÊݤò¹Ô¤¤¡¢
306 .I addrinfo
307 ¹½Â¤ÂΤΥê¥ó¥¯¥ê¥¹¥È¤ò½é´ü²½¤·¡¢
308 .I res
309 ¤Ë¥ê¥¹¥È¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÆþ¤ì¤ÆÊÖ¤¹¡£
310 ¤³¤Î¤È¤­¡¢³Æ¹½Â¤ÂΤΥͥåȥ¥¯¥¢¥É¥ì¥¹¤Ï
311 .I node
312 ¤È
313 .I service
314 ¤Ë°ìÃפ·¡¢
315 .I hints
316 ¤Ç²Ý¤µ¤ì¤¿¤¹¤Ù¤Æ¤ÎÀ©¸Â¤òËþ¤¿¤¹¤â¤Î¤È¤Ê¤ë¡£
317 ¥ê¥ó¥¯¥ê¥¹¥È¤ÎÍ×ÁǤÏ
318 .I ai_next
319 ¥Õ¥£¡¼¥ë¥É¤Ë¤è¤êÏ¢·ë¤µ¤ì¤ë¡£
320
321 ¥ê¥ó¥¯¥ê¥¹¥È¤Î
322 .I addrinfo
323 ¹½Â¤ÂΤÏÊ£¿ô¸Ä¤Ë¤Ê¤ë¤³¤È¤â¤¢¤ê¡¢¤½¤ÎÍýͳ¤Ï¤¤¤¯¤Ä¤«¤¢¤ë¡£
324 ¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤¬¥Þ¥ë¥Á¥Û¡¼¥à¤Ç¤¢¤ë¡¢
325 Ê£¿ô¤Î¥×¥í¥È¥³¥ë¤Ç¥¢¥¯¥»¥¹¤Ç¤­¤ë (Î㤨¤Ð
326 .B AF_INET
327 ¤È
328 .B AF_INET6
329 ¤ÎξÊý) ¡¢
330 Ê£¿ô¤Î¥½¥±¥Ã¥È¼ïÊ̤ÇƱ¤¸¥µ¡¼¥Ó¥¹¤¬ÍøÍѤǤ­¤ë
331 (Î㤨¤Ð¡¢¤Ò¤È¤Ä¤¬
332 .B SOCK_STREM
333 ¥¢¥É¥ì¥¹¤Ç¡¢¤â¤¦¤Ò¤È¤Ä¤¬
334 .B SOCK_DGRAM
335 ¥¢¥É¥ì¥¹¤Ç¤¢¤ë)¡¢¤¬¤¢¤ë¡£
336 Ä̾ï¤Ï¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÏÊÖ¤µ¤ì¤¿½ç½ø¤Ç¥¢¥É¥ì¥¹¤ò»î¤¹¤Ù¤­¤Ç¤¢¤ë¡£
337 .BR getaddrinfo ()
338 ¤ÎÃæ¤Ç»ÈÍѤµ¤ì¤ëʤÙÂؤ¨´Ø¿ô¤Ï RFC\ 3484 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
339 Æüì¤Ê¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
340 .I /etc/gai.conf
341 ¤òÊÔ½¸¤¹¤ë¤³¤È¤Ç¡¢¤³¤Î½ç½ø¤òÈùÄ´À°¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë
342 .RI ( /etc/gai.conf
343 ¤Ï glibc 2.5 °Ê¹ß¤ÇÍøÍѤǤ­¤ë)¡£
344 .PP
345 .I hints.ai_flags
346 ¤Ë
347 .B AI_CANONNAME
348 ¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢ÊÖ¤µ¤ì¤ë¥ê¥¹¥È¤ÎºÇ½é¤Î
349 .I addrinfo
350 ¹½Â¤ÂΤÎ
351 .I ai_canonname
352 ¥Õ¥£¡¼¥ë¥É¤Ï¥Û¥¹¥È¤Î¸ø¼°¤Ê̾Á°¤ò»Ø¤¹¤è¤¦¤ËÀßÄꤵ¤ì¤ë¡£
353 .\" In glibc prior to 2.3.4, the ai_canonname of each addrinfo
354 .\" structure was set pointing to the canonical name; that was
355 .\" more than POSIX.1-2001 specified, or other implementations provided.
356 .\" MTK, Aug 05
357
358 ÊÖ¤µ¤ì¤ë³Æ¡¹¤Î
359 .I addrinfo
360 ¹½Â¤ÂΤλĤê¤Î¥Õ¥£¡¼¥ë¥É¤Ï°Ê²¼¤Î¤è¤¦¤Ë½é´ü²½¤µ¤ì¤ë¡£
361 .IP * 2
362 .IR ai_family ,
363 .IR ai_socktype ,
364 .I ai_protocol
365 ¥Õ¥£¡¼¥ë¥É¤Ï¥½¥±¥Ã¥ÈÀ¸À®¥Ñ¥é¥á¡¼¥¿¤òÊÖ¤¹
366 (¤³¤ì¤é¤Î¥Õ¥£¡¼¥ë¥É¤Î°ÕÌ£¤Ï
367 .BR socket (2)
368 ¤ÎƱ¤¸Ì¾Á°¤Î°ú¤­¿ô¤ÈƱ¤¸¤Ç¤¢¤ë)¡£
369 Î㤨¤Ð¡¢
370 .I ai_family
371 ¤Ï
372 .B AF_INET
373 ¤ä
374 .B AF_INET6
375 ¤òÊÖ¤·¡¢
376 .I ai_socktype
377 ¤Ï
378 .B SOCK_DGRAM
379 ¤ä
380 .BR SOCK_STREAM
381 ¤òÊÖ¤·¡¢
382 .I ai_protocol
383 ¤Ï¤½¤Î¥½¥±¥Ã¥È¤Î¥×¥í¥È¥³¥ë¤òÊÖ¤¹¡£
384 .IP *
385 .I ai_addr
386 ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬½ñ¤­¹þ¤Þ¤ì¡¢
387 .I ai_addrlen
388 ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï¥½¥±¥Ã¥È¥¢¥É¥ì¥¹¤ÎŤµ¤¬¥Ð¥¤¥Èñ°Ì¤Ç½ñ¤­¹þ¤Þ¤ì¤ë¡£
389 .PP
390 .I hints.ai_flags
391 ¤¬
392 .B AI_ADDRCONFIG
393 ¤ò´Þ¤à¾ì¹ç¡¢
394 .I res
395 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï¡¢
396 ¥í¡¼¥«¥ë¥·¥¹¥Æ¥à¤ËºÇÄã°ì¤Ä¤Î IPv4 ¥¢¥É¥ì¥¹¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï
397 IPv4 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¡¢
398 ¥í¡¼¥«¥ë¥·¥¹¥Æ¥à¤ËºÇÄã°ì¤Ä¤Î IPv6 ¥¢¥É¥ì¥¹¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï
399 IPv6 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¤ë¡£
400 .PP
401 .I hint.ai_flags
402 ¤Ë
403 .B AI_V4MAPPED
404 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
405 .I hints.ai_family
406 ¤Ë
407 .B AF_INET6
408 ¤¬»ØÄꤵ¤ì¡¢
409 ¥Þ¥Ã¥Á¤¹¤ë IPv6 ¥¢¥É¥ì¥¹¤¬¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
410 .I res
411 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï IPv4-mapped IPv6 ¥¢¥É¥ì¥¹¤¬ÊÖ¤µ¤ì¤ë¡£
412 .I hints.ai_flags
413 ¤Ë
414 .B AI_V4MAPPED
415 ¤È
416 .B AI_ALL
417 ¤ÎξÊý¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
418 .I res
419 ¤¬»Ø¤¹¥ê¥¹¥È¤Ë¤Ï IPv6 ¥¢¥É¥ì¥¹¤È IPv4-mapped IPv6 ¥¢¥É¥ì¥¹¤Î
420 ξÊý¤¬ÊÖ¤µ¤ì¤ë¡£
421 .B AI_V4MAPPED
422 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
423 .B AI_ALL
424 ¤Ï̵»ë¤µ¤ì¤ë¡£
425 .PP
426 .BR freeaddrinfo ()
427 ´Ø¿ô¤Ï¡¢
428 ¥ê¥ó¥¯¥ê¥¹¥È
429 .I res
430 ¤ËÂФ·¤ÆưŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë¡£
431 .SS "¹ñºÝ²½¥É¥á¥¤¥ó̾¤Î¤¿¤á¤Î getaddrinfo() ¤Î³ÈÄ¥"
432 .PP
433 glibc 2.3.4 ¤«¤é¡¢
434 .BR getaddrinfo ()
435 ¤ÏÆþ½ÐÎϤ¹¤ë¥Û¥¹¥È̾¤òÆ©²áŪ¤Ë¹ñºÝ²½¥É¥á¥¤¥ó̾ (IDN) ·Á¼° (RFC 3490 ¤Î
436 .I "Internationalizing Domain Names in Applications (IDNA)"
437 ¤ò»²¾È¤Î¤³¤È) ¤ÈÊÑ´¹¤¹¤ë¤³¤È¤òÁªÂòŪ¤Ëǧ¤á¤ë¤è¤¦¤Ë³ÈÄ¥¤µ¤ì¤Æ¤¤¤ë¡£
438 4 ¤Ä¤Î¿·¤·¤¤¥Õ¥é¥°¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
439 .TP
440 .B AI_IDN
441 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢
442 .I node
443 ¤ÇÍ¿¤¨¤é¤ì¤¿¥Î¡¼¥É̾¤ÏɬÍפ¬¤¢¤ì¤Ð IDN ·Á¼°¤ËÊÑ´¹¤µ¤ì¤ë¡£
444 ¥½¡¼¥¹Éä¹æ²½·Á¼°¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤Î¤â¤Î¤Ç¤¢¤ë¡£
445
446 ÆþÎÏ̾¤ËÈó ASCII Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
447 IDN Éä¹æ²½·Á¼°¤¬»È¤ï¤ì¤ë¡£
448 Èó ASCII Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë(¥Ô¥ê¥ª¥É¤Ç¶èÀÚ¤é¤ì¤ë)Éôʬ¥Î¡¼¥É̾¤Ï¡¢
449 ̾Á°²ò·èµ¡Ç½¤ËÅϤµ¤ì¤ëÁ°¤Ë ASCII ¸ß´¹Éä¹æ²½·Á¼° (ACE) ¤ò»È¤Ã¤Æ
450 Éä¹æ²½¤µ¤ì¤ë¡£
451 .\" Implementation Detail:
452 .\" To minimize effects on system performance the implementation might
453 .\" want to check whether the input string contains any non-ASCII
454 .\" characters.  If there are none the IDN step can be skipped completely.
455 .\" On systems which allow not-ASCII safe encodings for a locale this
456 .\" might be a problem.
457 .TP
458 .B AI_CANONIDN
459 .B AI_CANONNAME
460 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
461 .BR getaddrinfo ()
462 ¤Ï̾Á°¤Î¸¡º÷¤ËÀ®¸ù¤·¤¿¸å¡¢
463 ÊÖ¤µ¤ì¤¿
464 .I addrinfo
465 ¹½Â¤ÂΤËÂбþ¤¹¤ë¥Î¡¼¥É¤ÎÀµµ¬Ì¾¤òÊÖ¤¹¡£
466 ÊÖ¤êÃͤÏ̾Á°²ò·èµ¡Ç½¤«¤éÊÖ¤µ¤ì¤¿ÃͤÎÀµ³Î¤Ê¥³¥Ô¡¼¤Ç¤¢¤ë¡£
467
468 .B AI_CANONIDN
469 ̾Á°¤¬ ACE ¤ÇÉä¹æ²½¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢°ì¤Ä¤Þ¤¿¤ÏÊ£¿ô¤Î̾Á°¤Î¹½À®Í×ÁǤÎÀèƬ¤Ë
470 .I xn\-\-
471 ¤ò´Þ¤ó¤Ç¤¤¤ë¡£
472 ¤³¤ì¤é¤Î¹½À®Í×ÁǤòÆɤ߹þ¤ß²Äǽ¤Ê·Á¤ËÊÑ´¹¤¹¤ë¤¿¤á¤Ë¡¢
473 .B AI_CANONNAME
474 ¤È¶¦¤Ë
475 .B AI_CANONIDN
476 ¥Õ¥é¥°¤òÅϤ¹¤³¤È¤â½ÐÍè¤ë¡£
477 ÊÖ¤µ¤ì¤ëʸ»úÎó¤Ï¸½ºß¤Î¥í¥±¡¼¥ë¤ÎÉä¹æ²½·Á¼°¤ÇÉä¹æ²½¤µ¤ì¤Æ¤¤¤ë¡£
478 .\"
479 .\"Implementation Detail:
480 .\"If no component of the returned name starts with xn\-\- the IDN
481 .\"step can be skipped, therefore avoiding unnecessary slowdowns.
482 .TP
483 .BR AI_IDN_ALLOW_UNASSIGNED ", " AI_IDN_USE_STD3_ASCII_RULES
484 ¤³¤ì¤é¤Î¥Õ¥é¥°¤¬ÀßÄꤵ¤ì¤ë¤È¡¢
485 IDNA ¥Ï¥ó¥É¥ê¥ó¥°¤ò»È¤¦¤È¤­¤Ë¤½¤ì¤¾¤ì
486 IDNA_ALLOW_UNASSIGNED (Èó³ä¤êÅö¤Æ Unicode ¥³¡¼¥É¥Ý¥¤¥ó¥È¤òµö²Ä¤¹¤ë) ¤È
487 IDNA_USE_STD3_ASCII_RULES (½ÐÎϤ¬ STD3 ½àµò¥Û¥¹¥È̾¤Ç¤¢¤ë¤³¤È¤ò³Îǧ¤¹¤ë)
488 ¥Õ¥é¥°¤¬Í­¸ú¤Ë¤Ê¤ë¡£
489
490 .SH ÊÖ¤êÃÍ
491 .\" FIXME glibc defines the following additional errors, some which
492 .\" can probably be returned by getaddrinfo(); they need to
493 .\" be documented.
494 .\" #ifdef __USE_GNU
495 .\" #define EAI_INPROGRESS  -100  /* Processing request in progress.  */
496 .\" #define EAI_CANCELED    -101  /* Request canceled.  */
497 .\" #define EAI_NOTCANCELED -102  /* Request not canceled.  */
498 .\" #define EAI_ALLDONE     -103  /* All requests done.  */
499 .\" #define EAI_INTR        -104  /* Interrupted by a signal.  */
500 .\" #define EAI_IDN_ENCODE  -105  /* IDN encoding failed.  */
501 .\" #endif
502 .BR getaddrinfo ()
503 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢¼ºÇÔ¤¹¤ë¤È°Ê²¼¤ÎÈó 0 ¤Î¥¨¥é¡¼¥³¡¼¥É¤Î¤¤¤º¤ì¤«¤òÊÖ¤¹¡£
504 .TP
505 .B EAI_ADDRFAMILY
506 .\" Not in SUSv3
507 »ØÄꤵ¤ì¤¿¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤Ë¤Ï¡¢
508 Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¤Ê¤¤¡£
509 .TP
510 .B EAI_AGAIN
511 ¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤«¤é°ì»þŪ¤Ê¼ºÇÔ (temporary failure)
512 ¤ò°ÕÌ£¤¹¤ëÊÖ»ö¤¬ÊÖ¤µ¤ì¤¿¡£¸å¤Ç¤â¤¦°ìÅٻ¤Æ¤ß¤è¡£
513 .TP
514 .B EAI_BADFLAGS
515 .I hints.ai_flags
516 ¤Î¥Õ¥é¥°¤ËÉÔÀµ¤Ê¥Õ¥é¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¡£¤Þ¤¿¤Ï¡¢
517 .I hints.ai_flags
518 ¤Ë
519 .B AI_CANONNAME
520 ¤¬´Þ¤Þ¤ì¤Æ¤¤¤Æ¡¢¤«¤Ä
521 .I name
522 ¤¬ NULL ¤Ç¤¢¤Ã¤¿¡£
523 .TP
524 .B EAI_FAIL
525 ¥Í¡¼¥à¥µ¡¼¥Ð¡¼¤«¤é¹±µ×Ū¤Ê¼ºÇÔ (permanent failure)
526 ¤ò°ÕÌ£¤¹¤ëÊÖ»ö¤¬ÊÖ¤µ¤ì¤¿¡£
527 .TP
528 .B EAI_FAMILY
529 Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
530 .TP
531 .B EAI_MEMORY
532 ¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
533 .TP
534 .B EAI_NODATA
535 .\" Not in SUSv3
536 »ØÄꤵ¤ì¤¿¥Í¥Ã¥È¥ï¡¼¥¯¥Û¥¹¥È¤Ï¸ºß¤¹¤ë¤¬¡¢
537 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬¤Ò¤È¤Ä¤âÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
538 .TP
539 .B EAI_NONAME
540 .I node
541 ¤È
542 .I service
543 ¤Î¤É¤Á¤é¤«¤¬ÉÔÌÀ¡¢¤Þ¤¿¤Ï
544 .I node
545 ¤È
546 .I service
547 ¤ÎξÊý¤¬ NULL ¤À¤Ã¤¿¾ì¹ç¡¢¤Þ¤¿¤Ï
548 .B AI_NUMERICSERV
549 ¤¬
550 .I hints.ai_flags
551 ¤Ë»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢
552 .I hints.ai_flags
553 ¤È
554 .I service
555 ¤¬¿ôÃͤΥݡ¼¥ÈÈÖ¹æ¤Îʸ»úÎó¤Ç¤Ê¤¤¡£
556 .TP
557 .B EAI_SERVICE
558 Í׵ᤵ¤ì¤¿¥µ¡¼¥Ó¥¹¤Ï¡¢Í׵ᤵ¤ì¤¿¥½¥±¥Ã¥È¥¿¥¤¥×¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤¡£
559 ¾¤Î¥½¥±¥Ã¥È¥¿¥¤¥×¤Ç¤Ê¤éÍøÍѲÄǽ¤«¤â¤·¤ì¤Ê¤¤¡£
560 ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ëÎã¤È¤·¤Æ¤Ï¡¢
561 .I service
562 ¤¬ "shell" (¥¹¥È¥ê¡¼¥à¡¦¥½¥±¥Ã¥È¤Ç¤Î¤ßÍøÍѤǤ­¤ë¥µ¡¼¥Ó¥¹) ¤Ç¡¢
563 .I hints.ai_protocol
564 ¤Ë
565 .B IPPROTO_UDP
566 ¤¬»ØÄꤵ¤ì¤¿¤ê¡¢
567 .I hints.ai_socktype
568 ¤Ë
569 .B SOCK_DGRAM
570 ¤¬»ØÄꤵ¤ì¤¿¤ê¤·¤¿¾ì¹ç¤¬¤¢¤ë¡£
571 ¤Þ¤¿¡¢
572 .I service
573 ¤¬ NULL °Ê³°¤Ç¡¢
574 .I hints.ai_socktype
575 ¤Ë
576 .B SOCK_RAW
577 (¥µ¡¼¥Ó¥¹¤Î¹Í¤¨Êý¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥½¥±¥Ã¥È¼ïÊÌ)
578 ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤â¡¢¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¡£
579 .TP
580 .B EAI_SOCKTYPE
581 Í׵ᤵ¤ì¤¿¥½¥±¥Ã¥È¥¿¥¤¥×¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
582 ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ëÎã¤È¤·¤Æ¤Ï¡¢
583 .I hints.ai_socktype
584 ¤È
585 .I hints.ai_protocol
586 ¤¬Ì·½â¤·¤Æ¤¤¤ë¾ì¹ç (Î㤨¤Ð
587 .I hints.ai_socktype
588 ¤¬
589 .B SOCK_DGRAM
590 ¤Ç
591 .I hints.ai_protocol
592 ¤¬
593 .BR IPPROTO_TCP )
594 ¤¬¤¢¤ë¡£
595 .TP
596 .B EAI_SYSTEM
597 ¤½¤Î¾¤Î¥·¥¹¥Æ¥à¥¨¥é¡¼¡£¾Ü¤·¤¯¤Ï
598 .I errno
599 ¤òÄ´¤Ù¤ë¤³¤È¡£
600 .PP
601 .BR gai_strerror ()
602 ´Ø¿ô¤òÍѤ¤¤ë¤È¡¢¤³¤ì¤é¤Î¥¨¥é¡¼¥³¡¼¥É¤ò¿Í´Ö¤Ë²ÄÆɤÊʸ»úÎó¤ËÊÑ´¹¤Ç¤­¤ë¤Î¤Ç¡¢
603 ¥¨¥é¡¼Êó¹ð¤ËŬ¤¹¤ë¤À¤í¤¦¡£
604 .SH ¥Õ¥¡¥¤¥ë
605 .I /etc/gai.conf
606 .SH ½àµò
607 POSIX.1-2001.
608 .BR getaddrinfo ()
609 ´Ø¿ô¤Ï RFC 2553 ¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë¡£
610 .SH Ãí°Õ
611 .BR getaddrinfo ()
612 ¤Ï¡¢IPv6 scope-ID ¤ò»ØÄꤹ¤ë¤¿¤á¤Ë
613 .IB address % scope-id
614 µ­Ë¡¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¡£
615
616 .BR AI_ADDRCONFIG ,
617 .BR AI_ALL ,
618 .B AI_V4MAPPED
619 ¤Ï glibc 2.3.3 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
620 .B AI_NUMERICSERV
621 ¤Ï glibc 2.3.4 °Ê¹ß¤ÇÍøÍѲÄǽ¤Ç¤¢¤ë¡£
622
623 POSIX.1-2001 ¤Ë¤è¤ë¤È¡¢
624 .I hints
625 ¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
626 .I ai_flags
627 ¤ò 0 ¤È¤ß¤Ê¤¹¤Ù¤­¤È¤µ¤ì¤Æ¤¤¤ë¡£
628 GNU C ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¡¢Âå¤ï¤ê¤Ë
629 .I ai_flags
630 ¤ò
631 .BR "(AI_V4MAPPED\ |\ AI_ADDRCONFIG)"
632 ¤È¤ß¤Ê¤¹¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
633 ¤³¤ÎÃͤÎÊý¤¬É¸½àµ¬³Ê¤Î²þÁ±¤Ë¤Ê¤ë¤È¹Í¤¨¤é¤ì¤Æ¤¤¤ë¤«¤é¤Ç¤¢¤ë¡£
634 .SH Îã
635 .\" getnameinfo.3 refers to this example
636 .\" socket.2 refers to this example
637 .\" bind.2 refers to this example
638 .\" connect.2 refers to this example
639 .\" recvfrom.2 refers to this example
640 .\" sendto.2 refers to this example
641 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢
642 .BR getaddrinfo (),
643 .BR gai_strerror (),
644 .BR freeaddrinfo (),
645 .BR getnameinfo (3)
646 ¤Î»È¤¤Êý¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
647 ¥×¥í¥°¥é¥à¤Ï UDP ¥Ç¡¼¥¿¥°¥é¥à¤Î echo ¥µ¡¼¥Ð¤È¥¯¥é¥¤¥¢¥ó¥È¤Ç¤¢¤ë¡£
648 .SS ¥µ¡¼¥Ð¤Î¥×¥í¥°¥é¥à
649 \&
650 .nf
651 #include <sys/types.h>
652 #include <stdio.h>
653 #include <stdlib.h>  
654 #include <unistd.h>
655 #include <string.h>
656 #include <sys/socket.h>
657 #include <netdb.h>
658
659 #define BUF_SIZE 500
660
661 int
662 main(int argc, char *argv[])
663 {
664     struct addrinfo hints;
665     struct addrinfo *result, *rp;
666     int sfd, s;
667     struct sockaddr_storage peer_addr;
668     socklen_t peer_addr_len;
669     ssize_t nread;
670     char buf[BUF_SIZE];
671
672     if (argc != 2) {
673         fprintf(stderr, "Usage: %s port\\n", argv[0]);
674         exit(EXIT_FAILURE);
675     }
676
677     memset(&hints, 0, sizeof(struct addrinfo));
678     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
679     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
680     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
681     hints.ai_protocol = 0;          /* Any protocol */
682     hints.ai_canonname = NULL;
683     hints.ai_addr = NULL;
684     hints.ai_next = NULL;
685
686     s = getaddrinfo(NULL, argv[1], &hints, &result);
687     if (s != 0) {
688         fprintf(stderr, "getaddrinfo: %s\\n", gai_strerror(s));
689         exit(EXIT_FAILURE);
690     }
691
692     /* getaddrinfo() returns a list of address structures.
693        Try each address until we successfully bind(2).
694        If socket(2) (or bind(2)) fails, we (close the socket
695        and) try the next address. */
696
697     for (rp = result; rp != NULL; rp = rp\->ai_next) {
698         sfd = socket(rp\->ai_family, rp\->ai_socktype, 
699                 rp\->ai_protocol);
700         if (sfd == \-1)
701             continue;
702
703         if (bind(sfd, rp\->ai_addr, rp\->ai_addrlen) == 0)
704             break;                  /* Success */
705
706         close(sfd);
707     }
708
709     if (rp == NULL) {               /* No address succeeded */
710         fprintf(stderr, "Could not bind\\n");
711         exit(EXIT_FAILURE);
712     }
713
714     freeaddrinfo(result);           /* No longer needed */
715
716     /* Read datagrams and echo them back to sender */
717
718     for (;;) {
719         peer_addr_len = sizeof(struct sockaddr_storage);
720         nread = recvfrom(sfd, buf, BUF_SIZE, 0,
721                 (struct sockaddr *) &peer_addr, &peer_addr_len);
722         if (nread == \-1)
723             continue;               /* Ignore failed request */
724
725         char host[NI_MAXHOST], service[NI_MAXSERV];
726
727         s = getnameinfo((struct sockaddr *) &peer_addr,
728                         peer_addr_len, host, NI_MAXHOST,
729                         service, NI_MAXSERV, NI_NUMERICSERV);
730        if (s == 0)
731             printf("Received %ld bytes from %s:%s\\n",
732                     (long) nread, host, service);
733         else
734             fprintf(stderr, "getnameinfo: %s\\n", gai_strerror(s));
735
736         if (sendto(sfd, buf, nread, 0,
737                     (struct sockaddr *) &peer_addr,
738                     peer_addr_len) != nread)
739             fprintf(stderr, "Error sending response\\n");
740     }
741 }
742 .fi
743 .SS ¥¯¥é¥¤¥¢¥ó¥È¤Î¥×¥í¥°¥é¥à
744 \&
745 .nf
746 #include <sys/types.h>
747 #include <sys/socket.h>
748 #include <netdb.h>
749 #include <stdio.h>
750 #include <stdlib.h>
751 #include <unistd.h>
752 #include <string.h>
753
754 #define BUF_SIZE 500
755
756 int
757 main(int argc, char *argv[])
758 {
759     struct addrinfo hints;
760     struct addrinfo *result, *rp;
761     int sfd, s, j;
762     size_t len;
763     ssize_t nread;
764     char buf[BUF_SIZE];
765
766     if (argc < 3) {
767         fprintf(stderr, "Usage: %s host port msg...\\n", argv[0]);
768         exit(EXIT_FAILURE);
769     }
770
771     /* Obtain address(es) matching host/port */
772
773     memset(&hints, 0, sizeof(struct addrinfo));
774     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
775     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
776     hints.ai_flags = 0;
777     hints.ai_protocol = 0;          /* Any protocol */
778
779     s = getaddrinfo(argv[1], argv[2], &hints, &result);
780     if (s != 0) {
781         fprintf(stderr, "getaddrinfo: %s\\n", gai_strerror(s));
782         exit(EXIT_FAILURE);
783     }
784
785     /* getaddrinfo() returns a list of address structures.
786        Try each address until we successfully connect(2).
787        If socket(2) (or connect(2)) fails, we (close the socket
788        and) try the next address. */
789
790     for (rp = result; rp != NULL; rp = rp\->ai_next) {
791         sfd = socket(rp\->ai_family, rp\->ai_socktype,
792                      rp\->ai_protocol);
793         if (sfd == \-1)
794             continue;
795
796         if (connect(sfd, rp\->ai_addr, rp\->ai_addrlen) != \-1)
797             break;                  /* Success */
798
799         close(sfd);
800     }
801
802     if (rp == NULL) {               /* No address succeeded */
803         fprintf(stderr, "Could not connect\\n");
804         exit(EXIT_FAILURE);
805     }
806
807     freeaddrinfo(result);           /* No longer needed */
808
809     /* Send remaining command\-line arguments as separate 
810        datagrams, and read responses from server */
811
812     for (j = 3; j < argc; j++) {
813         len = strlen(argv[j]) + 1;
814                 /* +1 for terminating null byte */
815
816         if (len + 1 > BUF_SIZE) {
817             fprintf(stderr,
818                     "Ignoring long message in argument %d\\n", j);
819             continue;
820         }
821
822         if (write(sfd, argv[j], len) != len) {
823             fprintf(stderr, "partial/failed write\\n");
824             exit(EXIT_FAILURE);
825         }
826
827         nread = read(sfd, buf, BUF_SIZE);
828         if (nread == \-1) {
829             perror("read");
830             exit(EXIT_FAILURE);
831         }
832
833         printf("Received %ld bytes: %s\\n", (long) nread, buf);
834     }
835
836     exit(EXIT_SUCCESS);
837 }
838 .fi
839 .SH ´ØÏ¢¹àÌÜ
840 .\" .BR getipnodebyaddr (3),
841 .\" .BR getipnodebyname (3)
842 .BR getaddrinfo_a (3),
843 .BR gethostbyname (3),
844 .BR getnameinfo (3),
845 .BR inet (3),
846 .BR hostname (7),
847 .BR ip (7)