Top Description Inners Fields Constructors Methods
java.net

public final Class Inet6Address

extends InetAddress
Class Inheritance
Imports
sun.net.util.IPAddressUtil, java.io.IOException, .InvalidObjectException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, java.util.Enumeration, .Arrays, .Objects

This class represents an Internet Protocol version 6 (IPv6) address. Defined by RFC 2373: IP Version 6 Addressing Architecture.

Textual representation of IPv6 addresses

Textual representation of IPv6 address used as input to methods takes one of the following forms:
  1. The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the hexadecimal values of the eight 16-bit pieces of the address. This is the full form. For example,

    • 1080:0:0:0:8:800:200C:417A

    Note that it is not necessary to write the leading zeros in an individual field. However, there must be at least one numeral in every field, except as described below.

  2. Due to some methods of allocating certain styles of IPv6 addresses, it will be common for addresses to contain long strings of zero bits. In order to make writing addresses containing zero bits easier, a special syntax is available to compress the zeros. The use of "::" indicates multiple groups of 16-bits of zeros. The "::" can only appear once in an address. The "::" can also be used to compress the leading and/or trailing zeros in an address. For example,

    • 1080::8:800:200C:417A
  3. An alternative form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values of the six high-order 16-bit pieces of the address, and the 'd's are the decimal values of the four low-order 8-bit pieces of the standard IPv4 representation address, for example,

    • ::FFFF:129.144.52.38
    • ::129.144.52.38

    where "::FFFF:d.d.d.d" and "::d.d.d.d" are, respectively, the general forms of an IPv4-mapped IPv6 address and an IPv4-compatible IPv6 address. Note that the IPv4 portion must be in the "d.d.d.d" form. The following forms are invalid:

    • ::FFFF:d.d.d
    • ::FFFF:d.d
    • ::d.d.d
    • ::d.d

    The following form:

    • ::FFFF:d

    is valid, however it is an unconventional representation of the IPv4-compatible IPv6 address,

    • ::255.255.0.d

    while "::d" corresponds to the general IPv6 address "0:0:0:0:0:0:0:d".

For methods that return a textual representation as output value, the full form is used. Inet6Address will return the full form because it is unambiguous when used in combination with other textual data.

Special IPv6 address

IPv4-mapped address
Of the form ::ffff:w.x.y.z, this IPv6 address is used to represent an IPv4 address. It allows the native program to use the same address data structure and also the same socket when communicating with both IPv4 and IPv6 nodes.

In InetAddress and Inet6Address, it is used for internal representation; it has no functional role. Java will never return an IPv4-mapped address. These classes can take an IPv4-mapped address as input, both in byte array and text representation. However, it will be converted into an IPv4 address.

Textual representation of IPv6 scoped addresses

The textual representation of IPv6 addresses as described above can be extended to specify IPv6 scoped addresses. This extension to the basic addressing architecture is described in RFC 4007: IPv6 Scoped Address Architecture.

Because link-local and site-local addresses are non-global, it is possible that different hosts may have the same destination address and may be reachable through different interfaces on the same originating system. In this case, the originating system is said to be connected to multiple zones of the same scope. In order to disambiguate which is the intended destination zone, it is possible to append a zone identifier (or scope_id) to an IPv6 address.

The general format for specifying the scope_id is the following:

IPv6-address%scope_id

The IPv6-address is a literal IPv6 address as described above. The scope_id refers to an interface on the local system, and it can be specified in two ways.

  1. As a numeric identifier. This must be a positive integer that identifies the particular interface and scope as understood by the system. Usually, the numeric values can be determined through administration tools on the system. Each interface may have multiple values, one for each scope. If the scope is unspecified, then the default value used is zero.
  2. As a string. This must be the exact string that is returned by java.net.NetworkInterface#getName() for the particular interface in question. When an Inet6Address is created in this way, the numeric scope-id is determined at the time the object is created by querying the relevant NetworkInterface.

Note also, that the numeric scope_id can be retrieved from Inet6Address instances returned from the NetworkInterface class. This can be used to find out the current scope ids configured on the system.

Textual representation of IPv6 addresses as method inputs

