|Known Direct Subclasses|
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
class cannot be instantiated directly). Most code does not need to distinguish between the two
families, and should use
InetAddress may have a hostname (accessible via
getHostName), but may not,
depending on how the
InetAddress was created.
IPv4 numeric address formats
getAllByName method accepts IPv4 addresses in the "decimal-dotted-quad" form only:
IPv6 numeric address formats
getAllByName 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
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. 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:
- 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 addressesmay 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
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 address (standard IPv4 representation). Examples:
0:0:0:0:0:0:22.214.171.124 0:0:0:0:0:FFFF:126.96.36.199or in compressed form:
Scopes are given using a trailing
% followed by the scope id, as in
See RFC 4007 for more on IPv6's scoped
Additionally, for backwards compatibility, IPv6 addresses may be surrounded by square brackets.
In Android 4.0 (Ice Cream Sandwich) and earlier, DNS caching was performed both by InetAddress and by the C library, which meant that DNS TTLs could not be honored correctly. In later releases, caching is done solely by the C library and DNS TTLs are honored.
Public Method Summary
Returns the IP address represented by this
Returns the fully qualified hostname corresponding to this IP address.
Returns the numeric representation of this IP address (such as "127.0.0.1").
Returns the host name corresponding to this IP address.
Returns the IPv6 loopback address
Gets the hashcode of the represented IP address.
Returns whether this is the IPv6 unspecified wildcard address
Returns whether this address is a link-local address or not.
Returns whether this address is a loopback address or not.
Returns whether this address is a global multicast address or not.
Returns whether this address is a link-local multicast address or not.
Returns whether this address is a node-local multicast address or not.
Returns whether this address is a organization-local multicast address or not.
Returns whether this address is a site-local multicast address or not.
Returns whether this address is a multicast address or not.
Tries to reach this
Returns whether this address is a site-local address or not.
Returns a string containing the host name (if available) and host address.
Inherited Method Summary
Creates and returns a copy of this
Invoked when the garbage collector has detected that this instance is no longer reachable.
Returns an integer hash code for this object.
Causes a thread which is waiting on this object's monitor (by means of calling one of the
Causes all threads which are waiting on this object's monitor (by means of calling one of the