< prev index next >

src/java.base/share/classes/java/net/Inet6Address.java

Print this page




  32 import java.io.ObjectStreamField;
  33 import java.util.Enumeration;
  34 import java.util.Arrays;
  35 
  36 /**
  37  * This class represents an Internet Protocol version 6 (IPv6) address.
  38  * Defined by <a href="http://www.ietf.org/rfc/rfc2373.txt">
  39  * <i>RFC&nbsp;2373: IP Version 6 Addressing Architecture</i></a>.
  40  *
  41  * <h3> <a id="format">Textual representation of IP addresses</a> </h3>
  42  *
  43  * Textual representation of IPv6 address used as input to methods
  44  * takes one of the following forms:
  45  *
  46  * <ol>
  47  *   <li><p> <a id="lform">The preferred form</a> is x:x:x:x:x:x:x:x,
  48  *   where the 'x's are
  49  *   the hexadecimal values of the eight 16-bit pieces of the
  50  *   address. This is the full form.  For example,
  51  *
  52  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
  53  *   <tr><td>{@code 1080:0:0:0:8:800:200C:417A}<td></tr>
  54  *   </table></blockquote>
  55  *
  56  *   <p> Note that it is not necessary to write the leading zeros in
  57  *   an individual field. However, there must be at least one numeral
  58  *   in every field, except as described below.</li>
  59  *
  60  *   <li><p> Due to some methods of allocating certain styles of IPv6
  61  *   addresses, it will be common for addresses to contain long
  62  *   strings of zero bits. In order to make writing addresses
  63  *   containing zero bits easier, a special syntax is available to
  64  *   compress the zeros. The use of "::" indicates multiple groups
  65  *   of 16-bits of zeros. The "::" can only appear once in an address.
  66  *   The "::" can also be used to compress the leading and/or trailing
  67  *   zeros in an address. For example,
  68  *
  69  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
  70  *   <tr><td>{@code 1080::8:800:200C:417A}<td></tr>
  71  *   </table></blockquote>
  72  *
  73  *   <li><p> An alternative form that is sometimes more convenient
  74  *   when dealing with a mixed environment of IPv4 and IPv6 nodes is
  75  *   x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
  76  *   of the six high-order 16-bit pieces of the address, and the 'd's
  77  *   are the decimal values of the four low-order 8-bit pieces of the
  78  *   standard IPv4 representation address, for example,
  79  *
  80  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
  81  *   <tr><td>{@code ::FFFF:129.144.52.38}<td></tr>
  82  *   <tr><td>{@code ::129.144.52.38}<td></tr>
  83  *   </table></blockquote>
  84  *
  85  *   <p> where "::FFFF:d.d.d.d" and "::d.d.d.d" are, respectively, the
  86  *   general forms of an IPv4-mapped IPv6 address and an
  87  *   IPv4-compatible IPv6 address. Note that the IPv4 portion must be
  88  *   in the "d.d.d.d" form. The following forms are invalid:
  89  *
  90  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
  91  *   <tr><td>{@code ::FFFF:d.d.d}<td></tr>
  92  *   <tr><td>{@code ::FFFF:d.d}<td></tr>
  93  *   <tr><td>{@code ::d.d.d}<td></tr>
  94  *   <tr><td>{@code ::d.d}<td></tr>
  95  *   </table></blockquote>
  96  *
  97  *   <p> The following form:
  98  *
  99  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
 100  *   <tr><td>{@code ::FFFF:d}<td></tr>
 101  *   </table></blockquote>
 102  *
 103  *   <p> is valid, however it is an unconventional representation of
 104  *   the IPv4-compatible IPv6 address,
 105  *
 106  *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
 107  *   <tr><td>{@code ::255.255.0.d}<td></tr>
 108  *   </table></blockquote>
 109  *
 110  *   <p> while "::d" corresponds to the general IPv6 address
 111  *   "0:0:0:0:0:0:0:d".</li>
 112  * </ol>
 113  *
 114  * <p> For methods that return a textual representation as output
 115  * value, the full form is used. Inet6Address will return the full
 116  * form because it is unambiguous when used in combination with other
 117  * textual data.
 118  *
 119  * <h4> Special IPv6 address </h4>
 120  *
 121  * <blockquote>
 122  * <table cellspacing=2 summary="Description of IPv4-mapped address">
 123  * <tr><th valign=top><i>IPv4-mapped address</i></th>
 124  *         <td>Of the form::ffff:w.x.y.z, this IPv6 address is used to

 125  *         represent an IPv4 address. It allows the native program to
 126  *         use the same address data structure and also the same
 127  *         socket when communicating with both IPv4 and IPv6 nodes.
 128  *
 129  *         <p>In InetAddress and Inet6Address, it is used for internal
 130  *         representation; it has no functional role. Java will never
 131  *         return an IPv4-mapped address.  These classes can take an
 132  *         IPv4-mapped address as input, both in byte array and text
 133  *         representation. However, it will be converted into an IPv4
 134  *         address.</td></tr>
 135  * </table></blockquote>
 136  *
 137  * <h4><a id="scoped">Textual representation of IPv6 scoped addresses</a></h4>
 138  *
 139  * <p> The textual representation of IPv6 addresses as described above can be
 140  * extended to specify IPv6 scoped addresses. This extension to the basic
 141  * addressing architecture is described in [draft-ietf-ipngwg-scoping-arch-04.txt].
 142  *
 143  * <p> Because link-local and site-local addresses are non-global, it is possible
 144  * that different hosts may have the same destination address and may be




  32 import java.io.ObjectStreamField;
  33 import java.util.Enumeration;
  34 import java.util.Arrays;
  35 
  36 /**
  37  * This class represents an Internet Protocol version 6 (IPv6) address.
  38  * Defined by <a href="http://www.ietf.org/rfc/rfc2373.txt">
  39  * <i>RFC&nbsp;2373: IP Version 6 Addressing Architecture</i></a>.
  40  *
  41  * <h3> <a id="format">Textual representation of IP addresses</a> </h3>
  42  *
  43  * Textual representation of IPv6 address used as input to methods
  44  * takes one of the following forms:
  45  *
  46  * <ol>
  47  *   <li><p> <a id="lform">The preferred form</a> is x:x:x:x:x:x:x:x,
  48  *   where the 'x's are
  49  *   the hexadecimal values of the eight 16-bit pieces of the
  50  *   address. This is the full form.  For example,
  51  *
  52  *   <blockquote><ul style="list-style-type:none">
  53  *   <li>{@code 1080:0:0:0:8:800:200C:417A}</li>
  54  *   </ul></blockquote>
  55  *
  56  *   <p> Note that it is not necessary to write the leading zeros in
  57  *   an individual field. However, there must be at least one numeral
  58  *   in every field, except as described below.</li>
  59  *
  60  *   <li><p> Due to some methods of allocating certain styles of IPv6
  61  *   addresses, it will be common for addresses to contain long
  62  *   strings of zero bits. In order to make writing addresses
  63  *   containing zero bits easier, a special syntax is available to
  64  *   compress the zeros. The use of "::" indicates multiple groups
  65  *   of 16-bits of zeros. The "::" can only appear once in an address.
  66  *   The "::" can also be used to compress the leading and/or trailing
  67  *   zeros in an address. For example,
  68  *
  69  *   <blockquote><ul style="list-style-type:none">
  70  *   <li>{@code 1080::8:800:200C:417A}</li>
  71  *   </ul></blockquote>
  72  *
  73  *   <li><p> An alternative form that is sometimes more convenient
  74  *   when dealing with a mixed environment of IPv4 and IPv6 nodes is
  75  *   x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
  76  *   of the six high-order 16-bit pieces of the address, and the 'd's
  77  *   are the decimal values of the four low-order 8-bit pieces of the
  78  *   standard IPv4 representation address, for example,
  79  *
  80  *   <blockquote><ul style="list-style-type:none">
  81  *   <li>{@code ::FFFF:129.144.52.38}</li>
  82  *   <li>{@code ::129.144.52.38}</li>
  83  *   </ul></blockquote>
  84  *
  85  *   <p> where "::FFFF:d.d.d.d" and "::d.d.d.d" are, respectively, the
  86  *   general forms of an IPv4-mapped IPv6 address and an
  87  *   IPv4-compatible IPv6 address. Note that the IPv4 portion must be
  88  *   in the "d.d.d.d" form. The following forms are invalid:
  89  *
  90  *   <blockquote><ul style="list-style-type:none">
  91  *   <li>{@code ::FFFF:d.d.d}</li>
  92  *   <li>{@code ::FFFF:d.d}</li>
  93  *   <li>{@code ::d.d.d}</li>
  94  *   <li>{@code ::d.d}</li>
  95  *   </ul></blockquote>
  96  *
  97  *   <p> The following form:
  98  *
  99  *   <blockquote><ul style="list-style-type:none">
 100  *   <li>{@code ::FFFF:d}</li>
 101  *   </ul></blockquote>
 102  *
 103  *   <p> is valid, however it is an unconventional representation of
 104  *   the IPv4-compatible IPv6 address,
 105  *
 106  *   <blockquote><ul style="list-style-type:none">
 107  *   <li>{@code ::255.255.0.d}</li>
 108  *   </ul></blockquote>
 109  *
 110  *   <p> while "::d" corresponds to the general IPv6 address
 111  *   "0:0:0:0:0:0:0:d".</li>
 112  * </ol>
 113  *
 114  * <p> For methods that return a textual representation as output
 115  * value, the full form is used. Inet6Address will return the full
 116  * form because it is unambiguous when used in combination with other
 117  * textual data.
 118  *
 119  * <h4> Special IPv6 address </h4>
 120  *
 121  * <blockquote>
 122  * <table class="borderless">
 123  * <caption style="display:none">Description of IPv4-mapped address</caption>
 124  * <tr><th style="vertical-align:top; padding-right:2px"><i>IPv4-mapped address</i></th>
 125  *         <td>Of the form ::ffff:w.x.y.z, this IPv6 address is used to
 126  *         represent an IPv4 address. It allows the native program to
 127  *         use the same address data structure and also the same
 128  *         socket when communicating with both IPv4 and IPv6 nodes.
 129  *
 130  *         <p>In InetAddress and Inet6Address, it is used for internal
 131  *         representation; it has no functional role. Java will never
 132  *         return an IPv4-mapped address.  These classes can take an
 133  *         IPv4-mapped address as input, both in byte array and text
 134  *         representation. However, it will be converted into an IPv4
 135  *         address.</td></tr>
 136  * </table></blockquote>
 137  *
 138  * <h4><a id="scoped">Textual representation of IPv6 scoped addresses</a></h4>
 139  *
 140  * <p> The textual representation of IPv6 addresses as described above can be
 141  * extended to specify IPv6 scoped addresses. This extension to the basic
 142  * addressing architecture is described in [draft-ietf-ipngwg-scoping-arch-04.txt].
 143  *
 144  * <p> Because link-local and site-local addresses are non-global, it is possible
 145  * that different hosts may have the same destination address and may be


< prev index next >