Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.net

Class InetAddress

java.lang.Object
|
+--java.net.InetAddress

All Implemented Interfaces:

Serializable


public class InetAddress

extends Object

implements 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:

Constructor Summary

InetAddress(byte[] ipaddr)

Initializes this object's addr instance variable from the passed in int array.
InetAddress(byte[] ipaddr, java.lang.String hostname)

Initializes this object's addr instance variable from the passed in int array.
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.

Method Summary

booleanequals(java.lang.Object obj)

Tests this address for equality against another InetAddress.
byte[]getAddress()

Returns the IP address of this object as a int array.
static java.net.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.
static java.net.InetAddressgetByAddress(byte[] addr)

Returns an InetAddress object given the raw IP address.
static java.net.InetAddressgetByName(java.lang.String hostname)

Returns an InetAddress object representing the IP address of the given hostname.
java.lang.StringgetHostAddress()

Returns the IP address of this object as a String.
java.lang.StringgetHostName()

Returns the hostname for this address.
static java.net.InetAddressgetLocalHost()

Returns an InetAddress object representing the address of the current host.
inthashCode()

Returns a hash value for this address.
booleanisMulticastAddress()

Returns true if this address is a multicast address, false otherwise.
java.lang.StringtoString()

Converts this address to a String.

Constructor Details

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:


Method Details

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:


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:

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:

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:


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:


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:


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:


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: