Packages  This Package  Prev  Next  Index  

§4.4 Class InetAddress

public  final  class  java.net.InetAddress
    extends  java.lang.Object  (I-§1.12)
{
        // Methods
    public boolean equals(Object  obj);	§4.4.1
    public byte[] getAddress();	§4.4.2
    public static InetAddress[] getAllByName(String  host);	§4.4.3
    public static InetAddress getByName(String  host);	§4.4.4
    public String getHostName();	§4.4.5
    public static InetAddress getLocalHost();	§4.4.6
    public int hashCode();	§4.4.7
    public String toString();	§4.4.8
}
This class represents an Internet Protocol (IP) address.

Applications should use the methods getLocalHost (I-§4.4.6), getByName (I-§4.4.4), or getAllByName (I-§4.4.3) to create a new InetAddress instance.


Methods

equals

public boolean equals(Object obj)
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 (I-§4.4.2) is the same for both, and each of the array components is the same for the byte arrays.

Parameters:
obj - the object to compare against
Returns:
true if the objects are the same; false otherwise.
Overrides:
equals in class Object (I-§1.12.3).

getAddress

public byte[] getAddress()
Determines the raw IP address of this InetAddress object. The result is in network byte order: the highest order byte of the address is in get-Address()[0].
Returns:
the raw IP address of this object.

getAllByName

public static InetAddress[] getAllByName(String host) throws UnknownHostException
Parameters:
host - the name of the host
Returns:
an array of all the IP addresses for a given host name.
Throws
UnknownHostException (I-§4.18)
If no IP address for the host could be found.

getByName

public static InetAddress getByName(String host) throws UnknownHostException
Determines the IP address of a host, given the host's name. The host name can either be a machine name, such as "java.sun.com" or a string representing its IP address, such as "206.26.48.100".
Parameters:
host - the specified host, or null for the local host
Returns:
an IP address for the given host name.
Throws
UnknownHostException (I-§4.18)
If no IP address for the host could be found.

getHostName

public String getHostName()
Returns:
the host name for this IP address.

getLocalHost

public static InetAddress getLocalHost() throws UnknownHostException
Returns:
the IP address of the local host.
Throws
UnknownHostException (I-§4.18)
If no IP address for the host could be found.

hashCode

public int hashCode()
Returns:
a hash code value for this IP address.
Overrides:
hashCode in class Object (I-§1.12.6).

toString

public String toString()
Returns:
a string representation of this IP address.
Overrides:
toString in class Object (I-§1.12.9).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com