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, Option, Options, Pad
Constant Summary collapse
- DHCP_MAGIC =
DHCP magic value in BOOTP options
0x63825363- DHCP_OPTIONS =
define DHCP Options. keys are option type, value are arrays containing option names as strings, and a hash passed to Option#initialize.
{ 1 => ['subnet_mask', length: 4, v: IP::Addr], 2 => ['time_zone'], 3 => ['router', length: 4, v: IP::Addr], 4 => ['time_server', length: 4, v: IP::Addr], 5 => ['IEN_name_server', length: 4, v: IP::Addr], 6 => ['name_server', length: 4, v: IP::Addr], 7 => ['log_server', length: 4, v: IP::Addr], 8 => ['cookie_server', length: 4, v: IP::Addr], 9 => ['lpr_server', length: 4, v: IP::Addr], 12 => ['hostname'], 14 => ['dump_path'], 15 => ['domain'], 17 => ['root_disk_path'], 23 => ['default_ttl'], 24 => ['pmtu_timeout'], 28 => ['broadcast_address', length: 4, v: IP::Addr], 40 => ['NIS_domain'], 41 => ['NIS_server', length: 4, v: IP::Addr], 42 => ['NTP_server', length: 4, v: IP::Addr], 43 => ['vendor_specific'], 44 => ['NetBIOS_server', length: 4, v: IP::Addr], 45 => ['NetBIOS_dist_server', length: 4, v: IP::Addr], 50 => ['requested_addr', length: 4, v: IP::Addr], 51 => ['lease_time', length: 4, v: Types::Int32, value: 43_200], 53 => ['message-type', length: 1, v: Types::Int8], 54 => ['server_id', length: 4, v: IP::Addr], 55 => ['param_req_list'], 56 => ['error_message'], 57 => ['max_dhcp_size', length: 2, v: Types::Int16, value: 1_500], 58 => ['renewal_time', length: 4, v: Types::Int32, value: 21_600], 59 => ['rebinding_time', length: 4, v: Types::Int32, value: 37_800], 60 => ['vendor_class_id'], 61 => ['client_id'], 64 => ['NISplus_domain'], 65 => ['NISplus_server', length: 4, v: IP::Addr], 69 => ['SMTP_server', length: 4, v: IP::Addr], 70 => ['POP3_server', length: 4, v: IP::Addr], 71 => ['NNTP_server', length: 4, v: IP::Addr], 72 => ['WWW_server', length: 4, v: IP::Addr], 73 => ['finger_server', length: 4, v: IP::Addr], 74 => ['IRC_server', length: 4, v: IP::Addr] }.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, known_headers, #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
52 |
# File 'lib/packetgen/header/dhcp.rb', line 52 define_field :magic, Types::Int32, default: 0x63825563 |
#options ⇒ DHCP::Options
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
59 60 61 |
# File 'lib/packetgen/header/dhcp.rb', line 59 def parse? self.magic == DHCP_MAGIC end |