Methods of InetAddress and Inet6Address that accept a textual representation of an IPv6 address allow for that representation to be enclosed in square brackets. For example,

// The full IPv6 form InetAddress.getByName("1080:0:0:0:8:800:200C:417A"); // ==> /1080:0:0:0:8:800:200c:417a InetAddress.getByName("[1080:0:0:0:8:800:200C:417A]"); // ==> /1080:0:0:0:8:800:200c:417a // IPv6 scoped address with scope-id as string Inet6Address.ofLiteral("fe80::1%en0"); // ==> /fe80:0:0:0:0:0:0:1%en0 Inet6Address.ofLiteral("[fe80::1%en0]"); // ==> /fe80:0:0:0:0:0:0:1%en0
// The full IPv6 form
InetAddress.getByName("1080:0:0:0:8:800:200C:417A");   // ==> /1080:0:0:0:8:800:200c:417a
InetAddress.getByName("[1080:0:0:0:8:800:200C:417A]"); // ==> /1080:0:0:0:8:800:200c:417a

// IPv6 scoped address with scope-id as string
Inet6Address.ofLiteral("fe80::1%en0");   // ==> /fe80:0:0:0:0:0:0:1%en0
Inet6Address.ofLiteral("[fe80::1%en0]"); // ==> /fe80:0:0:0:0:0:0:1%en0
Since
1.4
External Specification
https://www.rfc-editor.org/info/rfc2373, https://www.rfc-editor.org/info/rfc4007

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final long
private final transient Inet6Address.Inet6AddressHolder
pack-priv static final int
private static final int
private static final ObjectStreamField[]
private static final long
private static final Unsafe
Inherited from java.net.InetAddress:
holderimplIPv4IPv6PLATFORM_LOOKUP_POLICY

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
Inet6Address(String hostName, byte[] addr, int scope_id)

pack-priv
Inet6Address(String hostName, byte[] addr)

pack-priv
Inet6Address(String hostName, byte[] addr, NetworkInterface nif)

pack-priv
Inet6Address(String hostName, byte[] addr, String ifname)

Method Summary

Modifier and TypeMethod and Description
pack-priv byte[]
addressBytes()

Returns a reference to the byte[] with the IPv6 address.

private static int
checkNumericZone(String s)

Check if the literal address string has %nn appended returns -1 if not, or the numeric value otherwise.

private static int
deriveNumericScope(byte[] thisAddr, NetworkInterface ifc)

private int
public boolean

Returns:

true if the objects are the same; false otherwise.
equals
(Object
the object to compare against.
obj
)

Overrides java.net.InetAddress.equals.

Compares this object against the specified object.

public byte[]

Returns:

the raw IP address of this object.
getAddress
()

Overrides java.net.InetAddress.getAddress.

Returns the raw IP address of this InetAddress object.

public static Inet6Address

Returns:

an Inet6Address object created from the raw IP address.
getByAddress
(String
the specified host
host
,
byte[]
the raw IP address in network byte order
addr
,
NetworkInterface
an interface this address must be associated with.
nif
)

Create an Inet6Address in the exact manner of InetAddress#getByAddress(String, byte[]) except that the IPv6 scope_id is set to the value corresponding to the given interface for the address type specified in addr.

public static Inet6Address

Returns:

an Inet6Address object created from the raw IP address.
getByAddress
(String
the specified host
host
,
byte[]
the raw IP address in network byte order
addr
,
int
the numeric scope_id for the address.
scope_id
)

Create an Inet6Address in the exact manner of InetAddress#getByAddress(String, byte[]) except that the IPv6 scope_id is set to the given numeric value.

public String

Returns:

the raw IP address in a string format.
getHostAddress
()

Overrides java.net.InetAddress.getHostAddress.

Returns the IP address string in textual presentation.

public NetworkInterface

Returns:

the scoped interface, or null if not set.
getScopedInterface
()

Returns the scoped interface, if this instance was created with a scoped interface.

public int

Returns:

the scopeId, or zero if not set.
getScopeId
()

Returns the numeric scopeId, if this instance is associated with an interface.

public int

Returns:

a hash code value for this IP address.
hashCode
()

Overrides java.net.InetAddress.hashCode.

Returns a hashcode for this IP address.

private static native void
init()

