class DHCP::OptHexString

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)

Public Instance Methods

bin_to_data(data) click to toggle source
# File lib/dhcp/options.rb, line 502
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) click to toggle source
# File lib/dhcp/options.rb, line 497
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