Build 1.0_r1(from source)

java.net
Class InetAddress

java.lang.Object
  extended by java.net.InetAddress
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Inet4Address, Inet6Address

public class InetAddress
extends Object
implements Serializable

The Internet Protocol (IP) address class. This class encapsulates an IP address and provides name and reverse name resolution functions. The address is stored in network order, but as a signed (rather than unsigned) integer.

See Also:
Serialized Form

Nested Class Summary
(package private) static class InetAddress.Cache
           
(package private)  class InetAddress.CacheElement
           
 
Field Summary
(package private) static InetAddress ANY
           
(package private) static byte[] any_bytes
           
(package private)  int family
           
(package private)  String hostName
           
(package private)  byte[] ipaddress
           
(package private) static byte[] localhost_bytes
           
(package private) static InetAddress LOOPBACK
           
 
Constructor Summary
InetAddress()
          Constructs an InetAddress.
InetAddress(byte[] address)
          Constructs an InetAddress, representing the address and hostName.
InetAddress(byte[] address, String hostName)
          Constructs an InetAddress, representing the address and hostName.
 
Method Summary
(package private) static byte[] addressOf(int addr)
          Returns the IP address of the argument addr as an array.
(package private) static int bytesToInt(byte[] bytes, int start)
          Takes the byte array and creates an integer out of four bytes starting at start as the high-order byte.
(package private)  InetAddress.CacheElement cacheElement()
           
(package private) static InetAddress createHostNameFromIPAddress(String ipAddressString)
          Creates an InetAddress based on an ipAddressString.
 boolean equals(Object obj)
          Compares this InetAddress against the specified object.
 byte[] getAddress()
          Returns the IP address of this InetAddress as an array.
(package private) static InetAddress[] getAliasesByNameImpl(String name)
          Query the IP stack for aliases for the host.
static InetAddress[] getAllByName(String host)
          Answer the IP addresses of a named host.
static InetAddress getByAddress(byte[] ipAddress)
          Returns the InetAddress corresponding to the array of bytes.
(package private) static InetAddress getByAddress(byte[] ipAddress, int scope_id)
          Returns the InetAddress corresponding to the array of bytes.
static InetAddress getByAddress(String hostName, byte[] ipAddress)
          Returns the InetAddress corresponding to the array of bytes, and the given hostname.
(package private) static InetAddress getByAddressInternal(String hostName, byte[] ipAddress, int scope_id)
          Returns the InetAddress corresponding to the array of bytes, and the given hostname.
static InetAddress getByName(String host)
          Returns the address of a host, given a host string name.
 String getCanonicalHostName()
          Returns canonical name for the host associated with the internet address
 String getHostAddress()
          Answer the dotted string IP address representing this address.
(package private) static InetAddress getHostByAddrImpl(byte[] addr)
          Query the IP stack for the host address.
(package private) static InetAddress getHostByNameImpl(String name, boolean preferIPv6Address)
          Query the IP stack for the host address.
 String getHostName()
          Answer the host name.
(package private) static String getHostNameImpl()
          Query the IP stack for the host machine name.
(package private) static String getHostNameInternal(String host)
           
static InetAddress getLocalHost()
          Answer the local host, if allowed by the security policy.
 int hashCode()
          Answer a hashcode for this IP address.
(package private) static int inetAddr(String host)
           
(package private) static int inetAddrImpl(String host)
          Convert a string containing an Ipv4 Internet Protocol dotted address into a binary address.
(package private) static String inetNtoaImpl(int hipAddr)
          Convert a binary address into a string containing an Ipv4 Internet Protocol dotted address.
(package private) static void intToBytes(int value, byte[] bytes, int start)
          Takes the integer and chops it into 4 bytes, putting it into the byte array starting with the high order byte at the index start.
 boolean isAnyLocalAddress()
          Method isAnyLocalAddress.
 boolean isLinkLocalAddress()
          Returns true if the address is a link local address.
 boolean isLoopbackAddress()
          Answer true if the address is a loop back address.
 boolean isMCGlobal()
          Returns true if the address is a global multicast address.
 boolean isMCLinkLocal()
          Returns true if the address is a link local multicast address.
 boolean isMCNodeLocal()
          Returns true if the address is a node local multicast address.
 boolean isMCOrgLocal()
          Returns true if the address is a organization local multicast address.
 boolean isMCSiteLocal()
          Returns true if the address is a site local multicast address.
 boolean isMulticastAddress()
          Answer true if the InetAddress is an IP multicast address.
 boolean isReachable(int timeout)
          Tries to see if the InetAddress is reachable.
 boolean isReachable(NetworkInterface netif, int ttl, int timeout)
          Tries to see if the InetAddress is reachable.
 boolean isSiteLocalAddress()
          Returns true if the address is a site local address.