Hides java.net.InetAddress.init.

Perform class load-time initializations.

private void
initif(String hostName, byte[] addr, NetworkInterface nif)

private void
initstr(String hostName, byte[] addr, String ifname)

public boolean

Returns:

a boolean indicating if the InetAddress is a wildcard address.
isAnyLocalAddress
()

Overrides java.net.InetAddress.isAnyLocalAddress.

Utility routine to check if the InetAddress is a wildcard address.

private static boolean
isDifferentLocalAddressType(byte[] thisAddr, byte[] otherAddr)

public boolean

Returns:

a boolean indicating if the InetAddress is an IPv4 compatible IPv6 address; or false if address is IPv4 address.
isIPv4CompatibleAddress
()

Utility routine to check if the InetAddress is an IPv4 compatible IPv6 address.

public boolean

Returns:

a boolean indicating if the InetAddress is a link local address; or false if address is not a link local unicast address.
isLinkLocalAddress
()

Overrides java.net.InetAddress.isLinkLocalAddress.

Utility routine to check if the InetAddress is a link local address.

pack-priv static boolean
isLinkLocalAddress(byte[] ipaddress)

public boolean

Returns:

a boolean indicating if the InetAddress is a loopback address; or false otherwise.
isLoopbackAddress
()

Overrides java.net.InetAddress.isLoopbackAddress.

Utility routine to check if the InetAddress is a loopback address.

public boolean

Returns:

a boolean indicating if the address has is a multicast address of global scope, false if it is not of global scope or it is not a multicast address
isMCGlobal
()

Overrides java.net.InetAddress.isMCGlobal.

Utility routine to check if the multicast address has global scope.

public boolean

Returns:

a boolean indicating if the address has is a multicast address of link-local scope, false if it is not of link-local scope or it is not a multicast address
isMCLinkLocal
()

Overrides java.net.InetAddress.isMCLinkLocal.

Utility routine to check if the multicast address has link scope.

public boolean

Returns:

a boolean indicating if the address has is a multicast address of node-local scope, false if it is not of node-local scope or it is not a multicast address
isMCNodeLocal
()

Overrides java.net.InetAddress.isMCNodeLocal.

Utility routine to check if the multicast address has node scope.

public boolean

Returns:

a boolean indicating if the address has is a multicast address of organization-local scope, false if it is not of organization-local scope or it is not a multicast address
isMCOrgLocal
()

Overrides java.net.InetAddress.isMCOrgLocal.

Utility routine to check if the multicast address has organization scope.

public boolean

Returns:

a boolean indicating if the address has is a multicast address of site-local scope, false if it is not of site-local scope or it is not a multicast address
isMCSiteLocal
()

Overrides java.net.InetAddress.isMCSiteLocal.

Utility routine to check if the multicast address has site scope.

public boolean

Returns:

a boolean indicating if the InetAddress is an IP multicast address
isMulticastAddress
()

Overrides java.net.InetAddress.isMulticastAddress.

Utility routine to check if the InetAddress is an IP multicast address.

public boolean

Returns:

a boolean indicating if the InetAddress is a site local address; or false if address is not a site local unicast address.
isSiteLocalAddress
()

Overrides java.net.InetAddress.isSiteLocalAddress.

Utility routine to check if the InetAddress is a site local address.

pack-priv static boolean
isSiteLocalAddress(byte[] ipaddress)

pack-priv static String

Returns:

a String representing an IPv6 address in textual representation format
numericToTextFormat
(byte[]
a byte array representing the IPv6 numeric address
src
)

Convert IPv6 binary address into presentation (printable) format.

public static InetAddress

Returns:

an InetAddress object with no hostname set, and constructed from the provided IPv6 address literal.
ofLiteral
(String
the textual representation of an IPv6 address.
ipv6AddressLiteral
)

Hides java.net.InetAddress.ofLiteral.

Creates an InetAddress based on the provided textual representation of an IPv6 address.

pack-priv static InetAddress

Returns:

Inet6Address or Inet4Address object constructed from literal IP address string.
parseAddressString
(String
literal IP address
addressLiteral
,
boolean
if true remove outer square brackets
removeSqBrackets
)

