CTL.Types
Class IPaddr

java.lang.Object
  extended by CTL.Types.IPaddr
All Implemented Interfaces:
Writable

public class IPaddr
extends java.lang.Object
implements Writable

IP address storage and serialization for IPv4 and IPv6


Field Summary
private  short[] IP
          8 x 16 Bit = 128 Bit, which is the length of an IPv6 address
 
Constructor Summary
IPaddr()
          Create an IPaddr for localhost
IPaddr(java.net.InetAddress in)
          Create an IPaddr from the Java InetAddress type
IPaddr(long ip)
          Create an IPaddr from an 'unsigned int32'
IPaddr(java.lang.String host)
          Create an IPaddr from a hostname
IPaddr(java.lang.String str, int i)
          Create an IPaddr from a hexadecimal string
 
Method Summary
 boolean equals(java.net.InetAddress ip)
          Check if two InetAddresses are equal
 boolean equals(IPaddr ip)
          Check if two IPaddrs are equal
static short[] getShortArray(java.net.InetAddress ip)
          Convert an InetAddress to a short array
 long getUint32()
          Convert this to an integer
static long getUint32(java.net.InetAddress ip)
          Convert ip to an integer
 short[] rawIP()
          Retrieve the raw short array
 void read(SerialIn in)
          Serial read function
static java.net.InetAddress setShortArray(short[] ip)
          Convert a short array to InetAddress
static java.net.InetAddress setUint32(long ip)
          Convert an integer to InetAddress
 java.net.InetAddress toInetAddress()
          Retrieve an InetAddress representation of this object
 java.lang.String toString()
          Retrieve a string representation of this object
 void write(SerialOut out)
          Serial write function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IP

private short[] IP
8 x 16 Bit = 128 Bit, which is the length of an IPv6 address

Constructor Detail

IPaddr

public IPaddr(java.net.InetAddress in)
Create an IPaddr from the Java InetAddress type

Parameters:
in - InetAddress

IPaddr

public IPaddr(long ip)
       throws java.net.UnknownHostException
Create an IPaddr from an 'unsigned int32'

Parameters:
ip - IP address
Throws:
java.net.UnknownHostException

IPaddr

public IPaddr(java.lang.String str,
              int i)
Create an IPaddr from a hexadecimal string

Parameters:
str - Hexadecimal number in a string
i - Dummy parameter

IPaddr

public IPaddr(java.lang.String host)
       throws java.net.UnknownHostException
Create an IPaddr from a hostname

Parameters:
host - Hostname
Throws:
java.net.UnknownHostException

IPaddr

public IPaddr()
Create an IPaddr for localhost

Method Detail

rawIP

public short[] rawIP()
Retrieve the raw short array

Returns:
Array

read

public void read(SerialIn in)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException,
                 java.lang.InstantiationException,
                 java.lang.IllegalAccessException,
                 java.lang.reflect.InvocationTargetException
Serial read function

Specified by:
read in interface Writable
Parameters:
in - Input stream
Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

write

public void write(SerialOut out)
           throws java.io.IOException,
                  java.lang.IllegalAccessException,
                  java.lang.reflect.InvocationTargetException
Serial write function

Specified by:
write in interface Writable
Parameters:
out - Output stream
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

equals

public boolean equals(IPaddr ip)
Check if two IPaddrs are equal

Parameters:
ip - IPaddr to compare to
Returns:
True if equal, false if not

equals

public boolean equals(java.net.InetAddress ip)
Check if two InetAddresses are equal

Parameters:
ip - InetAddress to compare to
Returns:
True if equal, false if not

getUint32

public long getUint32()
               throws java.net.UnknownHostException
Convert this to an integer

Returns:
Integer
Throws:
java.net.UnknownHostException

getUint32

public static long getUint32(java.net.InetAddress ip)
Convert ip to an integer

Parameters:
ip - InetAddress to convert
Returns:
Integer

setUint32

public static java.net.InetAddress setUint32(long ip)
                                      throws java.net.UnknownHostException
Convert an integer to InetAddress

Parameters:
ip - Integer
Returns:
InetAddress
Throws:
java.net.UnknownHostException

toString

public java.lang.String toString()
Retrieve a string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
String

toInetAddress

public java.net.InetAddress toInetAddress()
                                   throws java.net.UnknownHostException
Retrieve an InetAddress representation of this object

Returns:
InetAddress
Throws:
java.net.UnknownHostException

setShortArray

public static java.net.InetAddress setShortArray(short[] ip)
                                          throws java.net.UnknownHostException
Convert a short array to InetAddress

Parameters:
ip - Short Array
Returns:
InetAddress
Throws:
java.net.UnknownHostException

getShortArray

public static short[] getShortArray(java.net.InetAddress ip)
Convert an InetAddress to a short array

Parameters:
ip - InetAddress
Returns:
Short array