(package private) static InetAddress lookupHostByName(String host)
           
(package private) static boolean preferIPv6Addresses()
           
 String toString()
          Returns a string containing a concise, human-readable description of the address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

any_bytes

static final byte[] any_bytes

localhost_bytes

static final byte[] localhost_bytes

ANY

static InetAddress ANY

LOOPBACK

static final InetAddress LOOPBACK

hostName

String hostName

family

int family

ipaddress

byte[] ipaddress
Constructor Detail

InetAddress

InetAddress()
Constructs an InetAddress.


InetAddress

InetAddress(byte[] address)
Constructs an InetAddress, representing the address and hostName.

Parameters:
address - network address

InetAddress

InetAddress(byte[] address,
            String hostName)
Constructs an InetAddress, representing the address and hostName.

Parameters:
address - network address
Method Detail

addressOf

static byte[] addressOf(int addr)
Returns the IP address of the argument addr as an array. The elements are in network order (the highest order address byte is in the zero-th element).

Returns:
byte[] the network address as a byte array

cacheElement

InetAddress.CacheElement cacheElement()

equals

public boolean equals(Object obj)
Compares this InetAddress against the specified object.

Overrides:
equals in class Object
Parameters:
obj - the object to be tested for equality
Returns:
boolean true, if the objects are equal
See Also:
Object.hashCode()

getAddress

public byte[] getAddress()
Returns the IP address of this InetAddress as an array. The elements are in network order (the highest order address byte is in the zero-th element).

Returns:
byte[] the address as a byte array

getAllByName

public static InetAddress[] getAllByName(String host)
                                  throws UnknownHostException
Answer the IP addresses of a named host. The host name may either be a machine name or a dotted string IP address. If the host name is empty or null, an UnknownHostException is thrown. If the host name is a dotted IP string, an array with the corresponding single InetAddress is returned.

Parameters:
host - the hostName to be resolved to an address
Returns:
InetAddress[] an array of addresses for the host
Throws:
UnknownHostException - if the address lookup fails

getByName

public static InetAddress getByName(String host)
                             throws UnknownHostException
Returns the address of a host, given a host string name. The host string may be either a machine name or a dotted string IP address. If the latter, the hostName field will be determined upon demand.

Parameters:
host - the hostName to be resolved to an address
Returns:
InetAddress the InetAddress representing the host
Throws:
UnknownHostException - if the address lookup fails

getHostAddress

public String getHostAddress()
Answer the dotted string IP address representing this address.

Returns:
String the corresponding dotted string IP address

getHostName

public String getHostName()
Answer the host name.

Returns:
String the corresponding string name

getCanonicalHostName

public String getCanonicalHostName()
Returns canonical name for the host associated with the internet address

Returns:
String string containing the host name

getLocalHost

public static InetAddress getLocalHost()
                                throws UnknownHostException
Answer the local host, if allowed by the security policy. Otherwise, answer the loopback address which allows this machine to be contacted.

Returns:
InetAddress the InetAddress representing the local host
Throws:
UnknownHostException - if the address lookup fails

hashCode

public int hashCode()
Answer a hashcode for this IP address.

Overrides:
hashCode in class Object
Returns:
int the hashcode
See Also:
Object.equals(java.lang.Object)

isMulticastAddress

public boolean isMulticastAddress()
Answer true if the InetAddress is an IP multicast address.

Returns:
boolean true, if the address is in the multicast group

lookupHostByName

static InetAddress lookupHostByName(String host)
                             throws UnknownHostException
Throws:
UnknownHostException

getAliasesByNameImpl

