OSDN Git Service

c3b2625a4d8c2a86cfb8126e0e0b14be7b7d5d3c
[linuxjm/LDP_man-pages.git] / release / 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 .TH INET 3 2013\-02\-10 GNU "Linux Programmer's Manual"
48 .SH 名前
49 inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof,
50 inet_netof \- インターネットアドレス操作ルーチン
51 .SH 書式
52 .nf
53 \fB#include <sys/socket.h>\fP
54 \fB#include <netinet/in.h>\fP
55 \fB#include <arpa/inet.h>\fP
56 .sp
57 \fBint inet_aton(const char *\fP\fIcp\fP\fB, struct in_addr *\fP\fIinp\fP\fB);\fP
58 .sp
59 \fBin_addr_t inet_addr(const char *\fP\fIcp\fP\fB);\fP
60 .sp
61 \fBin_addr_t inet_network(const char *\fP\fIcp\fP\fB);\fP
62 .sp
63 \fBchar *inet_ntoa(struct in_addr \fP\fIin\fP\fB);\fP
64 .sp
65 \fBstruct in_addr inet_makeaddr(int \fP\fInet\fP\fB, int \fP\fIhost\fP\fB);\fP
66 .sp
67 \fBin_addr_t inet_lnaof(struct in_addr \fP\fIin\fP\fB);\fP
68 .sp
69 \fBin_addr_t inet_netof(struct in_addr \fP\fIin\fP\fB);\fP
70 .fi
71 .sp
72 .in -4n
73 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
74 .in
75 .sp
76 \fBinet_aton\fP(), \fBinet_ntoa\fP(): _BSD_SOURCE || _SVID_SOURCE
77 .SH 説明
78 \fBinet_aton\fP()  は、インターネットホストのアドレス \fIcp\fP を、 IPv4 の数値とドットによる表記から
79 (ネットワークバイトオーダの) バイナリ値へ 変換し、変換結果を \fIinp\fP が指している構造体に格納する。 アドレスが有効な場合 0
80 以外を返し、そうでない場合は 0 を返す。 \fIcp\fP で渡すアドレスとして、以下の形式を用いることができる。
81 .TP  10
82 \fIa.b.c.d\fP
83 4 つの数字のそれぞれはアドレスの各バイトを示す。 これらのバイトは左から右の順序でバイナリアドレスに割り当てられる。
84 .TP 
85 \fIa.b.c\fP
86 \fIa\fP と \fIb\fP はバイナリアドレスの最初の 2 バイトを示す。 \fIc\fP は 16 ビット値と解釈され、バイナリアドレスの右側の 2
87 バイトを表す。 この表記は、(過去のものとなった) クラス B ネットワークアドレスを 指定するのに適している。
88 .TP 
89 \fIa.b\fP
90 \fIa\fP はバイナリアドレスの最初のバイトを示す。 \fIb\fP は 24 ビット値と解釈され、バイナリアドレスの右側の 3 バイトを表す。
91 この表記は、(過去のものとなった) クラス C ネットワークアドレスを 指定するのに適している。
92 .TP 
93 \fIa\fP
94 値 \fIa\fP は 32 ビット値と解釈され、バイトの再配置は行われず、 そのままバイナリアドレスとして格納される。
95 .PP
96 上記の全ての形式で、ドット区切りのアドレスの各要素は、10 進数、 8 進数 (先頭に \fI0\fP を付ける)、 16 進数 (先頭に \fI0X\fP
97 を付ける) で指定できる。 これらの形式のアドレスをまとめて \fIIPv4 の数値とドットによる表記 (IPv4 numbers\-and\-dots
98 notation)\fP と呼ぶ。 また、10 進数 4 つだけを使った形式を \fIIPv4 のドット区切りの 10 進数表記 (IPv4
99 dotted\-decimal notation)\fP と呼ぶ (\fIIPv4 のドット区切り 4 分割表記 (IPv4 dotted\-decimal
100 notation)\fP と呼ぶこともある)。
101 .PP
102 \fBinet_addr\fP()  関数は、インターネットホストのアドレス \fIcp\fP を、 IPv4
103 の数値とドットによる表記からネットワークバイトオーダでの バイナリ値へ変換して返す。 入力が不正な場合、 \fBINADDR_NONE\fP (普通は \-1)
104 を返す。 \-1 は有効なアドレス (255.255.255.255) なので、この関数を使うと 問題になるかもしれない。
105 この関数を使うのは避け、代わりに \fBinet_aton\fP(), \fBinet_pton\fP(3), \fBgetaddrinfo\fP(3)
106 を使うのがよい。 これらの関数の方が、エラーの通知がよりきれいな方法で行われる。
107 .PP
108 \fBinet_network\fP()  関数は、 IPv4 の数値とドットによる表記の文字列 \fIcp\fP を、 インターネットアドレスとしての使用に適した
109 ホストバイトオーダの数値に変換する。 成功すると、変換されたアドレスを返す。 入力が不正な場合は \-1 を返す。
110 .PP
111 \fBinet_ntoa\fP()  関数は、ネットワークバイトオーダで渡されたインターネットホストアドレス \fIin\fP を、 IPv4 のドット区切りの
112 10 進数表記の文字列に変換する。 文字列は静的に割当てられたバッファに格納されて返されるので、 この後でこの関数を再度呼び出すと文字列は上書きされる。
113 .PP
114 \fBinet_lnaof\fP()  関数は、インターネットアドレス \fIin\fP のローカルネットワーク部分を返す。 この返り値はホストバイトオーダである。
115 .PP
116 \fBinet_netof\fP()  関数は、インターネットアドレス \fIin\fP のネットワーク部分を返す。 この返り値はホストバイトオーダである。
117 .PP
118 \fBinet_makeaddr\fP()  関数は \fBinet_netof\fP()  と \fBinet_lnaof\fP()  の逆の機能を持つ。
119 ネットワーク番号 \fInet\fP と、ローカルアドレス \fIhost\fP を 組み合わせて生成した、インターネットホストアドレスを
120 ネットワークバイトオーダで返す。 \fIhost\fP, \fInet\fP はともにホストバイトオーダである。
121 .PP
122 \fBinet_ntoa\fP(), \fBinet_makeaddr\fP(), \fBinet_lnaof\fP(), \fBinet_netof\fP()
123 で使用する構造体 \fIin_addr\fP は \fI<netinet/in.h>\fP で次のように定義されている:
124 .sp
125 .in +4n
126 .nf
127 typedef uint32_t in_addr_t;
128
129 struct in_addr {
130     in_addr_t s_addr;
131 };
132 .fi
133 .in
134 .SH 準拠
135 4.3BSD.  \fBinet_addr\fP(), \fBinet_ntoa\fP()  は POSIX.1\-2001 で規定されている。
136 \fBinet_aton\fP()  は POSIX.1\-2001 で規定されていないが、ほとんどのシステムで利用可能である。
137 .SH 注意
138 i386 ではホストバイトオーダは Least Significant Byte (LSB) first (リトルエンディアン) だが、
139 インターネットで使われるネットワークバイトオーダは Most Significant Byte (MSB) first (ビッグエンディアン)
140 である点に注意すること。
141
142 \fBinet_lnaof\fP(), \fBinet_netof\fP(), \fBinet_makeaddr\fP()  は過去の名残であり、渡されたアドレスが
143 \fIクラスフル・ネットワークアドレス (classful network addresses)\fP であると仮定して処理を行う。
144 クラスフル・ネットワークアドレスでは、以下にあるように、 IPv4 ネットワークアドレスをバイト境界でネットワーク部とホスト部に分割する。
145 .TP  10
146 Class A
147 (ネットワークバイトオーダの) アドレスの最上位ビットが 0 の場合、 このアドレス種別となる。このアドレス種別では、
148 最上位バイトがネットワークアドレスを表し、 残りの 3 バイトがホストアドレスを表す。
149 .TP 
150 Class B
151 (ネットワークバイトオーダの) アドレスの上位側 2 ビットがバイナリ値で 10 の場合、このアドレス種別となる。このアドレス種別では、 上位 2
152 バイトがネットワークアドレスを表し、 残りの 2 バイトがホストアドレスを表す。
153 .TP 
154 Class C
155 (ネットワークバイトオーダの) アドレスの上位側 3 ビットがバイナリ値で 110 の場合、このアドレス種別となる。このアドレス種別では、 上位 3
156 バイトがネットワークアドレスを表し、 残りの 1 バイトがホストアドレスを表す。
157 .PP
158 クラスフル・ネットワークアドレスは現在では廃止され、 クラスレス・ドメイン間ルーチン (CIDR) に取って代わられた。 CIDR
159 では、アドレスを任意のビット境界 (バイト境界ではない) で ネットワーク部とホスト部に分割する。
160 .SH 例
161 以下は \fBinet_aton\fP()  と \fBinet_ntoa\fP()  の使用例である。このように実行する。
162 .in +4n
163 .nf
164
165 $\fB ./a.out 226.000.000.037\fP      # Last byte is in octal
166 226.0.0.31
167 $\fB ./a.out 0x7f.1         \fP      # First byte is in hex
168 127.0.0.1
169 .fi
170 .in
171 .SS プログラムのソース
172 \&
173 .nf
174 #define _BSD_SOURCE
175 #include <arpa/inet.h>
176 #include <stdio.h>
177 #include <stdlib.h>
178
179 int
180 main(int argc, char *argv[])
181 {
182     struct in_addr addr;
183
184     if (argc != 2) {
185         fprintf(stderr, "%s <dotted\-address>\en", argv[0]);
186         exit(EXIT_FAILURE);
187     }
188
189     if (inet_aton(argv[1], &addr) == 0) {
190         fprintf(stderr, "Invalid address\en");
191         exit(EXIT_FAILURE);
192     }
193
194     printf("%s\en", inet_ntoa(addr));
195     exit(EXIT_SUCCESS);
196 }
197 .fi
198 .SH 関連項目
199 \fBbyteorder\fP(3), \fBgetaddrinfo\fP(3), \fBgethostbyname\fP(3), \fBgetnameinfo\fP(3),
200 \fBgetnetent\fP(3), \fBinet_ntop\fP(3), \fBinet_pton\fP(3), \fBhosts\fP(5),
201 \fBnetworks\fP(5)
202 .SH この文書について
203 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
204 である。プロジェクトの説明とバグ報告に関する情報は
205 http://www.kernel.org/doc/man\-pages/ に書かれている。