net.dhcp
Class DHCPMessage

java.lang.Object
  extended by net.dhcp.DHCPMessage

public class DHCPMessage
extends java.lang.Object

This class represents a DHCP Message.

Version:
1.1.1 9/06/1999
Author:
Jason Goldschmidt and Nick Stone

Field Summary
static int ACK
          Code for DHCPACK Message
static java.net.InetAddress BROADCAST_ADDR
           
static int CLIENT_PORT
          Default DHCP client port
static int DECLINE
          Code for DHCPDECLINE Message
static int DISCOVER
          Code for DHCPDISCOVER Message
static int INFORM
          Code for DHCPINFORM Message
static int NAK
          Code for DHCPNAK Message
static int OFFER
          Code for DHCPOFFER Message
static int RELEASE
          Code for DHCPRELEASE Message
static int REQUEST
          Code for DHCPREQUEST Message
static int SERVER_PORT
          Default DHCP server port
 
Constructor Summary
DHCPMessage()
          Creates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, the local subnet, binds to the default server port.
DHCPMessage(byte[] ibuf)
          Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to default host name, the local subnet, and bind to the default server port.
DHCPMessage(byte[] ibuf, java.net.InetAddress inServername)
          Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.
DHCPMessage(byte[] ibuf, java.net.InetAddress inServername, int inPort)
          Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.
DHCPMessage(byte[] ibuf, int inPort)
          Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to broadcast address, and binds to the specified port.
DHCPMessage(java.io.DataInputStream inStream)
           
DHCPMessage(DHCPMessage inMessage)
          Copy constructor creates DHCPMessage from inMessage
DHCPMessage(DHCPMessage inMessage, java.net.InetAddress inServername)
           
DHCPMessage(DHCPMessage inMessage, java.net.InetAddress inServername, int inPort)
          Copy constructor creates DHCPMessage from inMessage and sets server and port
DHCPMessage(java.net.InetAddress inServername)
          Creates empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to the default port.
DHCPMessage(java.net.InetAddress inServername, int inPort)
          Creates empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to a specified port.
DHCPMessage(int inPort)
          Creates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, and binds to a specified port.
 
Method Summary
 byte[] externalize()
          Converts a DHCPMessage object to a byte array.
 byte[] getChaddr()
          Get client harware address.
 byte[] getCiaddr()
          Get client IP address.
 java.lang.String getDestinationAddress()
          Get message destination hostname
 byte[] getFile()
          Get boot file name.
 short getFlags()
          Get flags field.
 byte[] getGiaddr()
          Get relay agent IP address.
 byte getHlen()
          Get hardware address length
 byte getHops()
          Get hops field.
 byte getHtype()
          Get hardware address type.
 byte getOp()
          Get message Op code / message type.
 byte[] getOption(int inOptNum)
          Returns specified DHCP option that matches the input code.
 byte[] getOptions()
          Get all options.
 int getPort()
          Get message destination port
 short getSecs()
          Get seconds elapsed since client began address acquisition or renewal process.
 byte[] getSiaddr()
          Get address of next server to use in bootstrap.
 byte[] getSname()
          Get optional server host name.
 int getXid()
          Get transaction ID.
 byte[] getYiaddr()
          Get 'your' (client) IP address.
 DHCPMessage internalize(byte[] ibuff)
          Convert a specified byte array containing a DHCP message into a DHCPMessage object.
 boolean IsOptSet(int inOptNum)
          Report whether or not the input option is set
 void printMessage()
           
 void removeOption(int inOptNum)
          Removes the specified DHCP option that matches the input code.
 void setChaddr(byte[] inChaddr)
          Set client harware address.
 void setCiaddr(byte[] inCiaddr)
          Set client IP address.
 void setDestinationHost(java.lang.String inHost)
          Set message destination IP
 void setFile(byte[] inFile)
          Set boot file name.
 void setFlags(short inFlags)
          Set flags field.
 void setGiaddr(byte[] inGiaddr)
          Set relay agent IP address.
 void setHlen(byte inHlen)
          Set hardware address length.
 void setHops(byte inHops)
          Set hops field.
 void setHtype(byte inHtype)
          Set hardware address type.
 void setOp(byte inOp)
          Set message Op code / message type.
 void setOption(int inOptNum, byte[] inOptionData)
          Sets DHCP options in DHCPMessage.
 void setPort(int inPortNum)
          Set message destination port.
 void setSecs(short inSecs)
          Set seconds elapsed since client began address acquisition or renewal process.
 void setSiaddr(byte[] inSiaddr)
          Set address of next server to use in bootstrap.
 void setSname(byte[] inSname)
          Set optional server host name.
 void setXid(int inXid)
          Set transaction ID.
 void setYiaddr(byte[] inYiaddr)
          Set 'your' (client) IP address.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_PORT

