1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
5 .\" <mtk.manpages@gmail.com>
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" References consulted:
28 .\" Linux libc source code
29 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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.
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.
42 .\" Japanese Version Copyright (c) 1998 Ueyama Rui
43 .\" all rights reserved.
44 .\" Translated 1998-05-23, Ueyama Rui <rui@linux.or.jp>
45 .\" Updated & Modefied 1999-02-26, Shouichi Saito
46 .\" Updated 1999-12-26, Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2005-10-04, Kentaro Shirakata <argrath@ub32.org>
48 .\" Updated 2007-05-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.46
49 .\" Updated 2008-08-13, Akihiro MOTOKI, LDP v3.05
51 .\"WORD: numbers-and-dots notation 数値とドットによる記法
52 .\"WORD: dotted-decimal notation ドット区切りの 10 進数記法
53 .\"WORD: feature test macro 機能検査マクロ
55 .TH INET 3 2008-06-19 "GNU" "Linux Programmer's Manual"
57 inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof,
58 inet_netof \- インターネットアドレス操作ルーチン
61 .B #include <sys/socket.h>
62 .B #include <netinet/in.h>
63 .B #include <arpa/inet.h>
65 .BI "int inet_aton(const char *" cp ", struct in_addr *" inp );
67 .BI "in_addr_t inet_addr(const char *" cp );
69 .BI "in_addr_t inet_network(const char *" cp );
71 .BI "char *inet_ntoa(struct in_addr " in );
73 .BI "struct in_addr inet_makeaddr(int " net ", int " host );
75 .BI "in_addr_t inet_lnaof(struct in_addr " in );
77 .BI "in_addr_t inet_netof(struct in_addr " in );
82 .RB ( feature_test_macros (7)
88 _BSD_SOURCE || _SVID_SOURCE
91 は、インターネットホストのアドレス \fIcp\fP を、
92 IPv4 の数値とドットによる表記から (ネットワークバイトオーダの) バイナリ値へ
93 変換し、変換結果を \fIinp\fP が指している構造体に格納する。
94 アドレスが有効な場合 0 以外を返し、そうでない場合は 0 を返す。
96 で渡すアドレスとして、以下の形式を用いることができる。
99 4 つの数字のそれぞれはアドレスの各バイトを示す。
100 これらのバイトは左から右の順序でバイナリアドレスに割り当てられる。
106 はバイナリアドレスの最初の 2 バイトを示す。
108 は 16 ビット値と解釈され、バイナリアドレスの右側の 2 バイトを表す。
109 この表記は、(過去のものとなった) クラス B ネットワークアドレスを
116 は 24 ビット値と解釈され、バイナリアドレスの右側の 3 バイトを表す。
117 この表記は、(過去のものとなった) クラス C ネットワークアドレスを
123 は 32 ビット値と解釈され、バイトの再配置は行われず、
124 そのままバイナリアドレスとして格納される。
126 上記の全ての形式で、ドット区切りのアドレスの各要素は、10 進数、
134 .I "IPv4 の数値とドットによる表記 (IPv4 numbers-and-dots notation)"
136 また、10 進数 4 つだけを使った形式を
137 .I "IPv4 のドット区切りの 10 進数表記 (IPv4 dotted-decimal notation)"
139 .RI ( "IPv4 のドット区切り 4 分割表記 (IPv4 dotted-decimal notation)"
143 関数は、インターネットホストのアドレス \fIcp\fP を、
144 IPv4 の数値とドットによる表記からネットワークバイトオーダでの
149 \-1 は有効なアドレス (255.255.255.255) なので、この関数を使うと
156 これらの関数の方が、エラーの通知がよりきれいな方法で行われる。
160 IPv4 の数値とドットによる表記の文字列 \fIcp\fP を、
161 インターネットアドレスとしての使用に適した
167 関数は、ネットワークバイトオーダで渡されたインターネットホストアドレス
168 \fIin\fP を、 IPv4 のドット区切りの 10 進数表記の文字列に変換する。
169 文字列は静的に割当てられたバッファに格納されて返されるので、
170 この後でこの関数を再度呼び出すと文字列は上書きされる。
173 関数は、インターネットアドレス \fIin\fP のローカルネットワーク部分を返す。
177 関数は、インターネットアドレス \fIin\fP のネットワーク部分を返す。
186 ネットワーク番号 \fInet\fP と、ローカルアドレス \fIhost\fP を
187 組み合わせて生成した、インターネットホストアドレスを
189 \fIhost\fP, \fInet\fP はともにホストバイトオーダである。
192 .BR inet_makeaddr (),
195 で使用する構造体 \fIin_addr\fP は
201 typedef uint32_t in_addr_t;
212 は POSIX.1-2001 で規定されている。
214 は POSIX.1-2001 で規定されていないが、ほとんどのシステムで利用可能である。
216 i386 ではホストバイトオーダは Least Significant Byte (LSB) first
218 インターネットで使われるネットワークバイトオーダは
219 Most Significant Byte (MSB) first (ビッグエンディアン)
226 .I "クラスフル・ネットワークアドレス (classful network addresses)"
228 クラスフル・ネットワークアドレスでは、以下にあるように、
229 IPv4 ネットワークアドレスをバイト境界でネットワーク部とホスト部に分割する。
232 (ネットワークバイトオーダの) アドレスの最上位ビットが 0 の場合、
233 このアドレス種別となる。このアドレス種別では、
234 最上位バイトがネットワークアドレスを表し、
235 残りの 3 バイトがホストアドレスを表す。
238 (ネットワークバイトオーダの) アドレスの上位側 2 ビットがバイナリ値で
239 10 の場合、このアドレス種別となる。このアドレス種別では、
240 上位 2 バイトがネットワークアドレスを表し、
241 残りの 2 バイトがホストアドレスを表す。
244 (ネットワークバイトオーダの) アドレスの上位側 3 ビットがバイナリ値で
245 110 の場合、このアドレス種別となる。このアドレス種別では、
246 上位 3 バイトがネットワークアドレスを表し、
247 残りの 1 バイトがホストアドレスを表す。
249 クラスフル・ネットワークアドレスは現在では廃止され、
250 クラスレス・ドメイン間ルーチン (CIDR) に取って代わられた。
251 CIDR では、アドレスを任意のビット境界 (バイト境界ではない) で
262 .RB "$" " ./a.out 226.000.000.037" " # Last byte is in octal"
264 .RB "$" " ./a.out 0x7f.1 " " # First byte is in hex"
272 #include <arpa/inet.h>
277 main(int argc, char *argv[])
282 fprintf(stderr, "%s <dotted\-address>\\n", argv[0]);
286 if (inet_aton(argv[1], &addr) == 0) {
291 printf("%s\\n", inet_ntoa(addr));
298 .BR gethostbyname (3),