1 .\" Copyright 2000 Sam Varshavchik <mrsam@courier-mta.com>
2 .\" and Copyright (c) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" References: RFC 2553
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
30 .TH INET_PTON 3 2008-06-18 "Linux" "Linux Programmer's Manual"
32 .\"O inet_pton \- convert IPv4 and IPv6 addresses from text to binary form
34 inet_pton \- IPv4/IPv6 ¥¢¥É¥ì¥¹¤ò¥Æ¥¥¹¥È·Á¼°¤«¤é¥Ð¥¤¥Ê¥ê·Á¼°¤ËÊÑ´¹¤¹¤ë
38 .B #include <arpa/inet.h>
40 .BI "int inet_pton(int " "af" ", const char *" "src" ", void *" "dst" );
44 .\"O This function converts the character string
46 .\"O into a network address structure in the
48 .\"O address family, then
50 .\"O the network address structure to
54 ¤ò¡¢¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼
56 ¤Î¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¹½Â¤ÂΤËÊÑ´¹¤·¡¢
61 .\"O argument must be either
70 ¤Î¤É¤Á¤é¤«¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
72 .\"O The following address families are currently supported:
73 ¸½ºß¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
77 .\"O points to a character string containing an IPv4 network address in
78 .\"O dotted-decimal format, "\fIddd.ddd.ddd.ddd\fP", where
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
86 .\"O .I sizeof(struct in_addr)
87 .\"O (4) bytes (32 bits) long.
89 ¤Ï¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ô·Á¼° "\fIddd.ddd.ddd.ddd\fP"
90 ¤Î IPv4 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
92 ¤Ï 0 ¤«¤é 255 ¤Þ¤Ç¤ÎÈϰϤκÇÂç 3 ·å¤Î 10 ¿Ê¿ô¤Ç¤¢¤ë¡£
100 .I "sizeof(struct in_addr)"
101 (4) ¥Ð¥¤¥È (32¥Ó¥Ã¥È) ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
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
111 .\"O .I sizeof(struct in6_addr)
112 .\"O (16) bytes (128 bits) long.
114 ¤Ï IPv6 ¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬³ÊǼ¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
122 .I "sizeof(struct in6_addr)"
123 (16) ¥Ð¥¤¥È (128 ¥Ó¥Ã¥È) ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
124 .\"O The allowed formats for IPv6 addresses follow these rules:
125 °Ê²¼¤Î 3 ¤Ä¤Î¥ë¡¼¥ë¤Ë¤·¤¿¤¬¤Ã¤¿·Á¼°¤¬ IPv6 ¥¢¥É¥ì¥¹¤È¤·¤ÆÆþÎϤǤ¤ë¡£
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
133 .\"O can be up to 4 hex digits).
136 ¤Ç¤¢¤ë¡£¤³¤Î·Á¼°¤Ï 8 ¸Ä¤Î 16 ¿Ê¿ô¤«¤é¹½À®¤µ¤ì¡¢
137 ³Æ¡¹¤Î 16 ¿Ê¿ô¤Ï 16 ¥Ó¥Ã¥ÈÃͤòɽ¤¹
139 ¤ÏºÇÂç 4 ·å¤Î 16 ¿Ê¿ô¤Ç¤¢¤ë)¡£
141 .\"O A series of contiguous zero values in the preferred format
142 .\"O can be abbreviated to
144 .\"O Only one instance of
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
151 .\"O The wildcard address, consisting of all zeros, can be written as
153 ¿ä¾©·Á¼°¤ÎÃæ¤ÎϢ³¤¹¤ë 0 ¤ÎÎó¤Ï
155 ¤Ëû½Ì¤Ç¤¤ë¡£¥¢¥É¥ì¥¹Ãæ¤Ç»ÈÍѤǤ¤ë
158 Î㤨¤Ð¡¢¥ë¡¼¥×¥Ð¥Ã¥¯¥¢¥É¥ì¥¹
163 Á´¥Ó¥Ã¥È¤¬ 0 ¤Ç¹½À®¤µ¤ì¤ë¥ï¥¤¥ë¥É¥«¡¼¥É¥¢¥É¥ì¥¹¤Ï
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
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
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 ¥¢¥É¥ì¥¹¤òɽµ¤¹¤ë¤Ë¤ÏÊ̤ηÁ¼°¤¬ÊØÍø¤Ç¤¢¤ë¡£
181 .I x:x:x:x:x:x:d.d.d.d
185 ¤Ï¥¢¥É¥ì¥¹¤ò 16 ¥Ó¥Ã¥Èñ°Ì¤Ë¶èÀڤ俤Ȥ¤Î¾å°Ì¦ 6 ¸Äʬ (¤Ä¤Þ¤ê 96 ¥Ó¥Ã¥Èʬ)
186 ¤òÄêµÁ¤¹¤ë 16 ¿Ê¿ô¤Ç¤¢¤ê¡¢
188 ¤ÎÉôʬ¤Ï¥¢¥É¥ì¥¹¤Î²¼°Ì 32 ¥Ó¥Ã¥È¤ò¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ôɽµ¤Çɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
189 .I ::FFFF:204.152.189.116
190 ¤Ï¤³¤Î·Á¼°¤ÎÎã¤Ç¤¢¤ë¡£
193 .\"O See RFC 2373 for further details on the representation of IPv6 addresses.
194 IPv6 ¥¢¥É¥ì¥¹¤Îɽ¸½ÊýË¡¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï RFC 2373 ¤ò»²¾È¤Î¤³¤È¡£
195 .\"O .SH "RETURN VALUE"
197 .\"O .BR inet_pton ()
198 .\"O returns 1 on success (network address was successfully converted).
199 .\"O 0 is returned if
201 .\"O does not contain a character string representing a valid network
202 .\"O address in the specified address family.
205 .\"O does not contain a valid address family, \-1 is returned and
208 .\"O .BR EAFNOSUPPORT .
209 À®¸ù¤¹¤ë (¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹¤¬Àµ¾ï¤ËÊÑ´¹¤µ¤ì¤ë) ¤È¡¢
213 ¤¬»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤ËÂФ¹¤ë
214 Àµ¤·¤¤¥Í¥Ã¥È¥ï¡¼¥¯¥¢¥É¥ì¥¹É½µ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
217 ¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¥Õ¥¡¥ß¥ê¡¼¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
223 .\"O .SH "CONFORMING TO"
229 .\"O .BR inet_aton (3)
231 .\"O .BR inet_addr (3),
232 .\"O .BR inet_pton ()
233 .\"O supports IPv6 addresses.
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)
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).
254 ¤¬¼õ¤±ÉÕ¤±¤ë IPv4 ¥¢¥É¥ì¥¹¤Ï¥É¥Ã¥È¶èÀÚ¤ê¤Î 10 ¿Ê¿ôɽµ¤À¤±¤Ç¤¢¤ë¡£
259 ¤Ç¤Ï¤â¤Ã¤È°ìÈÌŪ¤Ê¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»úɽµ (16 ¿Ê¿ô¤ä 8 ¿Ê¿ô¤Î·Á¼°¤ä¡¢
260 4 ¥Ð¥¤¥ÈÁ´¤Æ¤òÌÀ¼¨Åª¤Ë½ñ¤«¤Ê¤¯¤Æ¤â¤è¤¤·Á¼°) ¤¬»ÈÍѤǤ¤ë¡£
261 ¥É¥Ã¥È¶èÀÚ¤ê¤Î¿ô»úɽµ¤Ç IPv6 ¥¢¥É¥ì¥¹¤È IPv4 ¥¢¥É¥ì¥¹¤ÎξÊý¤ò°·¤¨¤ë
262 ¥¤¥ó¥¿¡¼¥Õ¥§¥¤¥¹¤Ë¤Ä¤¤¤Æ¤Ï¡¢
268 .\"O does not recognize IPv4 addresses.
269 .\"O An explicit IPv4-mapped IPv6 address must be supplied in
273 ¤Ï IPv4 ¥¢¥É¥ì¥¹¤òǧ¼±¤·¤Ê¤¤¡£
274 Âå¤ï¤ê¤Ë IPv4 ¥¢¥É¥ì¥¹¤ò¥Þ¥Ã¥Ô¥ó¥°¤·¤¿ IPv6 ¥¢¥É¥ì¥¹¤ò
276 ¤ËÍ¿¤¨¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
279 .\"O The program below demonstrates the use of
280 .\"O .BR inet_pton ()
282 .\"O .BR inet_ntop (3).
283 .\"O Here are some example runs:
288 ¤Î»ÈÍÑÎã¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£
289 ¼Â¹Ô¤¹¤ë¤È°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
293 .RB "$" " ./a.out i6 0:0:0:0:0:0:0:0"
295 .RB "$" " ./a.out i6 1:0:0:0:0:0:0:8"
297 .RB "$" " ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116"
298 ::ffff:204.152.189.116
301 .\"O .SS Program source
302 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
305 #include <arpa/inet.h>
311 main(int argc, char *argv[])
313 unsigned char buf[sizeof(struct in6_addr)];
315 char str[INET6_ADDRSTRLEN];
318 fprintf(stderr, "Usage: %s {i4|i6|<num>} string\\n", argv[0]);
322 domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :
323 (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);
325 s = inet_pton(domain, argv[2], buf);
328 fprintf(stderr, "Not in presentation format");
334 if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {
339 printf("%s\\n", str);