public static final int CLIENT_PORT
Default DHCP client port

See Also:
Constant Field Values

SERVER_PORT

public static final int SERVER_PORT
Default DHCP server port

See Also:
Constant Field Values

BROADCAST_ADDR

public static java.net.InetAddress BROADCAST_ADDR

DISCOVER

public static final int DISCOVER
Code for DHCPDISCOVER Message

See Also:
Constant Field Values

OFFER

public static final int OFFER
Code for DHCPOFFER Message

See Also:
Constant Field Values

REQUEST

public static final int REQUEST
Code for DHCPREQUEST Message

See Also:
Constant Field Values

DECLINE

public static final int DECLINE
Code for DHCPDECLINE Message

See Also:
Constant Field Values

ACK

public static final int ACK
Code for DHCPACK Message

See Also:
Constant Field Values

NAK

public static final int NAK
Code for DHCPNAK Message

See Also:
Constant Field Values

RELEASE

public static final int RELEASE
Code for DHCPRELEASE Message

See Also:
Constant Field Values

INFORM

public static final int INFORM
Code for DHCPINFORM Message

See Also:
Constant Field Values
Constructor Detail

DHCPMessage

public DHCPMessage()
Creates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, the local subnet, binds to the default server port.


DHCPMessage

public DHCPMessage(DHCPMessage inMessage)
Copy constructor creates DHCPMessage from inMessage


DHCPMessage

public DHCPMessage(DHCPMessage inMessage,
                   java.net.InetAddress inServername,
                   int inPort)
Copy constructor creates DHCPMessage from inMessage and sets server and port


DHCPMessage

public DHCPMessage(DHCPMessage inMessage,
                   java.net.InetAddress inServername)

DHCPMessage

public DHCPMessage(java.net.InetAddress inServername,
                   int inPort)
Creates empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to a specified port.

Parameters:
inServername - the host name
inPort - the port number

DHCPMessage

public DHCPMessage(java.net.InetAddress inServername)
Creates empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to the default port.

Parameters:
inServername - the host name

DHCPMessage

public DHCPMessage(int inPort)
Creates empty DHCPMessage object, initializes the object, sets the host to the broadcast address, and binds to a specified port.

Parameters:
inPort - the port number

DHCPMessage

public DHCPMessage(byte[] ibuf)
Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to default host name, the local subnet, and bind to the default server port.

Parameters:
ibuf - the byte array to initialize DHCPMessage object

DHCPMessage

public DHCPMessage(byte[] ibuf,
                   java.net.InetAddress inServername,
                   int inPort)
Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.

Parameters:
ibuf - the byte array to initialize DHCPMessage object
inServername - the hostname
inPort - the port number

DHCPMessage

public DHCPMessage(byte[] ibuf,
                   int inPort)
Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to broadcast address, and binds to the specified port.

Parameters:
ibuf - the byte array to initialize DHCPMessage object
inPort - the port number

DHCPMessage

public DHCPMessage(byte[] ibuf,
                   java.net.InetAddress inServername)
Creates empty DHCPMessage object, initializes the object with a specified byte array containing DHCP message information, sets the host to specified host name, and binds to the specified port.

Parameters:
ibuf - the byte array to initialize DHCPMessage object
inServername - the hostname

DHCPMessage

public DHCPMessage(java.io.DataInputStream inStream)
Method Detail

externalize

public byte[] externalize()
Converts a DHCPMessage object to a byte array.

Returns:
a byte array with information from DHCPMessage object.

internalize

public DHCPMessage internalize(byte[] ibuff)
Convert a specified byte array containing a DHCP message into a DHCPMessage object.

