jdk/src/share/classes/java/net/Inet6Address.java
author juh
Wed, 10 Jul 2013 18:01:22 -0700
changeset 18800 e7fa560afcfb
parent 17198 32db080a2a70
child 19069 1d9cb0d080e3
child 20831 96cf18811858
permissions -rw-r--r--
8020318: Fix doclint issues in java.net Reviewed-by: darcy, khazra
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InvalidObjectException;
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
    30
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class represents an Internet Protocol version 6 (IPv6) address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Defined by <a href="http://www.ietf.org/rfc/rfc2373.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <i>RFC&nbsp;2373: IP Version 6 Addressing Architecture</i></a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17198
diff changeset
    38
 * <h3> <A NAME="format">Textual representation of IP addresses</a> </h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Textual representation of IPv6 address used as input to methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * takes one of the following forms:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *   <li><p> <A NAME="lform">The preferred form</a> is x:x:x:x:x:x:x:x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   where the 'x's are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   the hexadecimal values of the eight 16-bit pieces of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   address. This is the full form.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   <tr><td><tt>1080:0:0:0:8:800:200C:417A</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   <p> Note that it is not necessary to write the leading zeros in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   an individual field. However, there must be at least one numeral
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   in every field, except as described below.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <li><p> Due to some methods of allocating certain styles of IPv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   addresses, it will be common for addresses to contain long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   strings of zero bits. In order to make writing addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   containing zero bits easier, a special syntax is available to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   compress the zeros. The use of "::" indicates multiple groups
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   of 16-bits of zeros. The "::" can only appear once in an address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   The "::" can also be used to compress the leading and/or trailing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   zeros in an address. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <tr><td><tt>1080::8:800:200C:417A</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   <li><p> An alternative form that is sometimes more convenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   when dealing with a mixed environment of IPv4 and IPv6 nodes is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   of the six high-order 16-bit pieces of the address, and the 'd's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   are the decimal values of the four low-order 8-bit pieces of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   standard IPv4 representation address, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   <tr><td><tt>::FFFF:129.144.52.38</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   <tr><td><tt>::129.144.52.38</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   <p> where "::FFFF:d.d.d.d" and "::d.d.d.d" are, respectively, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   general forms of an IPv4-mapped IPv6 address and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   IPv4-compatible IPv6 address. Note that the IPv4 portion must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   in the "d.d.d.d" form. The following forms are invalid:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *   <tr><td><tt>::FFFF:d.d.d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   <tr><td><tt>::FFFF:d.d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *   <tr><td><tt>::d.d.d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *   <tr><td><tt>::d.d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   <p> The following form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *   <tr><td><tt>::FFFF:d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   <p> is valid, however it is an unconventional representation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   the IPv4-compatible IPv6 address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *   <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *   <tr><td><tt>::255.255.0.d</tt><td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *   </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *   <p> while "::d" corresponds to the general IPv6 address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *   "0:0:0:0:0:0:0:d".</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p> For methods that return a textual representation as output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * value, the full form is used. Inet6Address will return the full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * form because it is unambiguous when used in combination with other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * textual data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <h4> Special IPv6 address </h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <blockquote>
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   119
 * <table cellspacing=2 summary="Description of IPv4-mapped address">
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   120
 * <tr><th valign=top><i>IPv4-mapped address</i></th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *         <td>Of the form::ffff:w.x.y.z, this IPv6 address is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *         represent an IPv4 address. It allows the native program to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *         use the same address data structure and also the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *         socket when communicating with both IPv4 and IPv6 nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *         <p>In InetAddress and Inet6Address, it is used for internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *         representation; it has no functional role. Java will never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *         return an IPv4-mapped address.  These classes can take an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *         IPv4-mapped address as input, both in byte array and text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *         representation. However, it will be converted into an IPv4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *         address.</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * </table></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * <p>
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   134
 * <h4><A NAME="scoped">Textual representation of IPv6 scoped addresses</a></h4>
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   135
 *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   136
 * <p> The textual representation of IPv6 addresses as described above can be
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   137
 * extended to specify IPv6 scoped addresses. This extension to the basic
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   138
 * addressing architecture is described in [draft-ietf-ipngwg-scoping-arch-04.txt].
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   139
 *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   140
 * <p> Because link-local and site-local addresses are non-global, it is possible
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   141
 * that different hosts may have the same destination address and may be
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   142
 * reachable through different interfaces on the same originating system. In
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   143
 * this case, the originating system is said to be connected to multiple zones
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   144
 * of the same scope. In order to disambiguate which is the intended destination
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   145
 * zone, it is possible to append a zone identifier (or <i>scope_id</i>) to an
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   146
 * IPv6 address.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   147
 *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   148
 * <p> The general format for specifying the <i>scope_id</i> is the following:
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   149
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <p><blockquote><i>IPv6-address</i>%<i>scope_id</i></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <p> The IPv6-address is a literal IPv6 address as described above.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   152
 * The <i>scope_id</i> refers to an interface on the local system, and it can be
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   153
 * specified in two ways.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   154
 * <p><ol><li><i>As a numeric identifier.</i> This must be a positive integer
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   155
 * that identifies the particular interface and scope as understood by the
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   156
 * system. Usually, the numeric values can be determined through administration
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   157
 * tools on the system. Each interface may have multiple values, one for each
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   158
 * scope. If the scope is unspecified, then the default value used is zero.</li>
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17198
diff changeset
   159
 * <li><i>As a string.</i> This must be the exact string that is returned by
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   160
 * {@link java.net.NetworkInterface#getName()} for the particular interface in
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   161
 * question. When an Inet6Address is created in this way, the numeric scope-id
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   162
 * is determined at the time the object is created by querying the relevant
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   163
 * NetworkInterface.</li></ol>
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   164
 *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   165
 * <p> Note also, that the numeric <i>scope_id</i> can be retrieved from
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   166
 * Inet6Address instances returned from the NetworkInterface class. This can be
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   167
 * used to find out the current scope ids configured on the system.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
class Inet6Address extends InetAddress {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    final static int INADDRSZ = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * cached scope_id - for link-local address use only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   178
    private transient int cached_scope_id;  // 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Holds a 128-bit (16 bytes) IPv6 address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    byte[] ipaddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   188
     * scope_id. The scope specified when the object is created. If the object
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   189
     * is created with an interface name, then the scope_id is not determined
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   190
     * until the time it is needed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   192
    private int scope_id;  // 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * This will be set to true when the scope_id field contains a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * integer scope_id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   198
    private boolean scope_id_set;  // false
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * scoped interface. scope_id is derived from this as the scope_id of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * address whose scope is the same as this address for the named interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   204
    private transient NetworkInterface scope_ifname;  // null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   206
    /**
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   207
     * set if the object is constructed with a scoped
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   208
     * interface instead of a numeric scope id.
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   209
     */
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   210
    private boolean scope_ifname_set; // false;
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   211
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    private static final long serialVersionUID = 6880410070516793377L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   214
    // Perform native initialization
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   215
    static { init(); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    Inet6Address() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super();
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   219
        holder().hostName = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        ipaddress = new byte[INADDRSZ];
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   221
        holder().family = IPv6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /* checking of value for scope_id should be done by caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * scope_id must be >= 0, or -1 to indicate not being set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    Inet6Address(String hostName, byte addr[], int scope_id) {
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   228
        holder().hostName = hostName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (addr.length == INADDRSZ) { // normal IPv6 address
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   230
            holder().family = IPv6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            ipaddress = addr.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (scope_id >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            this.scope_id = scope_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            scope_id_set = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    Inet6Address(String hostName, byte addr[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            initif (hostName, addr, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } catch (UnknownHostException e) {} /* cant happen if ifname is null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   245
    Inet6Address (String hostName, byte addr[], NetworkInterface nif)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   246
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   247
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        initif (hostName, addr, nif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   251
    Inet6Address (String hostName, byte addr[], String ifname)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   252
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   253
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        initstr (hostName, addr, ifname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   258
     * Create an Inet6Address in the exact manner of {@link
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   259
     * InetAddress#getByAddress(String,byte[])} except that the IPv6 scope_id is
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   260
     * set to the value corresponding to the given interface for the address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   261
     * type specified in <code>addr</code>. The call will fail with an
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   262
     * UnknownHostException if the given interface does not have a numeric
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * scope_id assigned for the given address type (eg. link-local or site-local).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * See <a href="Inet6Address.html#scoped">here</a> for a description of IPv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * scoped addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param host the specified host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param addr the raw IP address in network byte order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param nif an interface this address must be associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return  an Inet6Address object created from the raw IP address.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   271
     * @throws  UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   272
     *          if IP address is of illegal length, or if the interface does not
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   273
     *          have a numeric scope_id assigned for the given address type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   277
    public static Inet6Address getByAddress(String host, byte[] addr,
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   278
                                            NetworkInterface nif)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   279
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   280
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (host != null && host.length() > 0 && host.charAt(0) == '[') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (host.charAt(host.length()-1) == ']') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                host = host.substring(1, host.length() -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (addr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (addr.length == Inet6Address.INADDRSZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                return new Inet6Address(host, addr, nif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        throw new UnknownHostException("addr is of illegal length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   295
     * Create an Inet6Address in the exact manner of {@link
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   296
     * InetAddress#getByAddress(String,byte[])} except that the IPv6 scope_id is
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   297
     * set to the given numeric value. The scope_id is not checked to determine
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   298
     * if it corresponds to any interface on the system.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * See <a href="Inet6Address.html#scoped">here</a> for a description of IPv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * scoped addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param host the specified host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param addr the raw IP address in network byte order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param scope_id the numeric scope_id for the address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return  an Inet6Address object created from the raw IP address.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   306
     * @throws  UnknownHostException  if IP address is of illegal length.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   310
    public static Inet6Address getByAddress(String host, byte[] addr,
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   311
                                            int scope_id)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   312
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   313
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (host != null && host.length() > 0 && host.charAt(0) == '[') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (host.charAt(host.length()-1) == ']') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                host = host.substring(1, host.length() -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (addr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (addr.length == Inet6Address.INADDRSZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return new Inet6Address(host, addr, scope_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        throw new UnknownHostException("addr is of illegal length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   327
    private void initstr(String hostName, byte addr[], String ifname)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   328
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   329
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            NetworkInterface nif = NetworkInterface.getByName (ifname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (nif == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                throw new UnknownHostException ("no such interface " + ifname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            initif (hostName, addr, nif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        } catch (SocketException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            throw new UnknownHostException ("SocketException thrown" + ifname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   341
    private void initif(String hostName, byte addr[], NetworkInterface nif)
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   342
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   343
    {
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   344
        holder().hostName = hostName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (addr.length == INADDRSZ) { // normal IPv6 address
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   346
            holder().family = IPv6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            ipaddress = addr.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (nif != null) {
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   350
            scope_ifname = nif;
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   351
            scope_id = deriveNumericScope(nif);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            scope_id_set = true;
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   353
            scope_ifname_set = true;  // for consistency
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /* check the two Ipv6 addresses and return false if they are both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * non global address types, but not the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * (ie. one is sitelocal and the other linklocal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * return true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private boolean differentLocalAddressTypes(Inet6Address other) {
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   363
        if (isLinkLocalAddress() && !other.isLinkLocalAddress())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            return false;
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   365
        if (isSiteLocalAddress() && !other.isSiteLocalAddress())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   370
    private int deriveNumericScope(NetworkInterface ifc)
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   371
        throws UnknownHostException
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   372
    {
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   373
        Enumeration<InetAddress> addresses = ifc.getInetAddresses();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        while (addresses.hasMoreElements()) {
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   375
            InetAddress addr = addresses.nextElement();
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   376
            if (!(addr instanceof Inet6Address)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   379
            Inet6Address ia6_addr = (Inet6Address)addr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            /* check if site or link local prefixes match */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (!differentLocalAddressTypes(ia6_addr)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                /* type not the same, so carry on searching */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            /* found a matching address - return its scope_id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return ia6_addr.scope_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        throw new UnknownHostException ("no scope_id found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   391
    private int deriveNumericScope(String ifname) throws UnknownHostException {
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   392
        Enumeration<NetworkInterface> en;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            en = NetworkInterface.getNetworkInterfaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        } catch (SocketException e) {
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   396
            throw new UnknownHostException(
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   397
                    "could not enumerate local network interfaces");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        while (en.hasMoreElements()) {
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   400
            NetworkInterface ifc = en.nextElement();
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   401
            if (ifc.getName().equals(ifname)) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 7668
diff changeset
   402
                Enumeration<InetAddress> addresses = ifc.getInetAddresses();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                while (addresses.hasMoreElements()) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 7668
diff changeset
   404
                    InetAddress addr = addresses.nextElement();
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   405
                    if (!(addr instanceof Inet6Address)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    }
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   408
                    Inet6Address ia6_addr = (Inet6Address)addr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    /* check if site or link local prefixes match */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    if (!differentLocalAddressTypes(ia6_addr)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        /* type not the same, so carry on searching */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    /* found a matching address - return its scope_id */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    return ia6_addr.scope_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   419
        throw new UnknownHostException(
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   420
                "No matching address found for interface : " +ifname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * restore the state of this object from stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * including the scope information, only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * scoped interface name is valid on this system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        throws IOException, ClassNotFoundException {
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   430
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   431
        if (getClass().getClassLoader() != null) {
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   432
            throw new SecurityException ("invalid address type");
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   433
        }
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   434
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   437
        if (ifname != null && !ifname.equals("")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                scope_ifname = NetworkInterface.getByName(ifname);
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   440
                if (scope_ifname != null) {
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   441
                    scope_ifname_set = true;
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   442
                    try {
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   443
                        scope_id = deriveNumericScope(scope_ifname);
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   444
                    } catch (UnknownHostException e) {
6004
f88fd15b64b9 6966846: Incorrect assertion in java.net.Inet6Address.readObject
chegar
parents: 5506
diff changeset
   445
                        // typically should not happen, but it may be that
f88fd15b64b9 6966846: Incorrect assertion in java.net.Inet6Address.readObject
chegar
parents: 5506
diff changeset
   446
                        // the machine being used for deserialization has
f88fd15b64b9 6966846: Incorrect assertion in java.net.Inet6Address.readObject
chegar
parents: 5506
diff changeset
   447
                        // the same interface name but without IPv6 configured.
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   448
                    }
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   449
                } else {
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   450
                    /* the interface does not exist on this system, so we clear
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   451
                     * the scope information completely */
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   452
                    scope_id_set = false;
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   453
                    scope_ifname_set = false;
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   454
                    scope_id = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            } catch (SocketException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        /* if ifname was not supplied, then the numeric info is used */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        ipaddress = ipaddress.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        // Check that our invariants are satisfied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (ipaddress.length != INADDRSZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            throw new InvalidObjectException("invalid address length: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                             ipaddress.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
16870
f35b2bd19761 8000724: Improve networking serialization
michaelm
parents: 14783
diff changeset
   469
        if (holder().getFamily() != IPv6) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            throw new InvalidObjectException("invalid address family type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Utility routine to check if the InetAddress is an IP multicast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * address. 11111111 at the start of the address identifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * address as being a multicast address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   479
     * @return a {@code boolean} indicating if the InetAddress is an IP
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   480
     *         multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   481
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   484
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public boolean isMulticastAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return ((ipaddress[0] & 0xff) == 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Utility routine to check if the InetAddress in a wildcard address.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   491
     *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   492
     * @return a {@code boolean} indicating if the Inetaddress is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *         a wildcard address.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   494
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   497
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public boolean isAnyLocalAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        byte test = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        for (int i = 0; i < INADDRSZ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            test |= ipaddress[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return (test == 0x00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Utility routine to check if the InetAddress is a loopback address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   509
     * @return a {@code boolean} indicating if the InetAddress is a loopback
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   510
     *         address; or false otherwise.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   511
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   514
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public boolean isLoopbackAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        byte test = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        for (int i = 0; i < 15; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            test |= ipaddress[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return (test == 0x00) && (ipaddress[15] == 0x01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Utility routine to check if the InetAddress is an link local address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   526
     * @return a {@code boolean} indicating if the InetAddress is a link local
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   527
     *         address; or false if address is not a link local unicast address.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   528
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   531
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public boolean isLinkLocalAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return ((ipaddress[0] & 0xff) == 0xfe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                && (ipaddress[1] & 0xc0) == 0x80);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Utility routine to check if the InetAddress is a site local address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   540
     * @return a {@code boolean} indicating if the InetAddress is a site local
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   541
     *         address; or false if address is not a site local unicast address.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   542
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   545
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public boolean isSiteLocalAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return ((ipaddress[0] & 0xff) == 0xfe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                && (ipaddress[1] & 0xc0) == 0xc0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Utility routine to check if the multicast address has global scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   554
     * @return a {@code boolean} indicating if the address has is a multicast
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   555
     *         address of global scope, false if it is not of global scope or
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   556
     *         it is not a multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   557
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   560
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public boolean isMCGlobal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return ((ipaddress[0] & 0xff) == 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                && (ipaddress[1] & 0x0f) == 0x0e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Utility routine to check if the multicast address has node scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   569
     * @return a {@code boolean} indicating if the address has is a multicast
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   570
     *         address of node-local scope, false if it is not of node-local
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   571
     *         scope or it is not a multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   572
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   575
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    public boolean isMCNodeLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return ((ipaddress[0] & 0xff) == 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                && (ipaddress[1] & 0x0f) == 0x01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Utility routine to check if the multicast address has link scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   584
     * @return a {@code boolean} indicating if the address has is a multicast
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   585
     *         address of link-local scope, false if it is not of link-local
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   586
     *         scope or it is not a multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   587
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   590
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public boolean isMCLinkLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return ((ipaddress[0] & 0xff) == 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                && (ipaddress[1] & 0x0f) == 0x02);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Utility routine to check if the multicast address has site scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   599
     * @return a {@code boolean} indicating if the address has is a multicast
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   600
     *         address of site-local scope, false if it is not  of site-local
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   601
     *         scope or it is not a multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   602
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   605
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public boolean isMCSiteLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        return ((ipaddress[0] & 0xff) == 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                && (ipaddress[1] & 0x0f) == 0x05);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Utility routine to check if the multicast address has organization scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   614
     * @return a {@code boolean} indicating if the address has is a multicast
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   615
     *         address of organization-local scope, false if it is not of
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   616
     *         organization-local scope or it is not a multicast address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   617
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   620
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public boolean isMCOrgLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return ((ipaddress[0] & 0xff) == 0xff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                && (ipaddress[1] & 0x0f) == 0x08);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   627
     * Returns the raw IP address of this {@code InetAddress} object. The result
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   628
     * is in network byte order: the highest order byte of the address is in
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   629
     * {@code getAddress()[0]}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @return  the raw IP address of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   633
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public byte[] getAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return ipaddress.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Returns the numeric scopeId, if this instance is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * an interface. If no scoped_id is set, the returned value is zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @return the scopeId, or zero if not set.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   643
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   646
     public int getScopeId() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return scope_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Returns the scoped interface, if this instance was created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * with a scoped interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return the scoped interface, or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   657
     public NetworkInterface getScopedInterface() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return scope_ifname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   662
     * Returns the IP address string in textual presentation. If the instance
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   663
     * was created specifying a scope identifier then the scope id is appended
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   664
     * to the IP address preceded by a "%" (per-cent) character. This can be
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   665
     * either a numeric value or a string, depending on which was used to create
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   666
     * the instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @return  the raw IP address in a string format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   670
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public String getHostAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        String s = numericToTextFormat(ipaddress);
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   673
        if (scope_ifname != null) { /* must check this first */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            s = s + "%" + scope_ifname.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        } else if (scope_id_set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            s = s + "%" + scope_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Returns a hashcode for this IP address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @return  a hash code value for this IP address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   686
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (ipaddress != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            int hash = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            while (i<INADDRSZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                int j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                int component=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                while (j<4 && i<INADDRSZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    component = (component << 8) + ipaddress[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                hash += component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    /**
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   710
     * Compares this object against the specified object. The result is {@code
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   711
     * true} if and only if the argument is not {@code null} and it represents
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   712
     * the same IP address as this object.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   713
     *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   714
     * <p> Two instances of {@code InetAddress} represent the same IP address
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   715
     * if the length of the byte arrays returned by {@code getAddress} is the
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   716
     * same for both, and each of the array components is the same for the byte
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   717
     * arrays.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @param   obj   the object to compare against.
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   720
     *
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   721
     * @return  {@code true} if the objects are the same; {@code false} otherwise.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   722
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @see     java.net.InetAddress#getAddress()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
902
bbfb1e2369b2 6656849: NullPointerException thrown while de-serializing IPV6 Address.
jccollet
parents: 2
diff changeset
   725
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public boolean equals(Object obj) {
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   727
        if (obj == null || !(obj instanceof Inet6Address))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        Inet6Address inetAddr = (Inet6Address)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        for (int i = 0; i < INADDRSZ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if (ipaddress[i] != inetAddr.ipaddress[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Utility routine to check if the InetAddress is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * IPv4 compatible IPv6 address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   743
     * @return a {@code boolean} indicating if the InetAddress is an IPv4
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   744
     *         compatible IPv6 address; or false if address is IPv4 address.
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   745
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public boolean isIPv4CompatibleAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        if ((ipaddress[0] == 0x00) && (ipaddress[1] == 0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            (ipaddress[2] == 0x00) && (ipaddress[3] == 0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            (ipaddress[4] == 0x00) && (ipaddress[5] == 0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            (ipaddress[6] == 0x00) && (ipaddress[7] == 0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            (ipaddress[8] == 0x00) && (ipaddress[9] == 0x00) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            (ipaddress[10] == 0x00) && (ipaddress[11] == 0x00))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    // Utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    private final static int INT16SZ = 2;
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   762
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Convert IPv6 binary address into presentation (printable) format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @param src a byte array representing the IPv6 numeric address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @return a String representing an IPv6 address in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *         textual representation format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
14783
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   771
    static String numericToTextFormat(byte[] src) {
2ecc993a8e67 8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents: 10596
diff changeset
   772
        StringBuilder sb = new StringBuilder(39);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        for (int i = 0; i < (INADDRSZ / INT16SZ); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            sb.append(Integer.toHexString(((src[i<<1]<<8) & 0xff00)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                          | (src[(i<<1)+1] & 0xff)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (i < (INADDRSZ / INT16SZ) -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
               sb.append(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * Perform class load-time initializations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    private static native void init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Following field is only used during (de)/serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    private String ifname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * default behavior is overridden in order to write the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * scope_ifname field as a String, rather than a NetworkInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * which is not serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    {
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   801
        if (scope_ifname != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            ifname = scope_ifname.getName();
17198
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   803
            scope_ifname_set = true;
32db080a2a70 8007373: Inet6Address serialization incompatibility
msheppar
parents: 16870
diff changeset
   804
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}