static InetAddress[] getAliasesByNameImpl(String name)
                                   throws UnknownHostException
Query the IP stack for aliases for the host. The host is in string name form. If the host does not have aliases (only multi-homed hosts do), answer an array with a single InetAddress constructed from the host name & address.

Parameters:
name - the host name to lookup
Throws:
UnknownHostException - if an error occurs during lookup

getHostByAddrImpl

static InetAddress getHostByAddrImpl(byte[] addr)
                              throws UnknownHostException
Query the IP stack for the host address. The host is in address form.

Parameters:
addr - the host address to lookup
Throws:
UnknownHostException - if an error occurs during lookup

inetAddr

static int inetAddr(String host)
             throws UnknownHostException
Throws:
UnknownHostException

inetAddrImpl

static int inetAddrImpl(String host)
                 throws UnknownHostException
Convert a string containing an Ipv4 Internet Protocol dotted address into a binary address. Note, the special case of '255.255.255.255' throws an exception, so this value should not be used as an argument. See also inetAddr(String).

Throws:
UnknownHostException

inetNtoaImpl

static String inetNtoaImpl(int hipAddr)
Convert a binary address into a string containing an Ipv4 Internet Protocol dotted address.


getHostByNameImpl

static InetAddress getHostByNameImpl(String name,
                                     boolean preferIPv6Address)
                              throws UnknownHostException
Query the IP stack for the host address. The host is in string name form.

Parameters:
name - the host name to lookup
preferIPv6Addresses - address preference if underlying platform is V4/V6
Returns:
InetAddress the host address
Throws:
UnknownHostException - if an error occurs during lookup

getHostNameImpl

static String getHostNameImpl()
Query the IP stack for the host machine name.

Returns:
String the host machine name

getHostNameInternal

static String getHostNameInternal(String host)
                           throws UnknownHostException
Throws:
UnknownHostException

toString

public String toString()
Returns a string containing a concise, human-readable description of the address.

Overrides:
toString in class Object
Returns:
String the description, as host/address

isLoopbackAddress

public boolean isLoopbackAddress()
Answer true if the address is a loop back address. Valid IPv4 loopback addresses are 127.d.d.d Valid IPv6 loopback address is ::1

Returns:
boolean

isLinkLocalAddress

public boolean isLinkLocalAddress()
Returns true if the address is a link local address. Valid IPv6 link local addresses are FE80::0 through to FEBF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF There are no valid IPv4 link local addresses.

Returns:
boolean

isSiteLocalAddress

public boolean isSiteLocalAddress()
Returns true if the address is a site local address. Valid IPv6 link local addresses are FEC0::0 through to FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF There are no valid IPv4 site local addresses.

Returns:
boolean

isMCGlobal

public boolean isMCGlobal()
Returns true if the address is a global multicast address. Valid IPv6 link global multicast addresses are FFxE:/112 where x is a set of flags, and the additional 112 bits make up the global multicast address space Valid IPv4 global multicast addresses are between: 224.0.1.0 to 238.255.255.255

Returns:
boolean

isMCNodeLocal

public boolean isMCNodeLocal()
Returns true if the address is a node local multicast address. Valid IPv6 node local multicast addresses are FFx1:/112 where x is a set of flags, and the additional 112 bits make up the node local multicast address space There are no valid IPv4 node local multicast addresses.

Returns:
boolean

isMCLinkLocal

public boolean isMCLinkLocal()
Returns true if the address is a link local multicast address. Valid IPv6 link local multicast addresses are FFx2:/112 where x is a set of flags, and the additional 112 bits make up the node local multicast address space Valid IPv4 link-local addresses are between: 224.0.0.0 to 224.0.0.255

Returns:
boolean

isMCSiteLocal

public boolean isMCSiteLocal()
Returns true if the address is a site local multicast address. Valid IPv6 site local multicast addresses are FFx5:/112 where x is a set of flags, and the additional 112 bits make up the node local multicast address space Valid IPv4 site-local addresses are between: 239.252.0.0 to 239.255.255.255

Returns:
boolean

isMCOrgLocal

public boolean isMCOrgLocal()
Returns true if the address is a organization local multicast address. Valid IPv6 organization local multicast addresses are FFx8:/112 where x is a set of flags, and the additional 112 bits make up the node local multicast address space Valid IPv4 organization-local addresses are between: 239.192.0.0 to 239.251.255.255

