OSDN Git Service

(split) LDP: Translation snapshots for ja.po.
[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)