java.lang.Object
com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPMessage

public class DHCPMessage extends Object
This class represents a DHCP Message.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Broadcast Adress to send packets to
    private byte[]
    Client hardware address.
    private byte[]
    Client IP address; filled in by client in DHCPREQUEST if verifying previously allocated configuration parameters.
    static final int
    Default DHCP client port
    private InetAddress
    The destination IP-Adress of this message
    static final byte
    Message Code representing a DHCPACK message
    static final byte
    Message Code representing a DHCPDECLINE message
    static final byte
    Message Code representing a DHCPDISCOVER message
    static final byte
    Message Code representing a DHCPINFORM message
    static final byte
    Message Code representing a DHCPNAK message
    static final byte
    Message Code representing a DHCPOFFER message
    static final byte
    Message Code representing a DHCPRELEASE message
    static final byte
    Message Code representing a DHCPREQUEST message
    private byte[]
    Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
    private short
    Flags for this message.
    The leftmost bit is defined as the BROADCAST (B) flag.
    private byte[]
    Relay agent IP address, used in booting via a relay-agent.
    private int
    global port variable for this message
    private byte
    Hardware address length (e.g.
    private byte
    Client sets to zero, optionally used by relay-agents when booting via a relay-agent.
    private byte
    Networktype as defined by RFC1340 page 54.
    private byte
    Operation Code.

    Can either be OP_REQUEST or OP_REPLY.
    static final byte
    Operation for a reply
    static final byte
    Operation for a request
    private DHCPOptions
    Internal representation of the given DHCP options.
    private short
    Filled in by client, seconds elapsed since client started trying to boot.
    static final int
    Default DHCP server port
    private byte[]
    IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server.
    private byte[]
    Optional server host name, null terminated string.
    private int
    Transaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.
    private byte[]
    'your' (client) IP address.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 an 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, int inPort)
    Creates an 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(byte[] ibuf, InetAddress inServername)
    Creates an 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, InetAddress inServername, int inPort)
    Creates an 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(int inPort)
    Creates an empty DHCPMessage object, initializes the object, sets the host to the broadcast address, and binds to a specified port.
    Copy constructor creates DHCPMessage from inMessage
    DHCPMessage(DHCPMessage inMessage, InetAddress inServername)
    Copy constructor creates DHCPMessage from inMessage and sets server name.
    DHCPMessage(DHCPMessage inMessage, InetAddress inServername, int inPort)
    Copy constructor creates DHCPMessage from inMessage and sets server and port.
    Creates a new DHCPMessage object from the giben DataInputStream.
    DHCPMessage(InetAddress inServername)
    Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to the default port.
    DHCPMessage(InetAddress inServername, int inPort)
    Creates an empty DHCPMessage object, initializes the object, sets the host to a specified host name, and binds to a specified port.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Converts a DHCPMessage object to a byte array.
    byte[]
     
    byte[]
     
    Get message destination hostname
    byte[]
     
    short
     
    byte[]
     
    byte
     
    byte
     
    byte
     
    byte
     
    byte[]
    getOption(int inOptNum)
    Returns specified DHCP option that matches the input code.
    byte[]
     
    int
     
    short
     
    byte[]
     
    byte[]
     
    int
     
    byte[]
     
    private void
    Initializes datamembers in the constructors every empty DHCPMessage object will by default contain these params.
    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
    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
    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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OP_REQUEST

      public static final byte OP_REQUEST
      Operation for a request
      See Also:
    • OP_REPLY

      public static final byte OP_REPLY
      Operation for a reply
      See Also:
    • DHCPDISCOVER

      public static final byte DHCPDISCOVER
      Message Code representing a DHCPDISCOVER message
      See Also:
    • DHCPOFFER

      public static final byte DHCPOFFER
      Message Code representing a DHCPOFFER message
      See Also:
    • DHCPREQUEST

      public static final byte DHCPREQUEST
      Message Code representing a DHCPREQUEST message
      See Also:
    • DHCPDECLINE

      public static final byte DHCPDECLINE
      Message Code representing a DHCPDECLINE message
      See Also:
    • DHCPACK

      public static final byte DHCPACK
      Message Code representing a DHCPACK message
      See Also:
    • DHCPNAK

      public static final byte DHCPNAK
      Message Code representing a DHCPNAK message
      See Also:
    • DHCPRELEASE

      public static final byte DHCPRELEASE
      Message Code representing a DHCPRELEASE message
      See Also:
    • DHCPINFORM

      public static final byte DHCPINFORM
      Message Code representing a DHCPINFORM message
      See Also:
    • CLIENT_PORT

      public static final int CLIENT_PORT
      Default DHCP client port
      See Also:
    • SERVER_PORT

      public static final int SERVER_PORT
      Default DHCP server port
      See Also:
    • BROADCAST_ADDR

      public static InetAddress BROADCAST_ADDR
      Broadcast Adress to send packets to
    • op

      private byte op
      Operation Code.

      Can either be OP_REQUEST or OP_REPLY.
    • htype

      private byte htype
      Networktype as defined by RFC1340 page 54.
    • hlen

      private byte hlen
      Hardware address length (e.g. '6' for ethernet).
    • hops

      private byte hops
      Client sets to zero, optionally used by relay-agents when booting via a relay-agent.
    • xid

      private int xid
      Transaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.
    • secs

      private short secs
      Filled in by client, seconds elapsed since client started trying to boot.
    • flags

      private short flags
      Flags for this message.
      The leftmost bit is defined as the BROADCAST (B) flag.
    • ciaddr

      private byte[] ciaddr
      Client IP address; filled in by client in DHCPREQUEST if verifying previously allocated configuration parameters.
    • yiaddr

      private byte[] yiaddr
      'your' (client) IP address.
    • siaddr

      private byte[] siaddr
      IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK and DHCPNAK by server.
    • giaddr

      private byte[] giaddr
      Relay agent IP address, used in booting via a relay-agent.
    • chaddr

      private byte[] chaddr
      Client hardware address.
    • sname

      private byte[] sname
      Optional server host name, null terminated string.
    • file

      private byte[] file
      Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
    • optionsList

      private DHCPOptions optionsList
      Internal representation of the given DHCP options.
    • gPort

      private int gPort
      global port variable for this message
    • destination_IP

      private InetAddress destination_IP
      The destination IP-Adress of this message
  • Constructor Details

    • 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
      Parameters:
      inMessage - The message to be copied
    • DHCPMessage

      public DHCPMessage(DHCPMessage inMessage, InetAddress inServername, int inPort)
      Copy constructor creates DHCPMessage from inMessage and sets server and port.
      Parameters:
      inMessage - The message to be copied
      inServername - The host name
      inPort - The port number
    • DHCPMessage

      public DHCPMessage(DHCPMessage inMessage, InetAddress inServername)
      Copy constructor creates DHCPMessage from inMessage and sets server name.
      Parameters:
      inMessage - The message to be copied
      inServername - The host name
    • DHCPMessage

      public DHCPMessage(InetAddress inServername, int inPort)
      Creates an 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(InetAddress inServername)
      Creates an 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 an 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 an 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, InetAddress inServername, int inPort)
      Creates an 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 an 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, InetAddress inServername)
      Creates an 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(DataInputStream inStream)
      Creates a new DHCPMessage object from the giben DataInputStream.
      Parameters:
      inStream - The stream to read from
  • Method Details

    • initialize

      private void initialize()
      Initializes datamembers in the constructors every empty DHCPMessage object will by default contain these params. Initializes options array from linked list form.
    • externalize

      public byte[] externalize()
      Converts a DHCPMessage object to a byte array.
      Returns:
      A byte array with information from DHCPMessage object, ready to send.
    • 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(String inHost)
      Set message destination IP
      Parameters:
      inHost - string representation of message destination IP or hostname
    • getOp

      public byte getOp()
      Returns:
      message Op code / message type.
    • getHtype

      public byte getHtype()
      Returns:
      hardware address type.
    • getHlen

      public byte getHlen()
      Returns:
      hardware address length.
    • getHops

      public byte getHops()
      Returns:
      hops field.
    • getXid

      public int getXid()
      Returns:
      transaction ID.
    • getSecs

      public short getSecs()
      Returns:
      seconds elapsed since client began address acquisition or renewal process.
    • getFlags

      public short getFlags()
      Returns:
      flags field.
    • getCiaddr

      public byte[] getCiaddr()
      Returns:
      client IP address.
    • getYiaddr

      public byte[] getYiaddr()
      Returns:
      'your' (client) IP address.
    • getSiaddr

      public byte[] getSiaddr()
      Returns:
      address of next server to use in bootstrap.
    • getGiaddr

      public byte[] getGiaddr()
      Returns:
      relay agent IP address.
    • getChaddr

      public byte[] getChaddr()
      Returns:
      client harware address.
    • getSname

      public byte[] getSname()
      Returns:
      optional server host name.
    • getFile

      public byte[] getFile()
      Returns:
      boot file name.
    • getOptions

      public byte[] getOptions()
      Returns:
      a byte array containing options
    • getPort

      public int getPort()
      Returns:
      An interger representation of the message destination port
    • getDestinationAddress

      public 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
      Returns:
      the option matching input code
    • 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
      Returns:
      is the given option set?