Class: PacketGen::Header::DHCP
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::DHCP
- 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:
-
a #magic field (Types::Int32) to retrieve it in a BOOTP header,
-
a, #options field (Options type, which is a collection of DHCP options).
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. << { type: 'lease_time', value: 3600 }
# Add a domain option. Here, use integer type
dhcp. << { type: 15, value: 'example.net'}
# Add an end option
dhcp. << { type: 'end' }
# And finish with padding
dhcp. << { type: 'pad' }
Defined Under Namespace
Classes: End, IPAddrOption, Int16Option, Int32Option, Int8Option, Option, Options, Pad
Constant Summary collapse
- DHCP_MAGIC =
DHCP magic value in BOOTP options
0x63825363
- DHCP_OPTIONS =
Known DHCP options
{ '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
-
#parse? ⇒ Boolean
differentiate from BOOTP by checking presence of DHCP magic.
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
#magic ⇒ Integer
53 |
# File 'lib/packetgen/header/dhcp.rb', line 53 define_field :magic, Types::Int32, default: 0x63825563 |
#options ⇒ DHCP::Options
56 |
# File 'lib/packetgen/header/dhcp.rb', line 56 define_field :options, DHCP::Options |
Instance Method Details
#parse? ⇒ Boolean
differentiate from BOOTP by checking presence of DHCP magic
60 61 62 |
# File 'lib/packetgen/header/dhcp.rb', line 60 def parse? self.magic == DHCP_MAGIC end |