Parameters:
ibuff - byte array to convert to a DHCPMessage object
Returns:
a DHCPMessage object with information from byte array.

setOp

public void setOp(byte inOp)
Set message Op code / message type.

Parameters:
inOp - message Op code / message type

setHtype

public void setHtype(byte inHtype)
Set hardware address type.

Parameters:
inHtype - hardware address type

setHlen

public void setHlen(byte inHlen)
Set hardware address length.

Parameters:
inHlen - hardware address length

setHops

public void setHops(byte inHops)
Set hops field.

Parameters:
inHops - hops field

setXid

public void setXid(int inXid)
Set transaction ID.

Parameters:
inXid - transactionID

setSecs

public void setSecs(short inSecs)
Set seconds elapsed since client began address acquisition or renewal process.

Parameters:
inSecs - seconds elapsed since client began address acquisition or renewal process

setFlags

public void setFlags(short inFlags)
Set flags field.

Parameters:
inFlags - flags field

setCiaddr

public void setCiaddr(byte[] inCiaddr)
Set client IP address.

Parameters:
inCiaddr - client IP address

setYiaddr

public void setYiaddr(byte[] inYiaddr)
Set 'your' (client) IP address.

Parameters:
inYiaddr - 'your' (client) IP address

setSiaddr

public void setSiaddr(byte[] inSiaddr)
Set address of next server to use in bootstrap.

Parameters:
inSiaddr - address of next server to use in bootstrap

setGiaddr

public void setGiaddr(byte[] inGiaddr)
Set relay agent IP address.

Parameters:
inGiaddr - relay agent IP address

setChaddr

public void setChaddr(byte[] inChaddr)
Set client harware address.

Parameters:
inChaddr - client hardware address

setSname

public void setSname(byte[] inSname)
Set optional server host name.

Parameters:
inSname - server host name

setFile

public void setFile(byte[] inFile)
Set boot file name.

Parameters:
inFile - boot file name

setPort

public void setPort(int inPortNum)
Set message destination port.

Parameters:
inPortNum - port on message destination host

setDestinationHost

public void setDestinationHost(java.lang.String inHost)
Set message destination IP

Parameters:
inHost - string representation of message destination IP or hostname

getOp

public byte getOp()
Get message Op code / message type.


getHtype

public byte getHtype()
Get hardware address type.


getHlen

public byte getHlen()
Get hardware address length

Returns:

getHops

public byte getHops()
Get hops field.


getXid

public int getXid()
Get transaction ID.


getSecs

public short getSecs()
Get seconds elapsed since client began address acquisition or renewal process.


getFlags

public short getFlags()
Get flags field.


getCiaddr

public byte[] getCiaddr()
Get client IP address.


getYiaddr

public byte[] getYiaddr()
Get 'your' (client) IP address.


getSiaddr

public byte[] getSiaddr()
Get address of next server to use in bootstrap.


getGiaddr

public byte[] getGiaddr()
Get relay agent IP address.


getChaddr

public byte[] getChaddr()
Get client harware address.


getSname

public byte[] getSname()
Get optional server host name.


getFile

public byte[] getFile()
Get boot file name.


getOptions

public byte[] getOptions()
Get all options.

Returns:
a byte array containing options

getPort

public int getPort()
Get message destination port

Returns:
an interger representation of the message destination port

getDestinationAddress

public java.lang.String getDestinationAddress()
Get message destination hostname

Returns:
a string representing the hostname of the message destination server

setOption

public void setOption(int inOptNum,
                      byte[] inOptionData)
Sets DHCP options in DHCPMessage. If option already exists then remove old option and insert a new one.

Parameters:
inOptNum - option number
inOptionData - option data

getOption

public byte[] getOption(int inOptNum)
Returns specified DHCP option that matches the input code. Null is returned if option is not set.

Parameters:
inOptNum - option number

removeOption

public void removeOption(int inOptNum)
Removes the specified DHCP option that matches the input code.

Parameters:
inOptNum - option number

IsOptSet

public boolean IsOptSet(int inOptNum)
Report whether or not the input option is set

Parameters:
inOptNum - option number

printMessage

public void printMessage()