d.d.d.dd.d.dd.dd
When four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an IPv4 address.
When a three part address is specified, the last part is interpreted as a 16-bit quantity and placed in the right most two bytes of the network address. This makes the three part address format convenient for specifying Class B network addresses as 128.net.host.
When a two part address is supplied, the last part is interpreted as a 24-bit quantity and placed in the right most three bytes of the network address. This makes the two part address format convenient for specifying Class A network addresses as net.host.
When only one part is given, the value is stored directly in the network address without any byte rearrangement.
For example, the following (decimal) forms are supported by the methods
Inet4Address#ofLiteral(String) and InetAddress#getByName(String)
which are capable of parsing textual representations of IPv4 addresses:
// Dotted-decimal 'd.d.d.d' form with four part address literal
InetAddress.getByName("007.008.009.010"); // ==> /7.8.9.10
InetAddress.getByName("127.0.1.1"); // ==> /127.0.1.1
// Dotted-decimal 'd.d.d' form with three part address literal,
// the last part is placed in the right most two bytes
// of the constructed address
InetAddress.getByName("127.0.257"); // ==> /127.0.1.1
// Dotted-decimal 'd.d' form with two part address literal,
// the last part is placed in the right most three bytes
// of the constructed address
Inet4Address.ofLiteral("127.257"); // ==> /127.0.1.1
// 'd' form with one decimal value that is stored directly in
// the constructed address bytes without any rearrangement
Inet4Address.ofLiteral("02130706689"); // ==> /127.0.1.1
The above forms adhere to "strict" decimal-only syntax.
Additionally, the Inet4Address#ofPosixLiteral(String)
method implements a POSIX inet_addr compatible "loose"
parsing algorithm, allowing octal and hexadecimal address segments.
Please refer to
RFC 6943: Issues in Identifier Comparison for Security
Purposes. Aside from Inet4Address.ofPosixLiteral(String), all methods only
support strict decimal parsing.
For methods that return a textual representation as output value, the first form, i.e. a dotted-quad string in strict decimal notation, is used.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | |
| private static final long | serialVersionUID
use serialVersionUID from InetAddress, but Inet4Address instance
is always replaced by an InetAddress instance before being
serialized
|
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv 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 String | Returns: the raw IP address in a string format.Overrides java. Returns the IP address string in textual presentation form. |
| public int | Returns: a hash code value for this IP address.Overrides java. Returns a hashcode for this IP address. |
| private static native 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. |
| 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. |
| 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 String | Returns: a String representing the IPv4 address in textual representation formata byte array representing an IPv4 numeric address src)Converts IPv4 binary address into a string suitable for presentation. |
| public static Inet4Address | Returns: anInet4Address object with no hostname set, and constructed
from the provided IPv4 address literal.the textual representation of an IPv4 address. ipv4AddressLiteral)Hides java. Creates an |
| public static Inet4Address | Returns: anInet4Address object with no hostname set, and constructed
from the provided IPv4 address literal.a textual representation of an IPv4 address. posixIPAddressLiteral)Creates an |
| pack-priv static Inet4Address | Returns: Inet4Address object constructed from the address literal;
or null if the literal cannot be parsed as an IPv4 addressIPv4 address literal to parse addressLiteral, boolean whether to throw throwIAE)IllegalArgumentException if the
given addressLiteral string cannot be parsed as
an IPv4 address literal.Parses the given string as an IPv4 address literal. |
| private static Inet4Address | Returns: Inet4Address object constructed from the address literal;
or null if the literal cannot be parsed as an IPv4 addressIPv4 address literal to parse addressLiteral)Parses the given string as an IPv4 address literal in POSIX form. If the given |
| private Object | Returns: the alternate object to be serialized.Replaces the object to be serialized with an InetAddress object. |
| INADDRSZ | back to summary |
|---|---|
| pack-priv static final int INADDRSZ | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. use serialVersionUID from InetAddress, but Inet4Address instance is always replaced by an InetAddress instance before being serialized | |
| Inet4Address | back to summary |
|---|---|
| pack-priv Inet4Address() | |
| Inet4Address | back to summary |
|---|---|
| pack-priv Inet4Address(String hostName, byte[] addr) | |
| Inet4Address | back to summary |
|---|---|
| pack-priv Inet4Address(String hostName, int address) | |
| addressValue | back to summary |
|---|---|
| pack-priv int addressValue() Returns the 32-bit IPv4 address. | |
| 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
| |
| getHostAddress | back to summary |
|---|---|
| public String getHostAddress() Overrides java. Returns the IP address string in textual presentation form.
| |
| 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. | |
| isAnyLocalAddress | back to summary |
|---|---|
| public boolean isAnyLocalAddress() Overrides java. Utility routine to check if the InetAddress is a wildcard address.
| |
| isLinkLocalAddress | back to summary |
|---|---|
| public boolean isLinkLocalAddress() Overrides java. Utility routine to check if the InetAddress is a link local address.
| |
| 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. IP multicast address is a Class D address i.e first four bits of the address are 1110.
| |
| isSiteLocalAddress | back to summary |
|---|---|
| public boolean isSiteLocalAddress() Overrides java. Utility routine to check if the InetAddress is a site local address.
| |
| numericToTextFormat | back to summary |
|---|---|
| pack-priv static String numericToTextFormat(byte[] src) Converts IPv4 binary address into a string suitable for presentation.
| |
| ofLiteral | back to summary |
|---|---|
| public static Inet4Address ofLiteral(String ipv4AddressLiteral) Hides java. Creates an If the provided IPv4 address literal cannot represent a valid IPv4 address an This method doesn't block, i.e. no reverse lookup is performed.
| |
| ofPosixLiteral | back to summary |
|---|---|
| public static Inet4Address ofPosixLiteral(String posixIPAddressLiteral) Creates an The method // Dotted-quad 'x.x.x.x' form with four part address literal
Inet4Address.ofPosixLiteral("0177.0.0.1"); // ==> /127.0.0.1
Inet4Address.ofPosixLiteral("0x7F.0.0.1"); // ==> /127.0.0.1
// Dotted-triple 'x.x.x' form with three part address literal,
// the last part is placed in the rightmost two bytes
// of the constructed address
Inet4Address.ofPosixLiteral("0177.0.0402"); // ==> /127.0.1.2
Inet4Address.ofPosixLiteral("0x7F.0.0x102"); // ==> /127.0.1.2
// Dotted-double 'x.x' form with two part address literal,
// the last part is placed in the rightmost three bytes
// of the constructed address
Inet4Address.ofPosixLiteral("0177.0201003"); // ==> /127.1.2.3
Inet4Address.ofPosixLiteral("0x7F.0x10203"); // ==> /127.1.2.3
Inet4Address.ofPosixLiteral("127.66051"); // ==> /127.1.2.3
// Dotless 'x' form with one value that is stored directly in
// the constructed address bytes without any rearrangement
Inet4Address.ofPosixLiteral("0100401404"); // ==> /1.2.3.4
Inet4Address.ofPosixLiteral("0x1020304"); // ==> /1.2.3.4
Inet4Address.ofPosixLiteral("16909060"); // ==> /1.2.3.4
If the provided IPv4 address literal cannot represent a
valid IPv4 address in POSIX form an This method doesn't block, i.e. no hostname lookup is performed. API Note This method produces different results compared to Inet4Address#ofLiteral
when
| |
| parseAddressString | back to summary |
|---|---|
| pack-priv static Inet4Address parseAddressString(String addressLiteral, boolean throwIAE) Parses the given string as an IPv4 address literal.
If the given API Note The given
| |
| parseAddressStringPosix | back to summary |
|---|---|
| private static Inet4Address parseAddressStringPosix(String addressLiteral) Parses the given string as an IPv4 address literal in POSIX form. If the given API Note This method produces different results compared to Inet4Address#parseAddressString
when
| |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() throws ObjectStreamException Replaces the object to be serialized with an InetAddress object.
| |