Method tries to parse supplied IP address literal as IPv6, IPv4-compatible IPv6 or IPv4-mapped IPv6 address.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
s
)

Hides java.net.InetAddress.readObject.

Restores the state of this object from the stream.

private synchronized void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
s
)

Hides java.net.InetAddress.writeObject.

The default behavior of this method is overridden in order to write the scope_ifname field as a String, rather than a NetworkInterface which is not serializable.

Inherited from java.net.InetAddress:
anyLocalAddressgetAddressesFromNameServicegetAllByNamegetAllByName0getByAddressgetByAddressgetByNamegetCanonicalHostNamegetHostNamegetHostNamegetLocalHostgetLoopbackAddressholderipv4AddressesFirstipv6AddressesFirstisReachableisReachablesystemAddressesOrdertoString

Field Detail

FIELDS_OFFSETback to summary
private static final long FIELDS_OFFSET

Hides java.net.InetAddress.FIELDS_OFFSET.

holder6back to summary
private final transient Inet6Address.Inet6AddressHolder holder6
INADDRSZback to summary
pack-priv static final int INADDRSZ
INT16SZback to summary
private static final int INT16SZ
serialPersistentFieldsback to summary
private static final ObjectStreamField[] serialPersistentFields

Hides java.net.InetAddress.serialPersistentFields.

Annotations
@Serial
Serial Fields:
ipaddress:byte[]
holds a 128-bit (16 bytes) IPv6 address
scope_id:int
the address scope id. 0 if undefined
scope_id_set:boolean
true when the scope_id field contains a valid integer scope_id
scope_ifname_set:boolean
true if the object is constructed with a scoped interface instead of a numeric scope id
ifname:String
the name of the scoped network interface. null if undefined
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.net.InetAddress.serialVersionUID.

Annotations
@Serial
UNSAFEback to summary
private static final Unsafe UNSAFE

Hides java.net.InetAddress.UNSAFE.

Constructor Detail

Inet6Addressback to summary
pack-priv Inet6Address()
Inet6Addressback to summary
pack-priv Inet6Address(String hostName, byte[] addr, int scope_id)
Inet6Addressback to summary
pack-priv Inet6Address(String hostName, byte[] addr)
Inet6Addressback to summary
pack-priv Inet6Address(String hostName, byte[] addr, NetworkInterface nif) throws UnknownHostException
Inet6Addressback to summary
pack-priv Inet6Address(String hostName, byte[] addr, String ifname) throws UnknownHostException

Method Detail

addressBytesback to summary
pack-priv byte[] addressBytes()

Returns a reference to the byte[] with the IPv6 address.

checkNumericZoneback to summary
private static int checkNumericZone(String s)

Check if the literal address string has %nn appended returns -1 if not, or the numeric value otherwise.

%nn may also be a string that represents the displayName of a currently available NetworkInterface.

deriveNumericScopeback to summary
private static int deriveNumericScope(byte[] thisAddr, NetworkInterface ifc) throws UnknownHostException
deriveNumericScopeback to summary
private int deriveNumericScope(String ifname) throws UnknownHostException
equalsback to summary
public boolean equals(Object obj)

Overrides java.net.InetAddress.equals.

Compares this object against the specified object. The result is true if and only if the argument is not null and it represents the same IP address as this object.

Two instances of InetAddress represent the same IP address if the length of the byte arrays returned by getAddress is the same for both, and each of the array components is the same for the byte arrays.

Parameters
obj:Object

the object to compare against.

Returns:boolean

true if the objects are the same; false otherwise.

Annotations
@Override
See Also
java.net.InetAddress#getAddress()
getAddressback to summary
public byte[] getAddress()

Overrides java.net.InetAddress.getAddress.

Returns the raw IP address of this InetAddress object. The result is in network byte order: the highest order byte of the address is in getAddress()[0].

Returns:byte[]

the raw IP address of this object.

Annotations
@Override
getByAddressback to summary
public static Inet6Address getByAddress(String host, byte[] addr, NetworkInterface nif) throws UnknownHostException

