hypercast
Class IP_Address

java.lang.Object
  |
  +--hypercast.IP_Address
All Implemented Interfaces:
I_Address, I_NetworkAddress, I_PhysicalAddress

public class IP_Address
extends java.lang.Object
implements I_PhysicalAddress

This class includes all the functions related to an Internet Address/Port pair. The port is always valid (i.e. in the range 0 to (2^16)-1).


Field Summary
static int ADDRESS_SIZE
          The size of IP_Address type physical address when carried in the packet.
 
Constructor Summary
IP_Address(byte[] byteAddressAndPort)
          Constructs a IP_Address object from an 6 byte array.
IP_Address(byte[] byteAddress, int p)
          Constructs a IP_Address object from a byte array address and a port number.
IP_Address(java.net.DatagramSocket udpSocket)
          Constructs the IP_Address object cooresponding to the java.net.DatagramSocket.
IP_Address(java.net.InetAddress a, int p)
          Constructs a IP_Address object from an InetAddress instance and port number.
IP_Address(int portnum)
          Constructs the IP_Address object which has the specified port number.
IP_Address(hypercast.IP_Address ipAddr)
          Constructs a new IP_Address object from an IP_Address object.
IP_Address(java.lang.String addrAndPortString)
          Constructs a IP_Address object from a string containing the address and port separated by a '/' or ':'.
IP_Address(java.lang.String addrString, int p)
          Constructs a IP_Address object from a string address and a port number.
 
Method Summary
 boolean addressCheck(java.lang.Object obj)
          Test if two IP addresses are identical.
 boolean equals(java.lang.Object obj)
          Test if two IP addresses are identical.
 byte[] getByteAddress()
          Gets byte address of this object.
 java.net.InetAddress getInetAddress()
          Gets IP address of this object.
 java.lang.String getLocalIPbyDNS()
          Obtain local IP address by a DNS query and return local IP address in String form.
 int getPort()
          Gets port number of this IP_Address object.
 int getSize()
          Returns the byte array size
 boolean greaterThan(hypercast.I_Address addr)
          Compares two IP address objects.
 int hashCode()
          Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.
 void setPort(int Port)
          Sets port number of this IP_Address object.
 byte[] toByteArray()
          Converts the Address/Port pair to a 6 bytes array.
 java.lang.String toString()
          Converts the IP address object to string format "xxx.xxx.xxx.xxx/port" (e.g.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ADDRESS_SIZE

public static final int ADDRESS_SIZE
The size of IP_Address type physical address when carried in the packet.

See Also:
Constant Field Values
Constructor Detail

IP_Address

public IP_Address(hypercast.IP_Address ipAddr)
Constructs a new IP_Address object from an IP_Address object.

Parameters:
ipAddr - any object of type IP_Address

IP_Address

public IP_Address(java.net.DatagramSocket udpSocket)
Constructs the IP_Address object cooresponding to the java.net.DatagramSocket.

Parameters:
udpSocket - any object of type DatagramSocket

IP_Address

public IP_Address(int portnum)
Constructs the IP_Address object which has the specified port number.

Parameters:
portnum - a port number.

IP_Address

public IP_Address(java.net.InetAddress a,
                  int p)
Constructs a IP_Address object from an InetAddress instance and port number.

Parameters:
a - an instance of InetAddress
p - a port number
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1

IP_Address

public IP_Address(byte[] byteAddress,
                  int p)
Constructs a IP_Address object from a byte array address and a port number.

Parameters:
byteAddress - an Internet address as a byte array
p - port number
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1

IP_Address

public IP_Address(byte[] byteAddressAndPort)
Constructs a IP_Address object from an 6 byte array. This uses 2 more bytes than necessary. This is as Tyler Beam initially implemented it.

Parameters:
byteAddressAndPort - an Internet address and port stored in a byte array
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1

IP_Address

public IP_Address(java.lang.String addrString,
                  int p)
Constructs a IP_Address object from a string address and a port number.

Parameters:
addrString - a string representing the IP address (eg. "128.143.71.50")
p - The port.
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1
java.net.UnknownHostException - thrown by InetAddress.getByName

IP_Address

public IP_Address(java.lang.String addrAndPortString)
Constructs a IP_Address object from a string containing the address and port separated by a '/' or ':'.

Parameters:
addrAndPortString - a string representing the IP address and port (eg. "128.143.71.50/4747")
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1
java.net.UnknownHostException - thrown by InetAddress.getByName
Method Detail

getInetAddress

public java.net.InetAddress getInetAddress()
Gets IP address of this object.


getByteAddress

public byte[] getByteAddress()
Gets byte address of this object.

Returns:
A byte[] as returned by InetAddress.getAddress.

getPort

public int getPort()
Gets port number of this IP_Address object.


setPort

public void setPort(int Port)
Sets port number of this IP_Address object.


getSize

public int getSize()
Returns the byte array size

Specified by:
getSize in interface I_Address

toByteArray

public byte[] toByteArray()
Converts the Address/Port pair to a 6 bytes array. The format is |-------4------|----2----| | IP |node port| | | | |--------------|---------|

Specified by:
toByteArray in interface I_Address
Returns:
a 6 byte array where the first 4 bytes holds the address, the next 2 holds the port, the following 1 holds index and the last 1 holds node protocol and application protocol

equals

public boolean equals(java.lang.Object obj)
Test if two IP addresses are identical. It is important that the argument is of type Object so that it can be used in a Hashtable.

Specified by:
equals in interface I_Address
Overrides:
equals in class java.lang.Object
Parameters:
obj - an object (should be of type IP_Address.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type IP_Address.

addressCheck

public boolean addressCheck(java.lang.Object obj)
Test if two IP addresses are identical. It is important that the argument is of type Object so that it can be used in a Hashtable.

Specified by:
addressCheck in interface I_PhysicalAddress
Parameters:
obj - an object (should be of type IP_Address.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type IP_Address.

greaterThan

public boolean greaterThan(hypercast.I_Address addr)
Compares two IP address objects.

Specified by:
greaterThan in interface I_Address
Parameters:
addr - an object of type I_Address
Returns:
true if (this > addr), otherwise false
Throws:
java.lang.IllegalArgumentException - if obj is not of type IP_Address.

toString

public java.lang.String toString()
Converts the IP address object to string format "xxx.xxx.xxx.xxx/port" (e.g. "128.143.71.50/4747")

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.

Specified by:
hashCode in interface I_Address
Overrides:
hashCode in class java.lang.Object

getLocalIPbyDNS

public java.lang.String getLocalIPbyDNS()
Obtain local IP address by a DNS query and return local IP address in String form.