.\" Copyright 2000 Sam Varshavchik .\" and Copyright (c) 2008 Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References: RFC 2553 .\" .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved. .\" Translated 2001-01-14, NAKANO Takeo .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05 .\" .TH INET_PTON 3 2008-06-18 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .\"O inet_pton \- convert IPv4 and IPv6 addresses from text to binary form .SH 名前 inet_pton \- IPv4/IPv6 アドレスをテキスト形式からバイナリ形式に変換する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .BI "int inet_pton(int " "af" ", const char *" "src" ", void *" "dst" ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O This function converts the character string .\"O .I src .\"O into a network address structure in the .\"O .I af .\"O address family, then .\"O copies .\"O the network address structure to .\"O .IR dst . この関数は文字列 .I src を、アドレスファミリー .I af のネットワークアドレス構造体に変換し、 .I dst にコピーする。 .\"O The .\"O .I af .\"O argument must be either .\"O .B AF_INET .\"O or .\"O .BR AF_INET6 . .I af 引き数は .B AF_INET か .B AF_INET6 のどちらかでなければならない。 .PP .\"O The following address families are currently supported: 現在サポートされているアドレスファミリーは以下の通りである。 .TP .B AF_INET .\"O .I src .\"O points to a character string containing an IPv4 network address in .\"O dotted-decimal format, "\fIddd.ddd.ddd.ddd\fP", where .\"O .I ddd .\"O is a decimal number of up to three digits in the range 0 to 255. .\"O The address is converted to a .\"O .I struct in_addr .\"O and copied to .\"O .IR dst , .\"O which must be .\"O .I sizeof(struct in_addr) .\"O (4) bytes (32 bits) long. .I src はドット区切りの 10 進数形式 "\fIddd.ddd.ddd.ddd\fP" の IPv4 ネットワークアドレス文字列へのポインタである。 .I ddd は 0 から 255 までの範囲の最大 3 桁の 10 進数である。 このアドレスは .I "struct in_addr" に変換されて .I dst にコピーされる。 .I dst の長さは .I "sizeof(struct in_addr)" (4) バイト (32ビット) でなければならない。 .TP .B AF_INET6 .\"O .I src .\"O points to a character string containing an IPv6 network address. .\"O The address is converted to a .\"O .I struct in6_addr .\"O and copied to .\"O .IR dst , .\"O which must be .\"O .I sizeof(struct in6_addr) .\"O (16) bytes (128 bits) long. .I src は IPv6 ネットワークアドレスが格納された文字列へのポインタである。 このアドレスは .I "struct in6_addr" に変換されて .I dst にコピーされる。 .I dst の長さは .I "sizeof(struct in6_addr)" (16) バイト (128 ビット) でなければならない。 .\"O The allowed formats for IPv6 addresses follow these rules: 以下の 3 つのルールにしたがった形式が IPv6 アドレスとして入力できる。 .RS .IP 1. 3 .\"O The preferred format is .\"O .IR x:x:x:x:x:x:x:x . .\"O This form consists of eight hexadecimal numbers, .\"O each of which expresses a 16-bit value (i.e., each .\"O .I x .\"O can be up to 4 hex digits). 推奨形式は .I x:x:x:x:x:x:x:x である。この形式は 8 個の 16 進数から構成され、 各々の 16 進数は 16 ビット値を表す .RI ( x は最大 4 桁の 16 進数である)。 .IP 2. .\"O A series of contiguous zero values in the preferred format .\"O can be abbreviated to .\"O .IR :: . .\"O Only one instance of .\"O .I :: .\"O can occur in an address. .\"O For example, the loopback address .\"O .I 0:0:0:0:0:0:0:1 .\"O can be abbreviated as .\"O .IR ::1 . .\"O The wildcard address, consisting of all zeroes, can be written as .\"O .IR :: . 推奨形式の中の連続する 0 の列は .I :: に短縮できる。アドレス中で使用できる .I :: は 1 個だけである。 例えば、ループバックアドレス .I 0:0:0:0:0:0:0:1 は .I ::1 と短縮できる。 全ビットが 0 で構成されるワイルドカードアドレスは .I :: と記載できる。 .IP 3. .\"O An alternate format is useful for expressing IPv4-mapped IPv6 addresses. .\"O This form is written as .\"O .IR x:x:x:x:x:x:d.d.d.d , .\"O where the six leading .\"O .IR x s .\"O are hexadecimal values that define the six most-significant .\"O 16-bit pieces of the address (i.e., 96 bits), and the .\"O .IR d s .\"O express a value in dotted-decimal notation that .\"O defines the least significant 32 bits of the address. .\"O An example of such an address is .\"O .IR ::FFFF:204.152.189.116 . IPv4 をマッピングした IPv6 アドレスを表記するには別の形式が便利である。 この別の形式は .I x:x:x:x:x:x:d.d.d.d と書くことができる。 最初の 6 個の .I x はアドレスを 16 ビット単位に区切ったときの上位側 6 個分 (つまり 96 ビット分) を定義する 16 進数であり、 .I d の部分はアドレスの下位 32 ビットをドット区切りの 10 進数表記で表したものである。 .I ::FFFF:204.152.189.116 はこの形式の例である。 .RE .IP .\"O See RFC 2373 for further details on the representation of IPv6 addresses. IPv6 アドレスの表現方法の詳細については RFC 2373 を参照のこと。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O .BR inet_pton () .\"O returns 1 on success (network address was successfully converted). .\"O 0 is returned if .\"O .I src .\"O does not contain a character string representing a valid network .\"O address in the specified address family. .\"O If .\"O .I af .\"O does not contain a valid address family, \-1 is returned and .\"O .I errno .\"O is set to .\"O .BR EAFNOSUPPORT . 成功する (ネットワークアドレスが正常に変換される) と、 .BR inet_pton () は 1 を返す。 .I src が指定されたアドレスファミリーに対する 正しいネットワークアドレス表記でない場合には、 0 を返す。 .I af がサポートされているアドレスファミリーでない場合には、 \-1 を返し、 .I errno に .B EAFNOSUPPORT を設定する。 .\"O .SH "CONFORMING TO" .SH 準拠 POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O Unlike .\"O .BR inet_aton (3) .\"O and .\"O .BR inet_addr (3), .\"O .BR inet_pton () .\"O supports IPv6 addresses. .BR inet_aton (3) や .BR inet_addr (3) と異なり、 .BR inet_pton () は IPv6 アドレスに対応している。 .\"O On the other hand, .\"O .BR inet_pton () .\"O only accepts IPv4 addresses in dotted-decimal notation, whereas .\"O .BR inet_aton (3) .\"O and .\"O .BR inet_addr (3) .\"O allow the more general numbers-and-dots notation (hexadecimal .\"O and octal number formats, and formats that don't require all .\"O four bytes to be explicitly written). .\"O For an interface that handles both IPv6 addresses, and IPv4 .\"O addresses in numbers-and-dots notation, see .\"O .BR getaddrinfo (3). 一方で、 .BR inet_pton () が受け付ける IPv4 アドレスはドット区切りの 10 進数表記だけである。 これに対し、 .BR inet_aton (3) や .BR inet_addr (3) ではもっと一般的なドット区切りの数字表記 (16 進数や 8 進数の形式や、 4 バイト全てを明示的に書かなくてもよい形式) が使用できる。 ドット区切りの数字表記で IPv6 アドレスと IPv4 アドレスの両方を扱える インターフェイスについては、 .BR getaddrinfo (3) を参照のこと。 .\"O .SH BUGS .SH バグ .\"O .B AF_INET6 .\"O does not recognize IPv4 addresses. .\"O An explicit IPv4-mapped IPv6 address must be supplied in .\"O .I src .\"O instead. .B AF_INET6 は IPv4 アドレスを認識しない。 代わりに IPv4 アドレスをマッピングした IPv6 アドレスを .I src に与えなければならない。 .\"O .SH EXAMPLE .SH 例 .\"O The program below demonstrates the use of .\"O .BR inet_pton () .\"O and .\"O .BR inet_ntop (3). .\"O Here are some example runs: 以下のプログラムは .BR inet_pton () と .BR inet_ntop (3) の使用例を示すものである。 実行すると以下のようになる。 .in +4n .nf .RB "$" " ./a.out i6 0:0:0:0:0:0:0:0" :: .RB "$" " ./a.out i6 1:0:0:0:0:0:0:8" 1::8 .RB "$" " ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116" ::ffff:204.152.189.116 .fi .in .\"O .SS Program source .SS プログラムのソース \& .nf #include #include #include #include int main(int argc, char *argv[]) { unsigned char buf[sizeof(struct in6_addr)]; int domain, s; char str[INET6_ADDRSTRLEN]; if (argc != 3) { fprintf(stderr, "Usage: %s {i4|i6|} string\\n", argv[0]); exit(EXIT_FAILURE); } domain = (strcmp(argv[1], "i4") == 0) ? AF_INET : (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]); s = inet_pton(domain, argv[2], buf); if (s <= 0) { if (s == 0) fprintf(stderr, "Not in presentation format"); else perror("inet_pton"); exit(EXIT_FAILURE); } if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) { perror("inet_ntop"); exit(EXIT_FAILURE); } printf("%s\\n", str); exit(EXIT_SUCCESS); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR getaddrinfo (3), .BR inet (3), .BR inet_ntop (3)