Create an Inet6Address in the exact manner of InetAddress#getByAddress(String, byte[]) except that the IPv6 scope_id is set to the value corresponding to the given interface for the address type specified in addr. The call will fail with an UnknownHostException if the given interface does not have a numeric scope_id assigned for the given address type (e.g. link-local or site-local). See here for a description of IPv6 scoped addresses.

Parameters
host:String

the specified host

addr:byte[]

the raw IP address in network byte order

nif:NetworkInterface

an interface this address must be associated with.

Returns:Inet6Address

an Inet6Address object created from the raw IP address.

Exceptions
UnknownHostException:
if IP address is of illegal length, or if the interface does not have a numeric scope_id assigned for the given address type.
Since
1.5
getByAddressback to summary
public static Inet6Address getByAddress(String host, byte[] addr, int scope_id) throws UnknownHostException

Create an Inet6Address in the exact manner of InetAddress#getByAddress(String, byte[]) except that the IPv6 scope_id is set to the given numeric value. The scope_id is not checked to determine if it corresponds to any interface on the system. See here for a description of IPv6 scoped addresses.

Parameters
host:String

the specified host

addr:byte[]

the raw IP address in network byte order

scope_id:int

the numeric scope_id for the address.

Returns:Inet6Address

an Inet6Address object created from the raw IP address.

Exceptions
UnknownHostException:
if IP address is of illegal length.
Since
1.5
getHostAddressback to summary
public String getHostAddress()

Overrides java.net.InetAddress.getHostAddress.

Returns the IP address string in textual presentation. If the instance was created specifying a scope identifier then the scope id is appended to the IP address preceded by a "%" (per-cent) character. This can be either a numeric value or a string, depending on which was used to create the instance.

Returns:String

the raw IP address in a string format.

Annotations
@Override
getScopedInterfaceback to summary
public NetworkInterface getScopedInterface()

Returns the scoped interface, if this instance was created with a scoped interface.

Returns:NetworkInterface

the scoped interface, or null if not set.

Since
1.5
getScopeIdback to summary
public int getScopeId()

Returns the numeric scopeId, if this instance is associated with an interface. If no scoped_id is set, the returned value is zero.

Returns:int

the scopeId, or zero if not set.

Since
1.5
hashCodeback to summary
public int hashCode()

Overrides java.net.InetAddress.hashCode.

Returns a hashcode for this IP address.

Returns:int

a hash code value for this IP address.

Annotations
@Override
initback to summary
private static native void init()

Hides java.net.InetAddress.init.

Perform class load-time initializations.

initifback to summary
private void initif(String hostName, byte[] addr, NetworkInterface nif) throws UnknownHostException
initstrback to summary
private void initstr(String hostName, byte[] addr, String ifname) throws UnknownHostException
isAnyLocalAddressback to summary
public boolean isAnyLocalAddress()

Overrides java.net.InetAddress.isAnyLocalAddress.

Utility routine to check if the InetAddress is a wildcard address.

Returns:boolean

a boolean indicating if the InetAddress is a wildcard address.

Annotations
@Override
isDifferentLocalAddressTypeback to summary
private static boolean isDifferentLocalAddressType(byte[] thisAddr, byte[] otherAddr)
isIPv4CompatibleAddressback to summary
public boolean isIPv4CompatibleAddress()

Utility routine to check if the InetAddress is an IPv4 compatible IPv6 address.

Returns:boolean

a boolean indicating if the InetAddress is an IPv4 compatible IPv6 address; or false if address is IPv4 address.

isLinkLocalAddressback to summary
public boolean isLinkLocalAddress()

Overrides java.net.InetAddress.isLinkLocalAddress.

Utility routine to check if the InetAddress is a link local address.

Returns:boolean

a boolean indicating if the InetAddress is a link local address; or false if address is not a link local unicast address.

Annotations
@Override
isLinkLocalAddressback to summary
pack-priv static boolean isLinkLocalAddress(byte[] ipaddress)
isLoopbackAddressback to summary
public boolean isLoopbackAddress()

Overrides java.net.InetAddress.isLoopbackAddress.

Utility routine to check if the InetAddress is a loopback address.

Returns:boolean

a boolean indicating if the InetAddress is a loopback address; or false otherwise.

Annotations
@Override
isMCGlobalback to summary
public boolean isMCGlobal()

