OSDN Git Service

(split) Apply minor changes from v3.32 to v3.35 in the upstream.
[linuxjm/LDP_man-pages.git] / draft / 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 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" References: RFC 2553
25 .\"
26 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
27 .\" Translated 2001-01-14, NAKANO Takeo <nakano@apm.seikei.ac.jp>
28 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
29 .\"
30 .TH INET_PTON 3  2008-06-18 "Linux" "Linux Programmer's Manual"
31 .\"O .SH NAME
32 .\"O inet_pton \- convert IPv4 and IPv6 addresses from text to binary form
33 .SH Ì¾Á°
34 inet_pton \- IPv4/IPv6 ¥¢¥É¥ì¥¹¤ò¥Æ¥­¥¹¥È·Á¼°¤«¤é¥Ð¥¤¥Ê¥ê·Á¼°¤ËÊÑ´¹¤¹¤ë
35 .\"O .SH SYNOPSIS
36 .SH ½ñ¼°
37 .nf
38 .B #include <arpa/inet.h>
39
40 .BI "int inet_pton(int " "af" ", const char *" "src" ", void *" "dst" );
41 .fi
42 .\"O .SH DESCRIPTION
43 .SH ÀâÌÀ
44 .\"O This function converts the character string
45 .\"O .I src
46 .\"O into a network address structure in the
47 .\"O .I af
48 .\"O address family, then
49 .\"O copies
50 .\"O the network address structure to
51 .\"O .IR dst .
52 ¤³¤Î´Ø¿ô¤Ïʸ»úÎó
53 .I src
54 ¤ò¡¢¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼
55 .I af
56 ¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¹½Â¤ÂΤËÊÑ´¹¤·¡¢
57 .I dst
58 ¤Ë¥³¥Ô¡¼¤¹¤ë¡£
59 .\"O The
60 .\"O .I af
61 .\"O argument must be either
62 .\"O .B AF_INET
63 .\"O or
64 .\"O .BR AF_INET6 .
65 .I af
66 °ú¤­¿ô¤Ï
67 .B AF_INET
68 ¤«
69 .B AF_INET6
70 ¤Î¤É¤Á¤é¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
71 .PP
72 .\"O The following address families are currently supported:
73 ¸½ºß¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
74 .TP
75 .B AF_INET
76 .\"O .I src
77 .\"O points to a character string containing an IPv4 network address in
78 .\"O dotted-decimal format, "\fIddd.ddd.ddd.ddd\fP", where
79 .\"O .I ddd
80 .\"O is a decimal number of up to three digits in the range 0 to 255.
81 .\"O The address is converted to a
82 .\"O .I struct in_addr
83 .\"O and copied to
84 .\"O .IR dst ,
85 .\"O which must be
86 .\"O .I sizeof(struct in_addr)
87 .\"O (4) bytes (32 bits) long.
88 .I src
89 ¤Ï¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ô·Á¼° "\fIddd.ddd.ddd.ddd\fP"
90 ¤Î IPv4 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
91 .I ddd
92 ¤Ï 0 ¤«¤é 255 ¤Þ¤Ç¤ÎÈϰϤκÇÂç 3 ·å¤Î 10 ¿Ê¿ô¤Ç¤¢¤ë¡£
93 ¤³¤Î¥¢¥É¥ì¥¹¤Ï
94 .I "struct in_addr"
95 ¤ËÊÑ´¹¤µ¤ì¤Æ
96 .I dst
97 ¤Ë¥³¥Ô¡¼¤µ¤ì¤ë¡£
98 .I dst
99 ¤ÎŤµ¤Ï
100 .I "sizeof(struct in_addr)"
101 (4) ¥Ð¥¤¥È (32¥Ó¥Ã¥È) ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
102 .TP
103 .B AF_INET6
104 .\"O .I src
105 .\"O points to a character string containing an IPv6 network address.
106 .\"O The address is converted to a
107 .\"O .I struct in6_addr
108 .\"O and copied to
109 .\"O .IR dst ,
110 .\"O which must be
111 .\"O .I sizeof(struct in6_addr)
112 .\"O (16) bytes (128 bits) long.
113 .I src
114 ¤Ï IPv6 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬³ÊǼ¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
115 ¤³¤Î¥¢¥É¥ì¥¹¤Ï
116 .I "struct in6_addr"
117 ¤ËÊÑ´¹¤µ¤ì¤Æ
118 .I dst
119 ¤Ë¥³¥Ô¡¼¤µ¤ì¤ë¡£
120 .I dst
121 ¤ÎŤµ¤Ï
122 .I "sizeof(struct in6_addr)"
123 (16) ¥Ð¥¤¥È (128 ¥Ó¥Ã¥È) ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
124 .\"O The allowed formats for IPv6 addresses follow these rules:
125 °Ê²¼¤Î 3 ¤Ä¤Î¥ë¡¼¥ë¤Ë¤·¤¿¤¬¤Ã¤¿·Á¼°¤¬ IPv6 ¥¢¥É¥ì¥¹¤È¤·¤ÆÆþÎϤǤ­¤ë¡£
126 .RS
127 .IP 1. 3
128 .\"O The preferred format is
129 .\"O .IR x:x:x:x:x:x:x:x .
130 .\"O This form consists of eight hexadecimal numbers,
131 .\"O each of which expresses a 16-bit value (i.e., each
132 .\"O .I x
133 .\"O can be up to 4 hex digits).
134 ¿ä¾©·Á¼°¤Ï
135 .I x:x:x:x:x:x:x:x
136 ¤Ç¤¢¤ë¡£¤³¤Î·Á¼°¤Ï 8 ¸Ä¤Î 16 ¿Ê¿ô¤«¤é¹½À®¤µ¤ì¡¢
137 ³Æ¡¹¤Î 16 ¿Ê¿ô¤Ï 16 ¥Ó¥Ã¥ÈÃͤòɽ¤¹
138 .RI ( x
139 ¤ÏºÇÂç 4 ·å¤Î 16 ¿Ê¿ô¤Ç¤¢¤ë)¡£
140 .IP 2.
141 .\"O A series of contiguous zero values in the preferred format
142 .\"O can be abbreviated to
143 .\"O .IR :: .
144 .\"O Only one instance of
145 .\"O .I ::
146 .\"O can occur in an address.
147 .\"O For example, the loopback address
148 .\"O .I 0:0:0:0:0:0:0:1
149 .\"O can be abbreviated as
150 .\"O .IR ::1 .
151 .\"O The wildcard address, consisting of all zeros, can be written as
152 .\"O .IR :: .
153 ¿ä¾©·Á¼°¤ÎÃæ¤ÎϢ³¤¹¤ë 0 ¤ÎÎó¤Ï
154 .I ::
155 ¤Ëû½Ì¤Ç¤­¤ë¡£¥¢¥É¥ì¥¹Ãæ¤Ç»ÈÍѤǤ­¤ë
156 .I ::
157 ¤Ï 1 ¸Ä¤À¤±¤Ç¤¢¤ë¡£
158 Î㤨¤Ð¡¢¥ë¡¼¥×¥Ð¥Ã¥¯¥¢¥É¥ì¥¹
159 .I 0:0:0:0:0:0:0:1
160 ¤Ï
161 .I ::1
162 ¤Èû½Ì¤Ç¤­¤ë¡£
163 Á´¥Ó¥Ã¥È¤¬ 0 ¤Ç¹½À®¤µ¤ì¤ë¥ï¥¤¥ë¥É¥«¡¼¥É¥¢¥É¥ì¥¹¤Ï
164 .I ::
165 ¤Èµ­ºÜ¤Ç¤­¤ë¡£
166 .IP 3.
167 .\"O An alternate format is useful for expressing IPv4-mapped IPv6 addresses.
168 .\"O This form is written as
169 .\"O .IR x:x:x:x:x:x:d.d.d.d ,
170 .\"O where the six leading
171 .\"O .IR x s
172 .\"O are hexadecimal values that define the six most-significant
173 .\"O 16-bit pieces of the address (i.e., 96 bits), and the
174 .\"O .IR d s
175 .\"O express a value in dotted-decimal notation that
176 .\"O defines the least significant 32 bits of the address.
177 .\"O An example of such an address is
178 .\"O .IR ::FFFF:204.152.189.116 .
179 IPv4 ¤ò¥Þ¥Ã¥Ô¥ó¥°¤·¤¿ IPv6 ¥¢¥É¥ì¥¹¤òɽµ­¤¹¤ë¤Ë¤ÏÊ̤ηÁ¼°¤¬ÊØÍø¤Ç¤¢¤ë¡£
180 ¤³¤ÎÊ̤ηÁ¼°¤Ï
181 .I x:x:x:x:x:x:d.d.d.d
182 ¤È½ñ¤¯¤³¤È¤¬¤Ç¤­¤ë¡£
183 ºÇ½é¤Î 6 ¸Ä¤Î
184 .I x
185 ¤Ï¥¢¥É¥ì¥¹¤ò 16 ¥Ó¥Ã¥Èñ°Ì¤Ë¶èÀڤ俤Ȥ­¤Î¾å°Ì¦ 6 ¸Äʬ (¤Ä¤Þ¤ê 96 ¥Ó¥Ã¥Èʬ)
186 ¤òÄêµÁ¤¹¤ë 16 ¿Ê¿ô¤Ç¤¢¤ê¡¢
187 .I d
188 ¤ÎÉôʬ¤Ï¥¢¥É¥ì¥¹¤Î²¼°Ì 32 ¥Ó¥Ã¥È¤ò¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ôɽµ­¤Çɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
189 .I ::FFFF:204.152.189.116
190 ¤Ï¤³¤Î·Á¼°¤ÎÎã¤Ç¤¢¤ë¡£
191 .RE
192 .IP
193 .\"O See RFC 2373 for further details on the representation of IPv6 addresses.
194 IPv6 ¥¢¥É¥ì¥¹¤Îɽ¸½ÊýË¡¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï RFC 2373 ¤ò»²¾È¤Î¤³¤È¡£
195 .\"O .SH "RETURN VALUE"
196 .SH ÊÖ¤êÃÍ
197 .\"O .BR inet_pton ()
198 .\"O returns 1 on success (network address was successfully converted).
199 .\"O 0 is returned if
200 .\"O .I src
201 .\"O does not contain a character string representing a valid network
202 .\"O address in the specified address family.
203 .\"O If
204 .\"O .I af
205 .\"O does not contain a valid address family, \-1 is returned and
206 .\"O .I errno
207 .\"O is set to
208 .\"O .BR EAFNOSUPPORT .
209 À®¸ù¤¹¤ë (¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬Àµ¾ï¤ËÊÑ´¹¤µ¤ì¤ë) ¤È¡¢
210 .BR inet_pton ()
211 ¤Ï 1 ¤òÊÖ¤¹¡£
212 .I src
213 ¤¬»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ËÂФ¹¤ë
214 Àµ¤·¤¤¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹É½µ­¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
215 0 ¤òÊÖ¤¹¡£
216 .I af
217 ¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
218 \-1 ¤òÊÖ¤·¡¢
219 .I errno
220 ¤Ë
221 .B EAFNOSUPPORT
222 ¤òÀßÄꤹ¤ë¡£
223 .\"O .SH "CONFORMING TO"
224 .SH ½àµò
225 POSIX.1-2001.
226 .\"O .SH NOTES
227 .SH Ãí°Õ
228 .\"O Unlike
229 .\"O .BR inet_aton (3)
230 .\"O and
231 .\"O .BR inet_addr (3),
232 .\"O .BR inet_pton ()
233 .\"O supports IPv6 addresses.
234 .BR inet_aton (3)
235 ¤ä
236 .BR inet_addr (3)
237 ¤È°Û¤Ê¤ê¡¢
238 .BR inet_pton ()
239 ¤Ï IPv6 ¥¢¥É¥ì¥¹¤ËÂбþ¤·¤Æ¤¤¤ë¡£
240 .\"O On the other hand,
241 .\"O .BR inet_pton ()
242 .\"O only accepts IPv4 addresses in dotted-decimal notation, whereas
243 .\"O .BR inet_aton (3)
244 .\"O and
245 .\"O .BR inet_addr (3)
246 .\"O allow the more general numbers-and-dots notation (hexadecimal
247 .\"O and octal number formats, and formats that don't require all
248 .\"O four bytes to be explicitly written).
249 .\"O For an interface that handles both IPv6 addresses, and IPv4
250 .\"O addresses in numbers-and-dots notation, see
251 .\"O .BR getaddrinfo (3).
252 °ìÊý¤Ç¡¢
253 .BR inet_pton ()
254 ¤¬¼õ¤±ÉÕ¤±¤ë IPv4 ¥¢¥É¥ì¥¹¤Ï¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ôɽµ­¤À¤±¤Ç¤¢¤ë¡£
255 ¤³¤ì¤ËÂФ·¡¢
256 .BR inet_aton (3)
257 ¤ä
258 .BR inet_addr (3)
259 ¤Ç¤Ï¤â¤Ã¤È°ìÈÌŪ¤Ê¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»úɽµ­ (16 ¿Ê¿ô¤ä 8 ¿Ê¿ô¤Î·Á¼°¤ä¡¢
260 4 ¥Ð¥¤¥ÈÁ´¤Æ¤òÌÀ¼¨Åª¤Ë½ñ¤«¤Ê¤¯¤Æ¤â¤è¤¤·Á¼°) ¤¬»ÈÍѤǤ­¤ë¡£
261 ¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»úɽµ­¤Ç IPv6 ¥¢¥É¥ì¥¹¤È IPv4 ¥¢¥É¥ì¥¹¤ÎξÊý¤ò°·¤¨¤ë
262 ¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Ë¤Ä¤¤¤Æ¤Ï¡¢
263 .BR getaddrinfo (3)
264 ¤ò»²¾È¤Î¤³¤È¡£
265 .\"O .SH BUGS
266 .SH ¥Ð¥°
267 .\"O .B AF_INET6
268 .\"O does not recognize IPv4 addresses.
269 .\"O An explicit IPv4-mapped IPv6 address must be supplied in
270 .\"O .I src
271 .\"O instead.
272 .B AF_INET6
273 ¤Ï IPv4 ¥¢¥É¥ì¥¹¤òǧ¼±¤·¤Ê¤¤¡£
274 Âå¤ï¤ê¤Ë IPv4 ¥¢¥É¥ì¥¹¤ò¥Þ¥Ã¥Ô¥ó¥°¤·¤¿ IPv6 ¥¢¥É¥ì¥¹¤ò
275 .I src
276 ¤ËÍ¿¤¨¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
277 .\"O .SH EXAMPLE
278 .SH Îã
279 .\"O The program below demonstrates the use of
280 .\"O .BR inet_pton ()
281 .\"O and
282 .\"O .BR inet_ntop (3).
283 .\"O Here are some example runs:
284 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï
285 .BR inet_pton ()
286 ¤È
287 .BR inet_ntop (3)
288 ¤Î»ÈÍÑÎã¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£
289 ¼Â¹Ô¤¹¤ë¤È°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
290 .in +4n
291 .nf
292
293 .RB "$" " ./a.out i6 0:0:0:0:0:0:0:0"
294 ::
295 .RB "$" " ./a.out i6 1:0:0:0:0:0:0:8"
296 1::8
297 .RB "$" " ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116"
298 ::ffff:204.152.189.116
299 .fi
300 .in
301 .\"O .SS Program source
302 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
303 \&
304 .nf
305 #include <arpa/inet.h>
306 #include <stdio.h>
307 #include <stdlib.h>
308 #include <string.h>
309
310 int
311 main(int argc, char *argv[])
312 {
313     unsigned char buf[sizeof(struct in6_addr)];
314     int domain, s;
315     char str[INET6_ADDRSTRLEN];
316
317     if (argc != 3) {
318         fprintf(stderr, "Usage: %s {i4|i6|<num>} string\\n", argv[0]);
319         exit(EXIT_FAILURE);
320     }
321
322     domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :
323              (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);
324
325     s = inet_pton(domain, argv[2], buf);
326     if (s <= 0) {
327         if (s == 0)
328             fprintf(stderr, "Not in presentation format");
329         else
330             perror("inet_pton");
331         exit(EXIT_FAILURE);
332     }
333
334     if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
335         perror("inet_ntop");
336         exit(EXIT_FAILURE);
337     }
338
339     printf("%s\\n", str);
340
341     exit(EXIT_SUCCESS);
342 }
343 .fi
344 .\"O .SH "SEE ALSO"
345 .SH ´ØÏ¢¹àÌÜ
346 .BR getaddrinfo (3),
347 .BR inet (3),
348 .BR inet_ntop (3)