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.
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
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.
- 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.
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.
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.
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
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
private static final long | |
private final transient Inet6Address. | |
pack-priv static final int | |
private static final int | |
private static final ObjectStreamField[] | |
private static final long | |
private static final Unsafe |
Access | Constructor and Description |
---|---|
pack-priv | |
pack-priv | |
pack-priv | |
pack-priv | |
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv byte[] | |
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 | |
private int | |
public boolean | Returns: true if the objects are the same; false otherwise.the object to compare against. obj)Overrides java. Compares this object against the specified object. |
public byte[] | Returns: the raw IP address of this object.Overrides java. Returns the raw IP address of this |
public static Inet6Address | Returns: an Inet6Address object created from the raw IP address.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 |
public static Inet6Address | Returns: an Inet6Address object created from the raw IP address.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 |
public String | Returns: the raw IP address in a string format.Overrides java. Returns the IP address string in textual presentation. |
public NetworkInterface | Returns: the scoped interface, or null if not set.Returns the scoped interface, if this instance was created with a scoped interface. |
public int | Returns: the scopeId, or zero if not set.Returns the numeric scopeId, if this instance is associated with an interface. |
public int | Returns: a hash code value for this IP address.Overrides java. Returns a hashcode for this IP address. |
private static native void | |
private void | |
private void | |
public boolean | Returns: aboolean indicating if the InetAddress is
a wildcard address.Overrides java. Utility routine to check if the InetAddress is a wildcard address. |
private static boolean | |
public boolean | Returns: aboolean indicating if the InetAddress is an IPv4
compatible IPv6 address; or false if address is IPv4 address.Utility routine to check if the InetAddress is an IPv4 compatible IPv6 address. |
public boolean | Returns: aboolean indicating if the InetAddress is a link local
address; or false if address is not a link local unicast address.Overrides java. Utility routine to check if the InetAddress is a link local address. |
pack-priv static boolean | |
public boolean | Returns: aboolean indicating if the InetAddress is a loopback
address; or false otherwise.Overrides java. Utility routine to check if the InetAddress is a loopback address. |
public boolean | Returns: aboolean 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 addressOverrides java. Utility routine to check if the multicast address has global scope. |
public boolean | Returns: aboolean 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 addressOverrides java. Utility routine to check if the multicast address has link scope. |
public boolean | Returns: aboolean 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 addressOverrides java. Utility routine to check if the multicast address has node scope. |
public boolean | Returns: aboolean 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 addressOverrides java. Utility routine to check if the multicast address has organization scope. |
public boolean | Returns: aboolean 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 addressOverrides java. Utility routine to check if the multicast address has site scope. |
public boolean | Returns: aboolean indicating if the InetAddress is an IP
multicast addressOverrides java. Utility routine to check if the InetAddress is an IP multicast address. |
public boolean | Returns: aboolean indicating if the InetAddress is a site local
address; or false if address is not a site local unicast address.Overrides java. Utility routine to check if the InetAddress is a site local address. |
pack-priv static boolean | |
pack-priv static String | Returns: a String representing an IPv6 address in textual representation formata byte array representing the IPv6 numeric address src)Convert IPv6 binary address into presentation (printable) format. |
public static InetAddress | Returns: anInetAddress object with no hostname set, and constructed
from the provided IPv6 address literal.the textual representation of an IPv6 address. ipv6AddressLiteral)Hides java. Creates an |
pack-priv static InetAddress | parseAddressString(String
literal IP address addressLiteral, boolean if removeSqBrackets)true remove outer square bracketsMethod tries to parse supplied IP address literal as IPv6, IPv4-compatible IPv6 or IPv4-mapped IPv6 address. |
private void | readObject(ObjectInputStream
the s)ObjectInputStream from which data is readHides java. Restores the state of this object from the stream. |
private synchronized void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to which data is writtenHides java. The default behavior of this method is overridden in order to
write the scope_ifname field as a |
FIELDS_OFFSET | back to summary |
---|---|
private static final long FIELDS_OFFSET |
holder6 | back to summary |
---|---|
private final transient Inet6Address. |
INADDRSZ | back to summary |
---|---|
pack-priv static final int INADDRSZ |
INT16SZ | back to summary |
---|---|
private static final int INT16SZ |
serialPersistentFields | back to summary |
---|---|
private static final ObjectStreamField[] serialPersistentFields Hides java.
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. |
UNSAFE | back to summary |
---|---|
private static final Unsafe UNSAFE Hides java. |
Inet6Address | back to summary |
---|---|
pack-priv Inet6Address() |
Inet6Address | back to summary |
---|---|
pack-priv Inet6Address(String hostName, byte[] addr, int scope_id) |
Inet6Address | back to summary |
---|---|
pack-priv Inet6Address(String hostName, byte[] addr) |
Inet6Address | back to summary |
---|---|
pack-priv Inet6Address(String hostName, byte[] addr, NetworkInterface nif) throws UnknownHostException |
Inet6Address | back to summary |
---|---|
pack-priv Inet6Address(String hostName, byte[] addr, String ifname) throws UnknownHostException |
addressBytes | back to summary |
---|---|
pack-priv byte[] addressBytes() Returns a reference to the byte[] with the IPv6 address. |
checkNumericZone | back 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. |
deriveNumericScope | back to summary |
---|---|
private static int deriveNumericScope(byte[] thisAddr, NetworkInterface ifc) throws UnknownHostException |
deriveNumericScope | back to summary |
---|---|
private int deriveNumericScope(String ifname) throws UnknownHostException |
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Compares this object against the specified object. The result is Two instances of
|
getAddress | back to summary |
---|---|
public byte[] getAddress() Overrides java. Returns the raw IP address of this
|
getByAddress | back to summary |
---|---|
public static Inet6Address getByAddress(String host, byte[] addr, NetworkInterface nif) throws UnknownHostException Create an Inet6Address in the exact manner of
|
getByAddress | back to summary |
---|---|
public static Inet6Address getByAddress(String host, byte[] addr, int scope_id) throws UnknownHostException Create an Inet6Address in the exact manner of
|
getHostAddress | back to summary |
---|---|
public String getHostAddress() Overrides java. 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. |
getScopedInterface | back to summary |
---|---|
public NetworkInterface getScopedInterface() Returns the scoped interface, if this instance was created with a scoped interface.
|
getScopeId | back 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.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a hashcode for this IP address.
|
init | back to summary |
---|---|
private static native void init() Hides java. Perform class load-time initializations. |
initif | back to summary |
---|---|
private void initif(String hostName, byte[] addr, NetworkInterface nif) throws UnknownHostException |
initstr | back to summary |
---|---|
private void initstr(String hostName, byte[] addr, String ifname) throws UnknownHostException |
isAnyLocalAddress | back to summary |
---|---|
public boolean isAnyLocalAddress() Overrides java. Utility routine to check if the InetAddress is a wildcard address.
|
isDifferentLocalAddressType | back to summary |
---|---|
private static boolean isDifferentLocalAddressType(byte[] thisAddr, byte[] otherAddr) |
isIPv4CompatibleAddress | back to summary |
---|---|
public boolean isIPv4CompatibleAddress() Utility routine to check if the InetAddress is an IPv4 compatible IPv6 address.
|
isLinkLocalAddress | back to summary |
---|---|
public boolean isLinkLocalAddress() Overrides java. Utility routine to check if the InetAddress is a link local address.
|
isLinkLocalAddress | back to summary |
---|---|
pack-priv static boolean isLinkLocalAddress(byte[] ipaddress) |
isLoopbackAddress | back to summary |
---|---|
public boolean isLoopbackAddress() Overrides java. Utility routine to check if the InetAddress is a loopback address.
|
isMCGlobal | back to summary |
---|---|
public boolean isMCGlobal() Overrides java. Utility routine to check if the multicast address has global scope.
|
isMCLinkLocal | back to summary |
---|---|
public boolean isMCLinkLocal() Overrides java. Utility routine to check if the multicast address has link scope.
|
isMCNodeLocal | back to summary |
---|---|
public boolean isMCNodeLocal() Overrides java. Utility routine to check if the multicast address has node scope.
|
isMCOrgLocal | back to summary |
---|---|
public boolean isMCOrgLocal() Overrides java. Utility routine to check if the multicast address has organization scope.
|
isMCSiteLocal | back to summary |
---|---|
public boolean isMCSiteLocal() Overrides java. Utility routine to check if the multicast address has site scope.
|
isMulticastAddress | back to summary |
---|---|
public boolean isMulticastAddress() Overrides java. 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.
|
isSiteLocalAddress | back to summary |
---|---|
public boolean isSiteLocalAddress() Overrides java. Utility routine to check if the InetAddress is a site local address.
|
isSiteLocalAddress | back to summary |
---|---|
pack-priv static boolean isSiteLocalAddress(byte[] ipaddress) |
numericToTextFormat | back to summary |
---|---|
pack-priv static String numericToTextFormat(byte[] src) Convert IPv6 binary address into presentation (printable) format.
|
ofLiteral | back to summary |
---|---|
public static InetAddress ofLiteral(String ipv6AddressLiteral) Hides java. Creates an If the provided address literal cannot represent a valid IPv6 address an 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
|
parseAddressString | back 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
-
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException Hides java. 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.
|
writeObject | back to summary |
---|---|
private synchronized void writeObject(ObjectOutputStream s) throws IOException Hides java. The default behavior of this method is overridden in order to
write the scope_ifname field as a
|
Modifier and Type | Field 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. |
Access | Constructor and Description |
---|---|
private | |
private | Inet6AddressHolder(byte[] ipaddress, int scope_id, boolean scope_id_set, NetworkInterface ifname, boolean scope_ifname_set)
|
Modifier and Type | Method and Description |
---|---|
public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
pack-priv String | |
public int | |
pack-priv void | |
pack-priv void | |
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 |
ipaddress | back to summary |
---|---|
pack-priv byte[] ipaddress Holds a 128-bit (16 bytes) IPv6 address. |
scope_id | back 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_set | back 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_ifname | back 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_set | back to summary |
---|---|
pack-priv boolean scope_ifname_set set if the object is constructed with a scoped interface instead of a numeric scope id. |
Inet6AddressHolder | back to summary |
---|---|
private Inet6AddressHolder() |
Inet6AddressHolder | back to summary |
---|---|
private Inet6AddressHolder(byte[] ipaddress, int scope_id, boolean scope_id_set, NetworkInterface ifname, boolean scope_ifname_set) |
equals | back to summary |
---|---|
public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
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.
|
getHostAddress | back to summary |
---|---|
pack-priv String getHostAddress() |
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
|
init | back to summary |
---|---|
pack-priv void init(byte[] addr, int scope_id) |
init | back to summary |
---|---|
pack-priv void init(byte[] addr, NetworkInterface nif) throws UnknownHostException |
isAnyLocalAddress | back to summary |
---|---|
pack-priv boolean isAnyLocalAddress() |
isIPv4CompatibleAddress | back to summary |
---|---|
pack-priv boolean isIPv4CompatibleAddress() |
isLinkLocalAddress | back to summary |
---|---|
pack-priv boolean isLinkLocalAddress() |
isLoopbackAddress | back to summary |
---|---|
pack-priv boolean isLoopbackAddress() |
isMCGlobal | back to summary |
---|---|
pack-priv boolean isMCGlobal() |
isMCLinkLocal | back to summary |
---|---|
pack-priv boolean isMCLinkLocal() |
isMCNodeLocal | back to summary |
---|---|
pack-priv boolean isMCNodeLocal() |
isMCOrgLocal | back to summary |
---|---|
pack-priv boolean isMCOrgLocal() |
isMCSiteLocal | back to summary |
---|---|
pack-priv boolean isMCSiteLocal() |
isMulticastAddress | back to summary |
---|---|
pack-priv boolean isMulticastAddress() |
isSiteLocalAddress | back to summary |
---|---|
pack-priv boolean isSiteLocalAddress() |
setAddr | back to summary |
---|---|
pack-priv void setAddr(byte[] addr) |