OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / man3 / inet.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
26 .\"
27 .\" References consulted:
28 .\"     Linux libc source code
29 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30 .\"     386BSD man pages
31 .\"     libc.info (from glibc distribution)
32 .\" Modified Sat Jul 24 19:12:00 1993 by Rik Faith <faith@cs.unc.edu>
33 .\" Modified Sun Sep  3 20:29:36 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
34 .\" Changed network into host byte order (for inet_network),
35 .\"     Andreas Jaeger <aj@arthur.rhein-neckar.de>, 980130.
36 .\" 2008-06-19, mtk
37 .\"     Describe the various address forms supported by inet_aton().
38 .\"     Clarify discussion of inet_lnaof(), inet_netof(), and inet_makeaddr().
39 .\"     Add discussion of Classful Addressing, noting that it is obsolete.
40 .\"     Added an EXAMPLE program.
41 .\"
42 .\"*******************************************************************
43 .\"
44 .\" This file was generated with po4a. Translate the source file.
45 .\"
46 .\"*******************************************************************
47 .\"
48 .\" Japanese Version Copyright (c) 1998 Ueyama Rui
49 .\"         all rights reserved.
50 .\" Translated 1998-05-23, Ueyama Rui <rui@linux.or.jp>
51 .\" Updated & Modefied 1999-02-26, Shouichi Saito
52 .\" Updated 1999-12-26, Kentaro Shirakata <argrath@ub32.org>
53 .\" Updated 2005-10-04, Kentaro Shirakata <argrath@ub32.org>
54 .\" Updated 2007-05-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.46
55 .\" Updated 2008-08-13, Akihiro MOTOKI, LDP v3.05
56 .\"
57 .TH INET 3 2013\-02\-10 GNU "Linux Programmer's Manual"
58 .SH 名前
59 inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof,
60 inet_netof \- インターネットアドレス操作ルーチン
61 .SH 書式
62 .nf
63 \fB#include <sys/socket.h>\fP
64 \fB#include <netinet/in.h>\fP
65 \fB#include <arpa/inet.h>\fP
66 .sp
67 \fBint inet_aton(const char *\fP\fIcp\fP\fB, struct in_addr *\fP\fIinp\fP\fB);\fP
68 .sp
69 \fBin_addr_t inet_addr(const char *\fP\fIcp\fP\fB);\fP
70 .sp
71 \fBin_addr_t inet_network(const char *\fP\fIcp\fP\fB);\fP
72 .sp
73 \fBchar *inet_ntoa(struct in_addr \fP\fIin\fP\fB);\fP
74 .sp
75 \fBstruct in_addr inet_makeaddr(int \fP\fInet\fP\fB, int \fP\fIhost\fP\fB);\fP
76 .sp
77 \fBin_addr_t inet_lnaof(struct in_addr \fP\fIin\fP\fB);\fP
78 .sp
79 \fBin_addr_t inet_netof(struct in_addr \fP\fIin\fP\fB);\fP
80 .fi
81 .sp
82 .in -4n
83 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
84 .in
85 .sp
86 \fBinet_aton\fP(), \fBinet_ntoa\fP(): _BSD_SOURCE || _SVID_SOURCE
87 .SH 説明
88 \fBinet_aton\fP()  は、インターネットホストのアドレス \fIcp\fP を、 IPv4 の数値とドットによる表記から
89 (ネットワークバイトオーダの) バイナリ値へ 変換し、変換結果を \fIinp\fP が指している構造体に格納する。 アドレスが有効な場合 0
90 以外を返し、そうでない場合は 0 を返す。 \fIcp\fP で渡すアドレスとして、以下の形式を用いることができる。
91 .TP  10
92 \fIa.b.c.d\fP
93 4 つの数字のそれぞれはアドレスの各バイトを示す。 これらのバイトは左から右の順序でバイナリアドレスに割り当てられる。
94 .TP 
95 \fIa.b.c\fP
96 \fIa\fP と \fIb\fP はバイナリアドレスの最初の 2 バイトを示す。 \fIc\fP は 16 ビット値と解釈され、バイナリアドレスの右側の 2
97 バイトを表す。 この表記は、(過去のものとなった) クラス B ネットワークアドレスを 指定するのに適している。
98 .TP 
99 \fIa.b\fP
100 \fIa\fP はバイナリアドレスの最初のバイトを示す。 \fIb\fP は 24 ビット値と解釈され、バイナリアドレスの右側の 3 バイトを表す。
101 この表記は、(過去のものとなった) クラス C ネットワークアドレスを 指定するのに適している。
102 .TP 
103 \fIa\fP
104 値 \fIa\fP は 32 ビット値と解釈され、バイトの再配置は行われず、 そのままバイナリアドレスとして格納される。
105 .PP
106 上記の全ての形式で、ドット区切りのアドレスの各要素は、10 進数、 8 進数 (先頭に \fI0\fP を付ける)、 16 進数 (先頭に \fI0X\fP
107 を付ける) で指定できる。 これらの形式のアドレスをまとめて \fIIPv4 の数値とドットによる表記 (IPv4 numbers\-and\-dots
108 notation)\fP と呼ぶ。 また、10 進数 4 つだけを使った形式を \fIIPv4 のドット区切りの 10 進数表記 (IPv4
109 dotted\-decimal notation)\fP と呼ぶ (\fIIPv4 のドット区切り 4 分割表記 (IPv4 dotted\-decimal
110 notation)\fP と呼ぶこともある)。
111 .PP
112 \fBinet_addr\fP()  関数は、インターネットホストのアドレス \fIcp\fP を、 IPv4
113 の数値とドットによる表記からネットワークバイトオーダでの バイナリ値へ変換して返す。 入力が不正な場合、 \fBINADDR_NONE\fP (普通は \-1)
114 を返す。 \-1 は有効なアドレス (255.255.255.255) なので、この関数を使うと 問題になるかもしれない。
115 この関数を使うのは避け、代わりに \fBinet_aton\fP(), \fBinet_pton\fP(3), \fBgetaddrinfo\fP(3)
116 を使うのがよい。 これらの関数の方が、エラーの通知がよりきれいな方法で行われる。
117 .PP
118 \fBinet_network\fP()  関数は、 IPv4 の数値とドットによる表記の文字列 \fIcp\fP を、 インターネットアドレスとしての使用に適した
119 ホストバイトオーダの数値に変換する。 成功すると、変換されたアドレスを返す。 入力が不正な場合は \-1 を返す。
120 .PP
121 \fBinet_ntoa\fP()  関数は、ネットワークバイトオーダで渡されたインターネットホストアドレス \fIin\fP を、 IPv4 のドット区切りの
122 10 進数表記の文字列に変換する。 文字列は静的に割当てられたバッファに格納されて返されるので、 この後でこの関数を再度呼び出すと文字列は上書きされる。
123 .PP
124 \fBinet_lnaof\fP()  関数は、インターネットアドレス \fIin\fP のローカルネットワーク部分を返す。 この返り値はホストバイトオーダである。
125 .PP
126 \fBinet_netof\fP()  関数は、インターネットアドレス \fIin\fP のネットワーク部分を返す。 この返り値はホストバイトオーダである。
127 .PP
128 \fBinet_makeaddr\fP()  関数は \fBinet_netof\fP()  と \fBinet_lnaof\fP()  の逆の機能を持つ。
129 ネットワーク番号 \fInet\fP と、ローカルアドレス \fIhost\fP を 組み合わせて生成した、インターネットホストアドレスを
130 ネットワークバイトオーダで返す。 \fIhost\fP, \fInet\fP はともにホストバイトオーダである。
131 .PP
132 \fBinet_ntoa\fP(), \fBinet_makeaddr\fP(), \fBinet_lnaof\fP(), \fBinet_netof\fP()
133 で使用する構造体 \fIin_addr\fP は \fI<netinet/in.h>\fP で次のように定義されている:
134 .sp
135 .in +4n
136 .nf
137 typedef uint32_t in_addr_t;
138
139 struct in_addr {
140     in_addr_t s_addr;
141 };
142 .fi
143 .in
144 .SH 準拠
145 4.3BSD.  \fBinet_addr\fP(), \fBinet_ntoa\fP()  は POSIX.1\-2001 で規定されている。
146 \fBinet_aton\fP()  は POSIX.1\-2001 で規定されていないが、ほとんどのシステムで利用可能である。
147 .SH 注意
148 i386 ではホストバイトオーダは Least Significant Byte (LSB) first (リトルエンディアン) だが、
149 インターネットで使われるネットワークバイトオーダは Most Significant Byte (MSB) first (ビッグエンディアン)
150 である点に注意すること。
151
152 \fBinet_lnaof\fP(), \fBinet_netof\fP(), \fBinet_makeaddr\fP()  は過去の名残であり、渡されたアドレスが
153 \fIクラスフル・ネットワークアドレス (classful network addresses)\fP であると仮定して処理を行う。
154 クラスフル・ネットワークアドレスでは、以下にあるように、 IPv4 ネットワークアドレスをバイト境界でネットワーク部とホスト部に分割する。
155 .TP  10
156 Class A
157 (ネットワークバイトオーダの) アドレスの最上位ビットが 0 の場合、 このアドレス種別となる。このアドレス種別では、
158 最上位バイトがネットワークアドレスを表し、 残りの 3 バイトがホストアドレスを表す。
159 .TP 
160 Class B
161 (ネットワークバイトオーダの) アドレスの上位側 2 ビットがバイナリ値で 10 の場合、このアドレス種別となる。このアドレス種別では、 上位 2
162 バイトがネットワークアドレスを表し、 残りの 2 バイトがホストアドレスを表す。
163 .TP 
164 Class C
165 (ネットワークバイトオーダの) アドレスの上位側 3 ビットがバイナリ値で 110 の場合、このアドレス種別となる。このアドレス種別では、 上位 3
166 バイトがネットワークアドレスを表し、 残りの 1 バイトがホストアドレスを表す。
167 .PP
168 クラスフル・ネットワークアドレスは現在では廃止され、 クラスレス・ドメイン間ルーチン (CIDR) に取って代わられた。 CIDR
169 では、アドレスを任意のビット境界 (バイト境界ではない) で ネットワーク部とホスト部に分割する。
170 .SH 例
171 以下は \fBinet_aton\fP()  と \fBinet_ntoa\fP()  の使用例である。このように実行する。
172 .in +4n
173 .nf
174
175 $\fB ./a.out 226.000.000.037\fP      # Last byte is in octal
176 226.0.0.31
177 $\fB ./a.out 0x7f.1         \fP      # First byte is in hex
178 127.0.0.1
179 .fi
180 .in
181 .SS プログラムのソース
182 \&
183 .nf
184 #define _BSD_SOURCE
185 #include <arpa/inet.h>
186 #include <stdio.h>
187 #include <stdlib.h>
188
189 int
190 main(int argc, char *argv[])
191 {
192     struct in_addr addr;
193
194     if (argc != 2) {
195         fprintf(stderr, "%s <dotted\-address>\en", argv[0]);
196         exit(EXIT_FAILURE);
197     }
198
199     if (inet_aton(argv[1], &addr) == 0) {
200         fprintf(stderr, "Invalid address\en");
201         exit(EXIT_FAILURE);
202     }
203
204     printf("%s\en", inet_ntoa(addr));
205     exit(EXIT_SUCCESS);
206 }
207 .fi
208 .SH 関連項目
209 \fBbyteorder\fP(3), \fBgetaddrinfo\fP(3), \fBgethostbyname\fP(3), \fBgetnameinfo\fP(3),
210 \fBgetnetent\fP(3), \fBinet_ntop\fP(3), \fBinet_pton\fP(3), \fBhosts\fP(5),
211 \fBnetworks\fP(5)
212 .SH この文書について
213 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
214 である。プロジェクトの説明とバグ報告に関する情報は
215 http://www.kernel.org/doc/man\-pages/ に書かれている。