Overrides java.net.InetAddress.isMCGlobal.

Utility routine to check if the multicast address has global scope.

Returns:boolean

a boolean indicating if the address has is a multicast address of global scope, false if it is not of global scope or it is not a multicast address

Annotations
@Override
isMCLinkLocalback to summary
public boolean isMCLinkLocal()

Overrides java.net.InetAddress.isMCLinkLocal.

Utility routine to check if the multicast address has link scope.

Returns:boolean

a boolean indicating if the address has is a multicast address of link-local scope, false if it is not of link-local scope or it is not a multicast address

Annotations
@Override
isMCNodeLocalback to summary
public boolean isMCNodeLocal()

Overrides java.net.InetAddress.isMCNodeLocal.

Utility routine to check if the multicast address has node scope.

Returns:boolean

a boolean indicating if the address has is a multicast address of node-local scope, false if it is not of node-local scope or it is not a multicast address

Annotations
@Override
isMCOrgLocalback to summary
public boolean isMCOrgLocal()

Overrides java.net.InetAddress.isMCOrgLocal.

Utility routine to check if the multicast address has organization scope.

Returns:boolean

a boolean indicating if the address has is a multicast address of organization-local scope, false if it is not of organization-local scope or it is not a multicast address

Annotations
@Override
isMCSiteLocalback to summary
public boolean isMCSiteLocal()

Overrides java.net.InetAddress.isMCSiteLocal.

Utility routine to check if the multicast address has site scope.

Returns:boolean

a boolean indicating if the address has is a multicast address of site-local scope, false if it is not of site-local scope or it is not a multicast address

Annotations
@Override
isMulticastAddressback to summary
public boolean isMulticastAddress()

Overrides java.net.InetAddress.isMulticastAddress.

Utility routine to check if the InetAddress is an IP multicast address. 11111111 at the start of the address identifies the address as being a multicast address.

Returns:boolean

a boolean indicating if the InetAddress is an IP multicast address

Annotations
@Override
isSiteLocalAddressback to summary
public boolean isSiteLocalAddress()

Overrides java.net.InetAddress.isSiteLocalAddress.

Utility routine to check if the InetAddress is a site local address.

Returns:boolean

a boolean indicating if the InetAddress is a site local address; or false if address is not a site local unicast address.

Annotations
@Override
isSiteLocalAddressback to summary
pack-priv static boolean isSiteLocalAddress(byte[] ipaddress)
numericToTextFormatback to summary
pack-priv static String numericToTextFormat(byte[] src)

Convert IPv6 binary address into presentation (printable) format.

Parameters
src:byte[]

a byte array representing the IPv6 numeric address

Returns:String

a String representing an IPv6 address in textual representation format

ofLiteralback to summary
public static InetAddress ofLiteral(String ipv6AddressLiteral)

Hides java.net.InetAddress.ofLiteral.

Creates an InetAddress based on the provided textual representation of an IPv6 address.

If the provided address literal cannot represent a valid IPv6 address an IllegalArgumentException is thrown. An IllegalArgumentException is also thrown if an IPv6 scoped address literal contains a scope-id that doesn't map to any network interface on the system, or if a scope-id is present in an IPv4-mapped IPv6 address literal.

This method doesn't block, i.e. no reverse lookup is performed.

Note that IPv6 address literal forms are also supported when enclosed in square brackets. Note also that if the supplied literal represents an IPv4-mapped IPv6 address an instance of Inet4Address is returned.

Parameters
ipv6AddressLiteral:String

the textual representation of an IPv6 address.

Returns:InetAddress

an InetAddress object with no hostname set, and constructed from the provided IPv6 address literal.

Exceptions
IllegalArgumentException:
if the ipv6AddressLiteral cannot be parsed as an IPv6 address literal.
NullPointerException:
if the ipv6AddressLiteral is null.
Since
22
parseAddressStringback to summary
pack-priv static InetAddress parseAddressString(String addressLiteral, boolean removeSqBrackets) throws UnknownHostException

Method tries to parse supplied IP address literal as IPv6, IPv4-compatible IPv6 or IPv4-mapped IPv6 address. If address part of the literal string doesn't contain address in valid IPv6 form - null is returned. UnknownHostException is thrown if InetAddress cannot be constructed from parsed string due to: - incorrect zone-id specified in IPv6-scoped address literal that references non-existing interface name. - unexpected zone-id in IPv4-mapped address literal.

