DthingApi
|
Public Member Functions | |
boolean | equals (Object obj) |
byte [] | getAddress () |
int | getAddressToInt () |
int | getFamily () |
String | getHostAddress () |
int | hashCode () |
String | toString () |
boolean | isAnyLocalAddress () |
boolean | isLinkLocalAddress () |
boolean | isLoopbackAddress () |
boolean | isMCGlobal () |
boolean | isMCLinkLocal () |
boolean | isMCNodeLocal () |
boolean | isMCOrgLocal () |
boolean | isMCSiteLocal () |
boolean | isMulticastAddress () |
boolean | isSiteLocalAddress () |
Static Public Member Functions | |
static InetAddress | getLocalHost () throws UnknownHostException |
static void | clearDnsCache () |
static InetAddress | getByAddress (byte[] addr) throws UnknownHostException |
static InetAddress | getByName (String host) throws UnknownHostException |
static InetAddress | getByAddress (String hostName, byte[] ipAddress) throws UnknownHostException |
Static Public Attributes | |
static final InetAddress | UNSPECIFIED |
Protected Attributes | |
byte [] | ipAddress |
String | hostName |
An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in practice you'll have an instance of either
or
(this class cannot be instantiated directly). Most code does not need to distinguish between the two families, and should use
.
An
may have a hostname (accessible via
), but may not, depending on how the
was created.
The
method accepts IPv4 addresses in the "decimal-dotted-quad" form only:
The
method accepts IPv6 addresses in the following forms (this text comes from RFC 2373, which you should consult for full details of IPv6 addressing):
The preferred form is
, where the 'x's are the hexadecimal values of the eight 16-bit pieces of the address. Note that it is not necessary to write the leading zeros in an individual field, but there must be at least one numeral in every field (except for the case described in the next bullet). Examples:
FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 1080:0:0:0:8:800:200C:417A
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 the following addresses:
1080:0:0:0:8:800:200C:417A a unicast address FF01:0:0:0:0:0:0:101 a multicast address 0:0:0:0:0:0:0:1 the loopback address 0:0:0:0:0:0:0:0 the unspecified addresses
may be represented as:
1080::8:800:200C:417A a unicast address FF01::101 a multicast address ::1 the loopback address :: the unspecified addresses
An alternative form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is
, 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 address (standard IPv4 representation). Examples:
0:0:0:0:0:0:13.1.68.3 0:0:0:0:0:FFFF:129.144.52.38
or in compressed form:
::13.1.68.3 ::FFFF:129.144.52.38
Scopes are given using a trailing
followed by the scope id, as in
or
. See RFC 4007 for more on IPv6's scoped address architecture.
Additionally, for backwards compatibility, IPv6 addresses may be surrounded by square brackets.
On Android, addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are cached for 10 seconds. The underlying C library or OS may cache for longer, but you can control the Java-level caching with the usual
and
system properties. These are parsed as integer numbers of seconds, where the special value 0 means "don't cache" and -1 means "cache forever".
Note also that on Android – unlike the RI – the cache is not unbounded. The current implementation caches around 512 entries, removed on a least-recently-used basis. (Obviously, you should not rely on these details.)
|
inlinestatic |
Removes all entries from the VM's DNS cache. This does not affect the C library's DNS cache, nor any caching DNS servers between you and the canonical server.
|
inline |
Compares this
instance against the specified address in
. Two addresses are equal if their address byte arrays have the same length and if the bytes in the arrays are equal.
obj | the object to be tested for equality. |
|
inline |
Returns the IP address represented by this
instance as a byte array. The elements are in network order (the highest order address byte is in the zeroth element).
|
inlinestatic |
Returns an
object given the raw IP address. The argument is in network byte order: the highest order byte of the address is in
.
This method doesn't block, i.e. no reverse name service lookup is performed.
IPv4 address byte array must be 4 bytes long and IPv6 byte array must be 16 bytes long
addr | the raw IP address in network byte order |
UnknownHostException | if IP address is of illegal length |
|
inlinestatic |
Returns an
corresponding to the given network-order bytes
and
.
For an IPv4 address, the byte array must be of length 4. For IPv6, the byte array must be of length 16. Any other length will cause an
.
No reverse lookup is performed. The given
(which may be null) is associated with the new
with no validation done.
(Note that numeric addresses such as
are names for the purposes of this API. Most callers probably want getAllByName instead.)
UnknownHostException | if ipAddress |
|
inlinestatic |
Determines the IP address of a host, given the host's name.
The host name can either be a machine name, such as "@code java.sun.com @endcode ", or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked.
For
specified in literal IPv6 address, either the form defined in RFC 2732 or the literal IPv6 address format defined in RFC 2373 is accepted. IPv6 scoped addresses are also supported. See here for a description of IPv6 scoped addresses.
If the host is
then an
representing a IPv4 address of the loopback interface is returned. See RFC 3330 section 2 and RFC 2373 section 2.5.3.
host | the specified host, or null |
UnknownHostException | if no IP address for the host |
|
inlinestatic |
Returns an
for the local host if possible, or the loopback address otherwise. This method works by getting the hostname, performing a DNS lookup, and then taking the first returned address. For devices with multiple network interfaces and/or multiple addresses per interface, this does not necessarily return the
you want.
Multiple interface/address configurations were relatively rare when this API was designed, but multiple interfaces are the default for modern mobile devices (with separate wifi and radio interfaces), and the need to support both IPv4 and IPv6 has made multiple addresses commonplace. New code should thus avoid this method except where it's basically being used to get a loopback address or equivalent.
There are two main ways to get a more specific answer:
Note that if the host doesn't have a hostname set – as Android devices typically don't – this method will effectively return the loopback address, albeit by getting the name
and then doing a lookup to translate that to
.
UnknownHostException | if the address lookup fails. |
|
inline |
Gets the hashcode of the represented IP address.
|
inline |
Returns whether this is the IPv6 unspecified wildcard address
or the IPv4 "any" address,
.
|
inline |
Returns whether this address is a link-local address or not.
Valid IPv6 link-local addresses have the prefix
.
RFC 3484 "Default Address Selection for Internet Protocol Version 6 (IPv6)" states that both IPv4 auto-configuration addresses (prefix
) and IPv4 loopback addresses (prefix
) have link-local scope, but Inet4Address only considers the auto-configuration addresses to have link-local scope. That is: the IPv4 loopback address returns false.
|
inline |
Returns whether this address is a loopback address or not.
Valid IPv4 loopback addresses have the prefix
.
The only valid IPv6 loopback address is
.
|
inline |
Returns whether this address is a global multicast address or not.
Valid IPv6 global multicast addresses have the prefix
, where
is 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
to
.
|
inline |
Returns whether this address is a link-local multicast address or not.
Valid IPv6 link-local multicast addresses have the prefix
, 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
.
|
inline |
Returns whether this address is a node-local multicast address or not.
Valid IPv6 node-local multicast addresses have the prefix
, 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.
|
inline |
Returns whether this address is a organization-local multicast address or not.
Valid IPv6 organization-local multicast addresses have the prefix
, 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
.
|
inline |
Returns whether this address is a site-local multicast address or not.
Valid IPv6 site-local multicast addresses have the prefix
, 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
.
|
inline |
Returns whether this address is a multicast address or not.
Valid IPv6 multicast addresses have the prefix
.
Valid IPv4 multicast addresses have the prefix
.
|
inline |
Returns 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
from RFC 1884, not the modern prefix
from RFC 4193.
RFC 3484 "Default Address Selection for Internet Protocol Version 6 (IPv6)" states that IPv4 private addresses have the prefix
,
, or
.
|
inline |
Returns a string containing a concise, human-readable description of this IP address.
|
static |
Used by the DatagramSocket.disconnect implementation.
internal use only