edu.virginia.cs.mng.hypercast
Class IP_Address

java.lang.Object
  |
  +--edu.virginia.cs.mng.hypercast.IP_Address

public final 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
private  java.net.InetAddress address
           
private static int MAX_PORT
           
private static int MIN_PORT
           
private  int port
           
 
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(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
private static java.net.InetAddress createInetAddress(byte[] byteAddress)
          Constructs an instance of InetAddress from a byte array.
 boolean equals(java.lang.Object obj)
          Compares two IP address.
 byte[] getByteAddress()
          Gets byte address of this object.
 java.net.InetAddress getInetAddress()
          Gets IP address of this object.
 int getPort()
          Gets port number of this IP_Address object.
 int getSize()
          Returns the byte array size
 boolean greaterThan(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.
 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
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

MIN_PORT

private static final int MIN_PORT

MAX_PORT

private static final int MAX_PORT

address

private java.net.InetAddress address

port

private int port
Constructor Detail

IP_Address

public IP_Address(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:
ipAddr - any object of type IP_Address

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:
byteAddress[] - 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)
           throws java.net.UnknownHostException
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)
           throws java.net.UnknownHostException
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

createInetAddress

private static java.net.InetAddress createInetAddress(byte[] byteAddress)
Constructs an instance of InetAddress from a byte array.

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.

getSize

public int getSize()
Returns the byte array size

toByteArray

public byte[] toByteArray()
Converts the Address/Port pair to a 6 bytes array.
Returns:
a 6 byte array where the first 4 bytes holds the address, the last 2 holds the port

equals

public boolean equals(java.lang.Object obj)
Compares two IP address. It is important that the argument is of type Object so that it can be used in a Hashtable.
Parameters:
obj - an object (should be of type IP_Address.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type IP_Address.
Overrides:
equals in class java.lang.Object

greaterThan

public boolean greaterThan(I_Address addr)
Compares two IP address objects.
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.
Overrides:
hashCode in class java.lang.Object