Parameters
addressLiteral:String

literal IP address

removeSqBrackets:boolean

if true remove outer square brackets

Returns:InetAddress

Inet6Address or Inet4Address object constructed from literal IP address string.

Exceptions
UnknownHostException:
if literal IP address string cannot be parsed as IPv6, IPv4-mapped IPv6 or IPv4-compatible IPv6 address literals.
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides java.net.InetAddress.readObject.

Restores the state of this object from the stream. This includes the scope information, but only if the scoped interface name is valid on this system.

Parameters
s:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
writeObjectback to summary
private synchronized void writeObject(ObjectOutputStream s) throws IOException

Hides java.net.InetAddress.writeObject.

The default behavior of this method is overridden in order to write the scope_ifname field as a String, rather than a NetworkInterface which is not serializable.

Parameters
s:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
java.net back to summary

private Class Inet6Address.Inet6AddressHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv byte[]
ipaddress

Holds a 128-bit (16 bytes) IPv6 address.

pack-priv int
scope_id

scope_id.

pack-priv boolean
scope_id_set

This will be set to true when the scope_id field contains a valid integer scope_id.

pack-priv NetworkInterface
scope_ifname

scoped interface.

pack-priv boolean
scope_ifname_set

set if the object is constructed with a scoped interface instead of a numeric scope id.

Constructor Summary

AccessConstructor and Description
private
private
Inet6AddressHolder(byte[] ipaddress, int scope_id, boolean scope_id_set, NetworkInterface ifname, boolean scope_ifname_set)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

pack-priv String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv void
init(byte[] addr, int scope_id)

pack-priv void
init(byte[] addr, NetworkInterface nif)

pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv void
setAddr(byte[] addr)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

ipaddressback to summary
pack-priv byte[] ipaddress

Holds a 128-bit (16 bytes) IPv6 address.

scope_idback to summary
pack-priv int scope_id

scope_id. The scope specified when the object is created. If the object is created with an interface name, then the scope_id is not determined until the time it is needed.

scope_id_setback to summary
pack-priv boolean scope_id_set

This will be set to true when the scope_id field contains a valid integer scope_id.

scope_ifnameback to summary
pack-priv NetworkInterface scope_ifname

scoped interface. scope_id is derived from this as the scope_id of the first address whose scope is the same as this address for the named interface.

scope_ifname_setback to summary
pack-priv boolean scope_ifname_set

set if the object is constructed with a scoped interface instead of a numeric scope id.

Constructor Detail

Inet6AddressHolderback to summary
private Inet6AddressHolder()
Inet6AddressHolderback to summary
private Inet6AddressHolder(byte[] ipaddress, int scope_id, boolean scope_id_set, NetworkInterface ifname, boolean scope_ifname_set)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

getHostAddressback to summary
pack-priv String getHostAddress()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

initback to summary
pack-priv void init(byte[] addr, int scope_id)
initback to summary
pack-priv void init(byte[] addr, NetworkInterface nif) throws UnknownHostException
isAnyLocalAddressback to summary
pack-priv boolean isAnyLocalAddress()
isIPv4CompatibleAddressback to summary
pack-priv boolean isIPv4CompatibleAddress()
isLinkLocalAddressback to summary
pack-priv boolean isLinkLocalAddress()
isLoopbackAddressback to summary
pack-priv boolean isLoopbackAddress()
isMCGlobalback to summary
pack-priv boolean isMCGlobal()
isMCLinkLocalback to summary
pack-priv boolean isMCLinkLocal()
isMCNodeLocalback to summary
pack-priv boolean isMCNodeLocal()
isMCOrgLocalback to summary
pack-priv boolean isMCOrgLocal()
isMCSiteLocalback to summary
pack-priv boolean isMCSiteLocal()
isMulticastAddressback to summary
pack-priv boolean isMulticastAddress()
isSiteLocalAddressback to summary
pack-priv boolean isSiteLocalAddress()
setAddrback to summary
pack-priv void setAddr(byte[] addr)