Returns:
boolean

isAnyLocalAddress

public boolean isAnyLocalAddress()
Method isAnyLocalAddress.

Returns:
boolean

isReachable

public boolean isReachable(int timeout)
                    throws IOException
Tries to see if the InetAddress is reachable. This method first tries to use ICMP(ICMP ECHO REQUEST). When first step fails, the TCP connection on port 7 (Echo) shall be lauched.

Parameters:
timeout - timeout in milliseconds
Returns:
true if address is reachable
Throws:
IOException - if I/O operation meets error
IllegalArgumentException - if timeout is less than zero

isReachable

public boolean isReachable(NetworkInterface netif,
                           int ttl,
                           int timeout)
                    throws IOException
Tries to see if the InetAddress is reachable. This method first tries to use ICMP(ICMP ECHO REQUEST). When first step fails, the TCP connection on port 7 (Echo) shall be lauched.

Parameters:
netif - the network interface through which to connect
ttl - max hops to live
timeout - timeout in milliseconds
Returns:
true if address is reachable
Throws:
IOException - if I/O operation meets error
IllegalArgumentException - if ttl or timeout is less than zero

getByAddress

public static InetAddress getByAddress(byte[] ipAddress)
                                throws UnknownHostException
Returns the InetAddress corresponding to the array of bytes. In the case of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is thrown. The IP address is not validated by a name service. The high order byte is ipAddress[0].

Parameters:
ipAddress - either a 4 (IPv4) or 16 (IPv6) byte array
Returns:
the InetAddress
Throws:
UnknownHostException

getByAddress

static InetAddress getByAddress(byte[] ipAddress,
                                int scope_id)
                         throws UnknownHostException
Returns the InetAddress corresponding to the array of bytes. In the case of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is thrown. The IP address is not validated by a name service. The high order byte is ipAddress[0].

Parameters:
ipAddress - either a 4 (IPv4) or 16 (IPv6) byte array
scope_id - the scope id for an IPV6 scoped address. If not a scoped address just pass in 0
Returns:
the InetAddress
Throws:
UnknownHostException

getByAddress

public static InetAddress getByAddress(String hostName,
                                       byte[] ipAddress)
                                throws UnknownHostException
Returns the InetAddress corresponding to the array of bytes, and the given hostname. In the case of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is thrown. The host name and IP address are not validated. The hostname either be a machine alias or a valid IPv6 or IPv4 address format. The high order byte is ipAddress[0].

Parameters:
hostName - string representation of hostname or ip address
ipAddress - either a 4 (IPv4) or 16 (IPv6) byte array
Returns:
the InetAddress
Throws:
UnknownHostException

getByAddressInternal

static InetAddress getByAddressInternal(String hostName,
                                        byte[] ipAddress,
                                        int scope_id)
                                 throws UnknownHostException
Returns the InetAddress corresponding to the array of bytes, and the given hostname. In the case of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is thrown. The host name and IP address are not validated. The hostname either be a machine alias or a valid IPv6 or IPv4 address format. The high order byte is ipAddress[0].

Parameters:
hostName - string representation of hostname or IP address
ipAddress - either a 4 (IPv4) or 16 (IPv6) byte array
scope_id - the scope id for a scoped address. If not a scoped address just pass in 0
Returns:
the InetAddress
Throws:
UnknownHostException

intToBytes

static void intToBytes(int value,
                       byte[] bytes,
                       int start)
Takes the integer and chops it into 4 bytes, putting it into the byte array starting with the high order byte at the index start. This method makes no checks on the validity of the parameters.


bytesToInt

static int bytesToInt(byte[] bytes,
                      int start)
Takes the byte array and creates an integer out of four bytes starting at start as the high-order byte. This method makes no checks on the validity of the parameters.


createHostNameFromIPAddress

static InetAddress createHostNameFromIPAddress(String ipAddressString)
                                        throws UnknownHostException
Creates an InetAddress based on an ipAddressString. No error handling is performed here.

Throws:
UnknownHostException

preferIPv6Addresses

static boolean preferIPv6Addresses()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature