jpcap
Class IPAddress

java.lang.Object
  |
  +--jpcap.IPAddress

public class IPAddress
extends java.lang.Object

This class represents an IP address.

This class represents both IPv4 and IPv6 address. This class also contains methods to convert an IP address to a domain name, and vise vesa.


Constructor Summary
IPAddress(byte[] address)
          Creates an IPv4 address represented by the byte array.
This method does not check whether the address is valid or not.
IPAddress(int version, byte[] address)
          Creates an IP address represented by the byte array in the specified version.
This method does not check whether the address is valid or not.
IPAddress(int version, java.lang.String address)
          Creates an IP address of the specified IP address or domain name in the specified version.
IPAddress(java.lang.String address)
          Creates an IPv4 address of the specified IP address or domain name.
 
Method Summary
 boolean equals(java.lang.Object p)
          Indicates whether some other object is "equal to" this one.
 byte[] getAddress()
          Returns this IP address as a byte array
 java.lang.String getHostAddress()
          Returns this IP address as a string.
 java.lang.String getHostName()
          Returns the domain name of this address.
 java.net.InetAddress getInetAddress()
          Returns an instance of java.net.InetAddress.
 int hashCode()
          Returns the hash code of this address.
static void setAddressConvert(boolean isDomainName)
          Specifies which representation (domain name or IP address ("%d.%d.%d.%d" or "%x:%x::%x:%x")) is used in toString().
 java.lang.String toString()
          Returns a string representation (either as a domain name as an IP address) of this IP address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IPAddress

public IPAddress(int version,
                 java.lang.String address)
          throws java.net.UnknownHostException
Creates an IP address of the specified IP address or domain name in the specified version.

Parameters:
version - IP version
address - IP address or domain name
Throws:
java.net.UnknownHostException - Raised when the specified address was illegal

IPAddress

public IPAddress(java.lang.String address)
          throws java.net.UnknownHostException
Creates an IPv4 address of the specified IP address or domain name.

Parameters:
address - IP address or domain name
Throws:
java.net.UnknownHostException - Raised when the specified address was illegal

IPAddress

public IPAddress(int version,
                 byte[] address)
Creates an IP address represented by the byte array in the specified version.
This method does not check whether the address is valid or not.

Parameters:
version - IP version
address - Byte array representing an IP address

IPAddress

public IPAddress(byte[] address)
Creates an IPv4 address represented by the byte array.
This method does not check whether the address is valid or not.

Parameters:
address - Byte array representing an IP address
Method Detail

getAddress

public byte[] getAddress()
Returns this IP address as a byte array

Returns:
Byte array representation of this address

getHostAddress

public java.lang.String getHostAddress()
Returns this IP address as a string. ("%d.%d.%d.%d" or "%x:%x::%x:%x")

Returns:
String representation of this address

getHostName

public java.lang.String getHostName()
                             throws java.net.UnknownHostException
Returns the domain name of this address.

Returns:
Domain name of this address
Throws:
java.net.UnknownHostException - Raised when the domain name cannot be found

getInetAddress

public java.net.InetAddress getInetAddress()
                                    throws java.net.UnknownHostException
Returns an instance of java.net.InetAddress. (Only if the IP version is 4. Returns null if the version is 6.)

Returns:
an instance of java.net.InetAddress. Null if the version is 6.
Throws:
java.net.UnknownHostException - Raised when the address cannot be converted into java.net.InetAddress

equals

public boolean equals(java.lang.Object p)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
p - the reference object with which to compare
Returns:
true if this object is the same as the obj argument; false otherwise

setAddressConvert

public static void setAddressConvert(boolean isDomainName)
Specifies which representation (domain name or IP address ("%d.%d.%d.%d" or "%x:%x::%x:%x")) is used in toString().

Parameters:
isDomainName - If true, domain name is used. If false, IP address is used

toString

public java.lang.String toString()
Returns a string representation (either as a domain name as an IP address) of this IP address.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this IP address
See Also:
setAddressConvert()

hashCode

public int hashCode()
Returns the hash code of this address.

Overrides:
hashCode in class java.lang.Object
Returns:
hash code of this address