Package java.net Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class InetAddress

Methods

public  final  class  java.net.InetAddress
    extends  java.lang.Object  
{
        // Methods
    public boolean equals(Object  obj);	
    public byte[] getAddress();	
    public static InetAddress[] getAllByName(String  host);	
    public static InetAddress getByName(String  host);	
    public String getHostName();	
    public static InetAddress getLocalHost();	
    public int hashCode();	
    public String toString();	
}

This class represents an Internet Protocol (IP) address.

Applications should use the methods getLocalHost , getByName , or getAllByName 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 is the same for both, and each of the array components is the same for the byte arrays.

Return Value:

Returns true if the objects are the same; false otherwise.

ParameterDescription
obj the object to compare against

Overrides:

equals in class Object .


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].

Return Value:

Returns the raw IP address of this object.


getAllByName

public static  InetAddress[]  getAllByName(String  host) 
throws UnknownHostException 

Return Value:

Returns an array of all the IP addresses for a given host name.

ParameterDescription
host the name of the host

Throw:

UnknownHostException

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".

Return Value:

Returns an IP address for the given host name.

ParameterDescription
host the specified host, or null for the local host

Throw:

UnknownHostException

If no IP address for the host could be found.


getHostName

public String getHostName() 

Return Value:

Returns the host name for this IP address.


getLocalHost

public static InetAddress getLocalHost() 
throws UnknownHostException 

Return Value:

Returns the IP address of the local host.

Throw:

UnknownHostException

If no IP address for the host could be found.


hashCode

public int hashCode() 

Return Value:

Returns a hash code value for this IP address.

Overrides:

hashCode in class Object .


toString

public String toString() 

Return Value:

Returns a string representation of this IP address.

Overrides:

toString in class Object .



Top© 1996 Sun Microsystems, Inc. All rights reserved.