OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man3 / inet_pton.3
1 .\" Copyright 2000 Sam Varshavchik <mrsam@courier-mta.com>
2 .\" and Copyright (c) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" References: RFC 2553
27 .\"*******************************************************************
28 .\"
29 .\" This file was generated with po4a. Translate the source file.
30 .\"
31 .\"*******************************************************************
32 .TH INET_PTON 3 2008\-06\-18 Linux "Linux Programmer's Manual"
33 .SH 名前
34 inet_pton \- IPv4/IPv6 アドレスをテキスト形式からバイナリ形式に変換する
35 .SH 書式
36 .nf
37 \fB#include <arpa/inet.h>\fP
38
39 \fBint inet_pton(int \fP\fIaf\fP\fB, const char *\fP\fIsrc\fP\fB, void *\fP\fIdst\fP\fB);\fP
40 .fi
41 .SH 説明
42 この関数は文字列 \fIsrc\fP を、アドレスファミリー \fIaf\fP のネットワークアドレス構造体に変換し、 \fIdst\fP にコピーする。 \fIaf\fP
43 引き数は \fBAF_INET\fP か \fBAF_INET6\fP のどちらかでなければならない。
44 .PP
45 現在サポートされているアドレスファミリーは以下の通りである。
46 .TP 
47 \fBAF_INET\fP
48 \fIsrc\fP はドット区切りの 10 進数形式 "\fIddd.ddd.ddd.ddd\fP" の IPv4 ネットワークアドレス文字列へのポインタである。
49 \fIddd\fP は 0 から 255 までの範囲の最大 3 桁の 10 進数である。 このアドレスは \fIstruct in_addr\fP に変換されて
50 \fIdst\fP にコピーされる。 \fIdst\fP の長さは \fIsizeof(struct in_addr)\fP (4) バイト (32ビット)
51 でなければならない。
52 .TP 
53 \fBAF_INET6\fP
54 \fIsrc\fP は IPv6 ネットワークアドレスが格納された文字列へのポインタである。 このアドレスは \fIstruct in6_addr\fP
55 に変換されて \fIdst\fP にコピーされる。 \fIdst\fP の長さは \fIsizeof(struct in6_addr)\fP (16) バイト (128
56 ビット) でなければならない。 以下の 3 つのルールにしたがった形式が IPv6 アドレスとして入力できる。
57 .RS
58 .IP 1. 3
59 推奨形式は \fIx:x:x:x:x:x:x:x\fP である。この形式は 8 個の 16 進数から構成され、 各々の 16 進数は 16 ビット値を表す
60 (\fIx\fP は最大 4 桁の 16 進数である)。
61 .IP 2.
62 推奨形式の中の連続する 0 の列は \fI::\fP に短縮できる。アドレス中で使用できる \fI::\fP は 1 個だけである。 例えば、ループバックアドレス
63 \fI0:0:0:0:0:0:0:1\fP は \fI::1\fP と短縮できる。 全ビットが 0 で構成されるワイルドカードアドレスは \fI::\fP と記載できる。
64 .IP 3.
65 IPv4 をマッピングした IPv6 アドレスを表記するには別の形式が便利である。 この別の形式は \fIx:x:x:x:x:x:d.d.d.d\fP
66 と書くことができる。 最初の 6 個の \fIx\fP はアドレスを 16 ビット単位に区切ったときの上位側 6 個分 (つまり 96 ビット分)
67 を定義する 16 進数であり、 \fId\fP の部分はアドレスの下位 32 ビットをドット区切りの 10 進数表記で表したものである。
68 \fI::FFFF:204.152.189.116\fP はこの形式の例である。
69 .RE
70 .IP
71 IPv6 アドレスの表現方法の詳細については RFC 2373 を参照のこと。
72 .SH 返り値
73 成功する (ネットワークアドレスが正常に変換される) と、 \fBinet_pton\fP()  は 1 を返す。 \fIsrc\fP
74 が指定されたアドレスファミリーに対する 正しいネットワークアドレス表記でない場合には、 0 を返す。 \fIaf\fP
75 がサポートされているアドレスファミリーでない場合には、 \-1 を返し、 \fIerrno\fP に \fBEAFNOSUPPORT\fP を設定する。
76 .SH 準拠
77 POSIX.1\-2001.
78 .SH 注意
79 \fBinet_aton\fP(3)  や \fBinet_addr\fP(3)  と異なり、 \fBinet_pton\fP()  は IPv6
80 アドレスに対応している。 一方で、 \fBinet_pton\fP()  が受け付ける IPv4 アドレスはドット区切りの 10 進数表記だけである。
81 これに対し、 \fBinet_aton\fP(3)  や \fBinet_addr\fP(3)  ではもっと一般的なドット区切りの数字表記 (16 進数や 8
82 進数の形式や、 4 バイト全てを明示的に書かなくてもよい形式) が使用できる。 ドット区切りの数字表記で IPv6 アドレスと IPv4
83 アドレスの両方を扱える インターフェイスについては、 \fBgetaddrinfo\fP(3)  を参照のこと。
84 .SH バグ
85 \fBAF_INET6\fP は IPv4 アドレスを認識しない。 代わりに IPv4 アドレスをマッピングした IPv6 アドレスを \fIsrc\fP
86 に与えなければならない。
87 .SH 例
88 以下のプログラムは \fBinet_pton\fP()  と \fBinet_ntop\fP(3)  の使用例を示すものである。 実行すると以下のようになる。
89 .in +4n
90 .nf
91
92 $\fB ./a.out i6 0:0:0:0:0:0:0:0\fP
93 ::
94 $\fB ./a.out i6 1:0:0:0:0:0:0:8\fP
95 1::8
96 $\fB ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116\fP
97 ::ffff:204.152.189.116
98 .fi
99 .in
100 .SS プログラムのソース
101 \&
102 .nf
103 #include <arpa/inet.h>
104 #include <stdio.h>
105 #include <stdlib.h>
106 #include <string.h>
107
108 int
109 main(int argc, char *argv[])
110 {
111     unsigned char buf[sizeof(struct in6_addr)];
112     int domain, s;
113     char str[INET6_ADDRSTRLEN];
114
115     if (argc != 3) {
116         fprintf(stderr, "Usage: %s {i4|i6|<num>} string\en", argv[0]);
117         exit(EXIT_FAILURE);
118     }
119
120     domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :
121              (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);
122
123     s = inet_pton(domain, argv[2], buf);
124     if (s <= 0) {
125         if (s == 0)
126             fprintf(stderr, "Not in presentation format");
127         else
128             perror("inet_pton");
129         exit(EXIT_FAILURE);
130     }
131
132     if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
133         perror("inet_ntop");
134         exit(EXIT_FAILURE);
135     }
136
137     printf("%s\en", str);
138
139     exit(EXIT_SUCCESS);
140 }
141 .fi
142 .SH 関連項目
143 \fBgetaddrinfo\fP(3), \fBinet\fP(3), \fBinet_ntop\fP(3)
144 .SH この文書について
145 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
146 である。プロジェクトの説明とバグ報告に関する情報は
147 http://www.kernel.org/doc/man\-pages/ に書かれている。