class PacketGen::Header::DHCP

Dynamic Host Configuration Protocol, {tools.ietf.org/html/rfc2131 RFC 2131}

A DHCP header is quite simple. It is composed of:

In PacketGen, a DHCP header is always a secondary header after {BOOTP} one.

Create a DHCP header

# standalone
dhcp = PacketGen::Header::DHCP.new
# in a packet
pkt = PacketGen.gen('IP').add('BOOTP').add('DHCP')
# access to DHCP header
pkt.dhcp      # => PacketGen::Header::DHCP

Add options

Options may be added these ways:

dhcp = PacketGen::Header::DHCP.new
# Add a lease_time option
dhcp.options << { type: 'lease_time', value: 3600 }
# Add a domain option. Here, use integer type
dhcp.options << { type: 15, value: 'example.net'}
# Add an end option
dhcp.options << { type: 'end' }
# And finish with padding
dhcp.options << { type: 'pad' }

@author Sylvain Daubert @since 2.2.0

Constants

DHCP_MAGIC

DHCP magic value in BOOTP options

DHCP_OPTIONS

Known DHCP options @since 3.1.0

IPAddrOption

@!parse

# {Option} class with IP address value
# @since 2.2.0
# @since 3.1.0 subclass of {Types::AbstractTLV}
class IPAddrOption < Types::AbstractTLV; end

@private

Int16Option

@!parse

# {Option} class with int16 value
# @since 2.2.0
# @since 3.1.0 subclass of {Types::AbstractTLV}
class Int16Option < Types::AbstractTLV; end

@private

Int32Option

@!parse

# {Option} class with int32 value
# @since 2.2.0
# @since 3.1.0 subclass of {Types::AbstractTLV}
class Int32Option < Types::AbstractTLV; end

@private

Int8Option

@!parse

# {Option} class with int8 value
# @since 2.2.0
# @since 3.1.0 subclass of {Types::AbstractTLV}
class Int8Option < Types::AbstractTLV; end

@private

Option

@!parse

# Option class with string value. {#type #type} and {#length #length} are
# {Types::Int8}.
#
# See also {IPAddrOption}, {Int8Option}, {Int16Option} and {Int32Option}.
# @since 2.2.0
# @since 3.1.0 subclass of {Types::AbstractTLV}
class Option < Types::AbstractTLV; end

@private

Public Instance Methods

parse?() click to toggle source

differentiate from BOOTP by checking presence of DHCP magic @return [Boolean]

# File lib/packetgen/header/dhcp.rb, line 59
def parse?
  self.magic == DHCP_MAGIC
end