Class: DHCP::SubOptVSRInfo

Inherits:
SubOptList show all
Defined in:
lib/dhcp/options.rb

Overview

Class for DHCP suboption for vendor specific information

Instance Attribute Summary

Attributes inherited from OptData

#data

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Methods inherited from SubOptList

#opt_header

Methods inherited from OptListData

#append, #data=, #each, #get, #initialize, #set, #size, #to_s

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::OptListData

Instance Method Details

#bin_to_data(data) ⇒ Object



226
227
228
229
# File 'lib/dhcp/options.rb', line 226

def bin_to_data(data)
  raise "Invalid data size" unless data.size >= 5 && data.size == data[4,1].ord + 5
  [ data[0,1].ord, data[2,data.size-2] ]
end

#data_to_bin(data) ⇒ Object



231
232
233
234
235
# File 'lib/dhcp/options.rb', line 231

def data_to_bin(data)
  raise "Invalid data" unless data.is_a?(Array) && data.size == 2 && data[0].is_a?(Fixnum) && data[1].is_a?(String)
  raise "Invalid data size" unless data[1].size < 256
  data[0].chr + data[1].size.chr + data[1]
end

#is_list?(list) ⇒ Boolean

Returns:

  • (Boolean)


204
205
206
207
208
209
210
211
# File 'lib/dhcp/options.rb', line 204

def is_list?(list)
  raise "Invalid suboption sublist/entry" unless list.is_a?(Array)
  return false if list.size == 2 && list[0].is_a?(Fixnum) && list[1].is_a?(String)
  list.each do |item|
    raise "Invalid suboption sublistlist" unless item.is_a?(Array) && item.size == 2 && item[0].is_a?(Fixnum) && item[1].is_a?(String)
  end
  return true
end

#split_data(data) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/dhcp/options.rb', line 213

def split_data(data)
  data = data.dup
  list = []
  while data.size > 0
    raise "Invalid suboption data" unless data.size >= 5
    len = data[4,1].ord
    raise "Invalid vendor-specific relay info. data length" unless data.size >= len + 5
    list << [ data[0,4].unpack('N')[0], data[5,len] ]
    data[0,5+len] = ''
  end
  list
end