Class DHCP

  • All Implemented Interfaces:
    IPacket

    public class DHCP
    extends BasePacket
    Representation of an DHCP Packet.
    • Field Detail

      • MIN_HEADER_LENGTH

        public static final int MIN_HEADER_LENGTH
        Dynamic Host Configuration Protocol packet. ------------------------------------------ |op (1) | htype(1) | hlen(1) | hops(1) | ------------------------------------------ | xid (4) | ------------------------------------------ | secs (2) | flags (2) | ------------------------------------------ | ciaddr (4) | ------------------------------------------ | yiaddr (4) | ------------------------------------------ | siaddr (4) | ------------------------------------------ | giaddr (4) | ------------------------------------------ | chaddr (16) | ------------------------------------------ | sname (64) | ------------------------------------------ | file (128) | ------------------------------------------ | options (312) | ------------------------------------------
        See Also:
        Constant Field Values
      • opCode

        protected byte opCode
      • hardwareType

        protected byte hardwareType
      • hardwareAddressLength

        protected byte hardwareAddressLength
      • hops

        protected byte hops
      • transactionId

        protected int transactionId
      • seconds

        protected short seconds
      • flags

        protected short flags
      • clientIPAddress

        protected int clientIPAddress
      • yourIPAddress

        protected int yourIPAddress
      • serverIPAddress

        protected int serverIPAddress
      • gatewayIPAddress

        protected int gatewayIPAddress
      • clientHardwareAddress

        protected byte[] clientHardwareAddress
      • serverName

        protected java.lang.String serverName
      • bootFileName

        protected java.lang.String bootFileName
      • options

        protected java.util.List<DhcpOption> options
    • Constructor Detail

      • DHCP

        public DHCP()
    • Method Detail

      • getOpCode

        public byte getOpCode()
        Returns:
        the opCode
      • setOpCode

        public DHCP setOpCode​(byte opCode)
        Parameters:
        opCode - the opCode to set
        Returns:
        this
      • getHardwareType

        public byte getHardwareType()
        Returns:
        the hardwareType
      • setHardwareType

        public DHCP setHardwareType​(byte hardwareType)
        Parameters:
        hardwareType - the hardwareType to set
        Returns:
        this
      • getHardwareAddressLength

        public byte getHardwareAddressLength()
        Returns:
        the hardwareAddressLength
      • setHardwareAddressLength

        public DHCP setHardwareAddressLength​(byte hardwareAddressLength)
        Parameters:
        hardwareAddressLength - the hardwareAddressLength to set
        Returns:
        this
      • getHops

        public byte getHops()
        Returns:
        the hops
      • setHops

        public DHCP setHops​(byte hops)
        Parameters:
        hops - the hops to set
        Returns:
        this
      • getTransactionId

        public int getTransactionId()
        Returns:
        the transactionId
      • setTransactionId

        public DHCP setTransactionId​(int transactionId)
        Parameters:
        transactionId - the transactionId to set
        Returns:
        this
      • getSeconds

        public short getSeconds()
        Returns:
        the seconds
      • setSeconds

        public DHCP setSeconds​(short seconds)
        Parameters:
        seconds - the seconds to set
        Returns:
        this
      • getFlags

        public short getFlags()
        Returns:
        the flags
      • setFlags

        public DHCP setFlags​(short flags)
        Parameters:
        flags - the flags to set
        Returns:
        this
      • getClientIPAddress

        public int getClientIPAddress()
        Returns:
        the clientIPAddress
      • setClientIPAddress

        public DHCP setClientIPAddress​(int clientIPAddress)
        Parameters:
        clientIPAddress - the clientIPAddress to set
        Returns:
        this
      • getYourIPAddress

        public int getYourIPAddress()
        Returns:
        the yourIPAddress
      • setYourIPAddress

        public DHCP setYourIPAddress​(int yourIPAddress)
        Parameters:
        yourIPAddress - the yourIPAddress to set
        Returns:
        this
      • getServerIPAddress

        public int getServerIPAddress()
        Returns:
        the serverIPAddress
      • setServerIPAddress

        public DHCP setServerIPAddress​(int serverIPAddress)
        Parameters:
        serverIPAddress - the serverIPAddress to set
        Returns:
        this
      • getGatewayIPAddress

        public int getGatewayIPAddress()
        Returns:
        the gatewayIPAddress
      • setGatewayIPAddress

        public DHCP setGatewayIPAddress​(int gatewayIPAddress)
        Parameters:
        gatewayIPAddress - the gatewayIPAddress to set
        Returns:
        this
      • getClientHardwareAddress

        public byte[] getClientHardwareAddress()
        Returns:
        the clientHardwareAddress
      • setClientHardwareAddress

        public DHCP setClientHardwareAddress​(byte[] clientHardwareAddress)
        Parameters:
        clientHardwareAddress - the clientHardwareAddress to set
        Returns:
        this
      • getOption

        public DhcpOption getOption​(DHCP.DHCPOptionCode optionCode)
        Gets a specific DHCP option parameter.
        Parameters:
        optionCode - The option code to get
        Returns:
        The value of the option if it exists, null otherwise
      • getOptions

        public java.util.List<DhcpOption> getOptions()
        Returns:
        the options
      • setOptions

        public DHCP setOptions​(java.util.List<DhcpOption> options)
        Parameters:
        options - the options to set
        Returns:
        this
      • getPacketType

        public DHCP.MsgType getPacketType()
        Returns:
        the packetType base on option 53
      • getServerName

        public java.lang.String getServerName()
        Returns:
        the serverName
      • setServerName

        public DHCP setServerName​(java.lang.String server)
        Parameters:
        server - the serverName to set
        Returns:
        this
      • getBootFileName

        public java.lang.String getBootFileName()
        Returns:
        the bootFileName
      • setBootFileName

        public DHCP setBootFileName​(java.lang.String bootFile)
        Parameters:
        bootFile - the bootFileName to set
        Returns:
        this
      • serialize

        public byte[] serialize()
        Description copied from interface: IPacket
        Sets all payloads parent packet if applicable, then serializes this packet and all payloads.
        Returns:
        a byte[] containing this packet and payloads
      • writeString

        protected void writeString​(java.lang.String string,
                                   java.nio.ByteBuffer bb,
                                   int maxLength)
      • deserializer

        public static Deserializer<DHCP> deserializer()
        Deserializer function for DHCP packets.
        Returns:
        deserializer function
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object