Class Inet6Address
- java.lang.Object
-
- java.net.InetAddress
-
- java.net.Inet6Address
-
- All Implemented Interfaces:
Serializable
public final class Inet6Address extends InetAddress
An IPv6 address. SeeInetAddress.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static InetAddressANYstatic InetAddressLOOPBACK-
Fields inherited from class java.net.InetAddress
UNSPECIFIED
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Inet6AddressgetByAddress(String host, byte[] addr, int scope_id)Constructs an IPv6 address according to the givenhost,addrandscope_id.static Inet6AddressgetByAddress(String host, byte[] addr, NetworkInterface nif)Gets an IPv6 address instance according to the givenhost,addrandnif.NetworkInterfacegetScopedInterface()Returns the network interface if this address is instanced with a scoped network interface, null otherwise.intgetScopeId()Returns the scope id if this address is scoped to an interface, 0 otherwise.booleanisAnyLocalAddress()Returns whether this is the IPv6 unspecified wildcard address::or the IPv4 "any" address,0.0.0.0.booleanisIPv4CompatibleAddress()Returns whether this IPv6 address is an IPv4-compatible address or not.booleanisLinkLocalAddress()Returns whether this address is a link-local address or not.booleanisLoopbackAddress()Returns whether this address is a loopback address or not.booleanisMCGlobal()Returns whether this address is a global multicast address or not.booleanisMCLinkLocal()Returns whether this address is a link-local multicast address or not.booleanisMCNodeLocal()Returns whether this address is a node-local multicast address or not.booleanisMCOrgLocal()Returns whether this address is a organization-local multicast address or not.booleanisMCSiteLocal()Returns whether this address is a site-local multicast address or not.booleanisMulticastAddress()Returns whether this address is a multicast address or not.booleanisSiteLocalAddress()Returns whether this address is a site-local address or not.StringtoString()Returns a string containing the host name (if available) and host address.-
Methods inherited from class java.net.InetAddress
clearDnsCache, equals, getAddress, getAllByName, getAllByNameOnNet, getByAddress, getByAddress, getByName, getByNameOnNet, getCanonicalHostName, getHostAddress, getHostName, getHostString, getLocalHost, getLoopbackAddress, hashCode, isNumeric, isReachable, isReachable, parseNumericAddress
-
-
-
-
Field Detail
-
ANY
public static final InetAddress ANY
-
LOOPBACK
public static final InetAddress LOOPBACK
-
-
Method Detail
-
getByAddress
public static Inet6Address getByAddress(String host, byte[] addr, int scope_id) throws UnknownHostException
Constructs an IPv6 address according to the givenhost,addrandscope_id.- Parameters:
host- the host name associated with the address.addr- the network address.scope_id- the scope id for link- or site-local addresses.- Returns:
- the Inet6Address instance representing the IP address.
- Throws:
UnknownHostException- if the address is null or has an invalid length.
-
getByAddress
public static Inet6Address getByAddress(String host, byte[] addr, NetworkInterface nif) throws UnknownHostException
Gets an IPv6 address instance according to the givenhost,addrandnif.scope_idis set according to the givennifand theaddrtype (for example site-local or link-local).- Parameters:
host- the hostname associated with the address.addr- the network address.nif- the network interface that this address is associated with.- Returns:
- the Inet6Address instance representing the IP address.
- Throws:
UnknownHostException- if the address isnullor has an invalid length or the interface doesn't have a numeric scope id for the given address type.
-
isAnyLocalAddress
public boolean isAnyLocalAddress()
Description copied from class:InetAddressReturns whether this is the IPv6 unspecified wildcard address::or the IPv4 "any" address,0.0.0.0.- Overrides:
isAnyLocalAddressin classInetAddress
-
isIPv4CompatibleAddress
public boolean isIPv4CompatibleAddress()
Returns whether this IPv6 address is an IPv4-compatible address or not. An IPv4-compatible address has the prefix::/96and is a deprecated and no-longer used equivalent of the modern IPv4-mapped IPv6 addresses.
-
isLinkLocalAddress
public boolean isLinkLocalAddress()
Description copied from class:InetAddressReturns whether this address is a link-local address or not.Valid IPv6 link-local addresses have the prefix
fe80::/10.RFC 3484 "Default Address Selection for Internet Protocol Version 6 (IPv6)" states that both IPv4 auto-configuration addresses (prefix
169.254/16) and IPv4 loopback addresses (prefix127/8) have link-local scope, butInet4Addressonly considers the auto-configuration addresses to have link-local scope. That is: the IPv4 loopback address returns false.- Overrides:
isLinkLocalAddressin classInetAddress
-
isLoopbackAddress
public boolean isLoopbackAddress()
Description copied from class:InetAddressReturns whether this address is a loopback address or not.Valid IPv4 loopback addresses have the prefix
127/8.The only valid IPv6 loopback address is
::1.- Overrides:
isLoopbackAddressin classInetAddress
-
isMCGlobal
public boolean isMCGlobal()
Description copied from class:InetAddressReturns whether this address is a global multicast address or not.Valid IPv6 global multicast addresses have the prefix
ffxe::/16, wherexis a set of flags and the additional 112 bits make up the global multicast address space.Valid IPv4 global multicast addresses are the range of addresses from
224.0.1.0to238.255.255.255.- Overrides:
isMCGlobalin classInetAddress
-
isMCLinkLocal
public boolean isMCLinkLocal()
Description copied from class:InetAddressReturns whether this address is a link-local multicast address or not.Valid IPv6 link-local multicast addresses have the prefix
ffx2::/16, where x is a set of flags and the additional 112 bits make up the link-local multicast address space.Valid IPv4 link-local multicast addresses have the prefix
224.0.0/24.- Overrides:
isMCLinkLocalin classInetAddress
-
isMCNodeLocal
public boolean isMCNodeLocal()
Description copied from class:InetAddressReturns whether this address is a node-local multicast address or not.Valid IPv6 node-local multicast addresses have the prefix
ffx1::/16, where x is a set of flags and the additional 112 bits make up the link-local multicast address space.There are no valid IPv4 node-local multicast addresses.
- Overrides:
isMCNodeLocalin classInetAddress
-
isMCOrgLocal
public boolean isMCOrgLocal()
Description copied from class:InetAddressReturns whether this address is a organization-local multicast address or not.Valid IPv6 organization-local multicast addresses have the prefix
ffx8::/16, where x is a set of flags and the additional 112 bits make up the link-local multicast address space.Valid IPv4 organization-local multicast addresses have the prefix
239.192/14.- Overrides:
isMCOrgLocalin classInetAddress
-
isMCSiteLocal
public boolean isMCSiteLocal()
Description copied from class:InetAddressReturns whether this address is a site-local multicast address or not.Valid IPv6 site-local multicast addresses have the prefix
ffx5::/16, where x is a set of flags and the additional 112 bits make up the link-local multicast address space.Valid IPv4 site-local multicast addresses have the prefix
239.255/16.- Overrides:
isMCSiteLocalin classInetAddress
-
isMulticastAddress
public boolean isMulticastAddress()
Description copied from class:InetAddressReturns whether this address is a multicast address or not.Valid IPv6 multicast addresses have the prefix
ff::/8.Valid IPv4 multicast addresses have the prefix
224/4.- Overrides:
isMulticastAddressin classInetAddress
-
isSiteLocalAddress
public boolean isSiteLocalAddress()
Description copied from class:InetAddressReturns whether this address is a site-local address or not.For the purposes of this method, valid IPv6 site-local addresses have the deprecated prefix
fec0::/10from RFC 1884, not the modern prefixfc00::/7from RFC 4193.RFC 3484 "Default Address Selection for Internet Protocol Version 6 (IPv6)" states that IPv4 private addresses have the prefix
10/8,172.16/12, or192.168/16.- Overrides:
isSiteLocalAddressin classInetAddress- Returns:
trueif this instance represents a site-local address,falseotherwise.
-
getScopeId
public int getScopeId()
Returns the scope id if this address is scoped to an interface, 0 otherwise.
-
getScopedInterface
public NetworkInterface getScopedInterface()
Returns the network interface if this address is instanced with a scoped network interface, null otherwise.
-
toString
public String toString()
Description copied from class:InetAddressReturns a string containing the host name (if available) and host address. For example:"www.google.com/74.125.224.115"or"/127.0.0.1".IPv6 addresses may additionally include an interface name or scope id. For example:
"www.google.com/2001:4860:4001:803::1013%eth0"or"/2001:4860:4001:803::1013%2".- Overrides:
toStringin classInetAddress- Returns:
- a printable representation of this object.
-
-