Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Compares this object against the specified object.
The result is true if and only if the argument is
not null and it represents the same IP address as
this object.
Two instances of InetAddress represent the same IP
address if the length of the byte arrays returned by
getAddress is the same for both, and each of the
array components is the same for the byte arrays.
return (obj != null) && (obj instanceof Inet4Address) &&
(((InetAddress)obj).address == address);
|
public byte[] | getAddress()Returns the raw IP address of this InetAddress
object. The result is in network byte order: the highest order
byte of the address is in getAddress()[0] .
byte[] addr = new byte[INADDRSZ];
addr[0] = (byte) ((address >>> 24) & 0xFF);
addr[1] = (byte) ((address >>> 16) & 0xFF);
addr[2] = (byte) ((address >>> 8) & 0xFF);
addr[3] = (byte) (address & 0xFF);
return addr;
|
public java.lang.String | getHostAddress()Returns the IP address string in textual presentation form.
return numericToTextFormat(getAddress());
|
public int | hashCode()Returns a hashcode for this IP address.
return address;
|
private static native void | init()Perform class load-time initializations.
|
public boolean | isAnyLocalAddress()Utility routine to check if the InetAddress in a wildcard address.
return address == 0;
|
public boolean | isLinkLocalAddress()Utility routine to check if the InetAddress is an link local address.
// link-local unicast in IPv4 (169.254.0.0/16)
// defined in "Documenting Special Use IPv4 Address Blocks
// that have been Registered with IANA" by Bill Manning
// draft-manning-dsua-06.txt
return (((address >>> 24) & 0xFF) == 169)
&& (((address >>> 16) & 0xFF) == 254);
|
public boolean | isLoopbackAddress() /* 127.0.0.1 */
/* 127.x.x.x */
byte[] byteAddr = getAddress();
return byteAddr[0] == 127;
|
public boolean | isMCGlobal()Utility routine to check if the multicast address has global scope.
// 224.0.1.0 to 238.255.255.255
byte[] byteAddr = getAddress();
return ((byteAddr[0] & 0xff) >= 224 && (byteAddr[0] & 0xff) <= 238 ) &&
!((byteAddr[0] & 0xff) == 224 && byteAddr[1] == 0 &&
byteAddr[2] == 0);
|
public boolean | isMCLinkLocal()Utility routine to check if the multicast address has link scope.
// 224.0.0/24 prefix and ttl == 1
return (((address >>> 24) & 0xFF) == 224)
&& (((address >>> 16) & 0xFF) == 0)
&& (((address >>> 8) & 0xFF) == 0);
|
public boolean | isMCNodeLocal()Utility routine to check if the multicast address has node scope.
// unless ttl == 0
return false;
|
public boolean | isMCOrgLocal()Utility routine to check if the multicast address has organization scope.
// 239.192 - 239.195
return (((address >>> 24) & 0xFF) == 239)
&& (((address >>> 16) & 0xFF) >= 192)
&& (((address >>> 16) & 0xFF) <= 195);
|
public boolean | isMCSiteLocal()Utility routine to check if the multicast address has site scope.
// 239.255/16 prefix or ttl < 32
return (((address >>> 24) & 0xFF) == 239)
&& (((address >>> 16) & 0xFF) == 255);
|
public boolean | isMulticastAddress()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.
return ((address & 0xf0000000) == 0xe0000000);
|
public boolean | isSiteLocalAddress()Utility routine to check if the InetAddress is a site local address.
// refer to RFC 1918
// 10/8 prefix
// 172.16/12 prefix
// 192.168/16 prefix
return (((address >>> 24) & 0xFF) == 10)
|| ((((address >>> 24) & 0xFF) == 172)
&& (((address >>> 16) & 0xF0) == 16))
|| ((((address >>> 24) & 0xFF) == 192)
&& (((address >>> 16) & 0xFF) == 168));
|
static java.lang.String | numericToTextFormat(byte[] src)
return (src[0] & 0xff) + "." + (src[1] & 0xff) + "." + (src[2] & 0xff) + "." + (src[3] & 0xff);
|
private java.lang.Object | writeReplace()Replaces the object to be serialized with an InetAddress object.
// will replace the to be serialized 'this' object
InetAddress inet = new InetAddress();
inet.hostName = this.hostName;
inet.address = this.address;
/**
* Prior to 1.4 an InetAddress was created with a family
* based on the platform AF_INET value (usually 2).
* For compatibility reasons we must therefore write the
* the InetAddress with this family.
*/
inet.family = 2;
return inet;
|