Class: PacketGen::Header::DHCP

Inherits:
Base show all
Defined in:
lib/packetgen/header/dhcp.rb,
lib/packetgen/header/dhcp.rb,
lib/packetgen/header/dhcp/option.rb,
lib/packetgen/header/dhcp/options.rb

Overview

Dynamic Host Configuration Protocol, 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

Defined Under Namespace

Classes: End, IPAddrOption, Int16Option, Int32Option, Int8Option, Option, Options, Pad

Constant Summary collapse

DHCP_MAGIC =

DHCP magic value in BOOTP options

Since:

  • 2.2.0

0x63825363
DHCP_OPTIONS =

Known DHCP options

Since:

  • 3.1.0

{
  'pad' => 0,
  'subnet_mask' => 1,
  'time_zone' => 2,
  'router' => 3,
  'time_server' => 4,
  'IEN_name_server' => 5,
  'name_server' => 6,
  'log_server' => 7,
  'cookie_server' => 8,
  'lpr_server' => 9,
  'hostname' => 12,
  'dump_path' => 14,
  'domain' => 15,
  'root_disk_path' => 17,
  'default_ttl' => 23,
  'pmtu_timeout' => 24,
  'broadcast_address' => 28,
  'NIS_domain' => 40,
  'NIS_server' => 41,
  'NTP_server' => 42,
  'vendor_specific' => 43,
  'NetBIOS_server' => 44,
  'NetBIOS_dist_server' => 45,
  'requested_addr' => 50,
  'lease_time' => 51,
  'message-type' => 53,
  'server_id' => 54,
  'param_req_list' => 55,
  'error_message' => 56,
  'max_dhcp_size' => 57,
  'renewal_time' => 58,
  'rebinding_time' => 59,
  'vendor_class_id' => 60,
  'client_id' => 61,
  'NISplus_domain' => 64,
  'NISplus_server' => 65,
  'SMTP_server' => 69,
  'POP3_server' => 70,
  'NNTP_server' => 71,
  'WWW_server' => 72,
  'finger_server' => 73,
  'IRC_server' => 74,
  'end' => 255
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #protocol_name, #read

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#magicInteger

Returns:

  • (Integer)

52
# File 'lib/packetgen/header/dhcp.rb', line 52

define_field :magic, Types::Int32, default: 0x63825563

#optionsDHCP::Options

Returns:


55
# File 'lib/packetgen/header/dhcp.rb', line 55

define_field :options, DHCP::Options

Instance Method Details

#parse?Boolean

differentiate from BOOTP by checking presence of DHCP magic

Returns:

  • (Boolean)

Since:

  • 2.2.0


59
60
61
# File 'lib/packetgen/header/dhcp.rb', line 59

def parse?
  self.magic == DHCP_MAGIC
end