Class: DHCP::OptHexString
Overview
Class for DHCP options containing data that is most often displayed as a string of hexadecimal digit pairs joined by colons (i.e. ethernet MAC addresses)
Instance Attribute Summary
Attributes inherited from OptData
Attributes inherited from Opt
Instance Method Summary collapse
Methods inherited from OptData
#get, #initialize, #opt_header, #set, #to_opt, #to_s
Methods inherited from Opt
#initialize, #opt_header, #to_opt, #to_s
Constructor Details
This class inherits a constructor from DHCP::OptData
Instance Method Details
#bin_to_data(data) ⇒ Object
535 536 537 |
# File 'lib/dhcp/options.rb', line 535 def bin_to_data(data) data.each_byte.map{|b| "%0.2X" % [b]}.join(':') ## Convert each byte to hex string and join bytes with ':' end |
#data_to_bin(data) ⇒ Object
530 531 532 533 |
# File 'lib/dhcp/options.rb', line 530 def data_to_bin(data) data = data.gsub(/[ \.:_\-]/,'') ## Allow various octet separator characters (trim them out) ['0' * (data.size % 2)].pack('H*') ## Pad hex string to even multiple and translate to binary end |