java.net
Class InetAddress
java.lang.Object
|
+--java.net.InetAddress
All Implemented Interfaces:
Serializable
This class models an Internet address. It does not have a public
constructor. Instead, new instances of this objects are created
using the static methods getLocalHost(), getByName(), and
getAllByName().
This class fulfills the function of the C style functions gethostname(),
gethostbyname(), and gethostbyaddr(). It resolves Internet DNS names
into their corresponding numeric addresses and vice versa.
Author:- Aaron M. Renn (arenn@urbanophile.com)
InetAddress
public InetAddress(byte[] ipaddr)
Initializes this object's addr instance variable from the passed in
int array. Note that this constructor is protected and is called
only by static methods in this class.
Parameters:
InetAddress
public InetAddress(byte[] ipaddr, java.lang.String hostname)
Initializes this object's addr instance variable from the passed in
int array. Note that this constructor is protected and is called
only by static methods in this class.
Parameters:
InetAddress
public InetAddress(byte[] ipaddr, java.lang.String hostname, java.lang.String hostname_alias)
Initializes this object's addr instance variable from the passed in
int array. Note that this constructor is protected and is called
only by static methods in this class.
Parameters:
equals
public boolean equals(java.lang.Object obj)
Tests this address for equality against another InetAddress. The two
addresses are considered equal if they contain the exact same octets.
This implementation overrides Object.equals()
Parameters:
Returns:
- true if the passed in object's address is equal to this one's,
false otherwise
getAddress
public byte[] getAddress()
Returns the IP address of this object as a int array.
Returns:
getAllByName
public static InetAddress[] getAllByName(java.lang.String hostname)
Returns an array of InetAddress objects representing all the host/ip
addresses of a given host, given the host's name. This name can be
either a hostname such as "www.urbanophile.com" or an IP address in
dotted decimal format such as "127.0.0.1". If the value is null, the
hostname of the local machine is supplied by default.
Parameters:
Returns:
- All addresses of the host as an array of InetAddress's
Throws:
getByAddress
public static InetAddress getByAddress(byte[] addr)
Returns an InetAddress object given the raw IP address.
The argument is in network byte order: the highest order byte of the
address is in getAddress()[0].
Since:Parameters:
Throws:
getByName
public static InetAddress getByName(java.lang.String hostname)
Returns an InetAddress object representing the IP address of the given
hostname. This name can be either a hostname such as "www.urbanophile.com"
or an IP address in dotted decimal format such as "127.0.0.1". If the
hostname is null, the hostname of the local machine is supplied by
default. This method is equivalent to returning the first element in
the InetAddress array returned from GetAllByName.
Parameters:
Returns:
- The address of the host as an InetAddress
Throws:
getHostAddress
public String getHostAddress()
Returns the IP address of this object as a String. The address is in
the dotted octet notation, for example, "127.0.0.1".
Returns:
- The IP address of this object in String form
getHostName
public String getHostName()
Returns the hostname for this address. This will return the IP address
as a String if there is no hostname available for this address
Returns:
- The hostname for this address
getLocalHost
public static InetAddress getLocalHost()
Returns an InetAddress object representing the address of the current
host.
Returns:
Throws:
hashCode
public int hashCode()
Returns a hash value for this address. Useful for creating hash
tables. Overrides Object.hashCode()
Returns:
- A hash value for this address.
isMulticastAddress
public boolean isMulticastAddress()
Returns true if this address is a multicast address, false otherwise.
An address is multicast if the high four bits are "1110". These are
also known as "Class D" addresses.
Returns:
- true if mulitcast, false if not
toString
public String toString()
Converts this address to a String. This string contains the IP in
dotted decimal form. For example: "127.0.0.1" This method is equivalent
to getHostAddress() and overrides Object.toString()
Returns:
- This address in String form
This class fulfills the function of the C style functions gethostname(), gethostbyname(), and gethostbyaddr(). It resolves Internet DNS names into their corresponding numeric addresses and vice versa.