class Lib::DHCP::Options
Attributes
options[R]
Public Class Methods
new(*options)
click to toggle source
# File lib/lib/dhcp/options.rb, line 17 def initialize(*options) @options = [] options.each { |option| self.add option } end
unpack(packet)
click to toggle source
# File lib/lib/dhcp/options.rb, line 56 def self.unpack(packet) size = packet.size offset = 0 options = self.new while offset < size payload = packet.unpack("@#{offset}a*").first option = Lib::DHCP::Option.unpack(payload) options << option break if option.oid == Lib::DHCP::Option::END_OPTION offset += (option.len.to_i + 2) #(option.oid == 0 or option.oid == 255) ? offset += (option.len.to_i + 1) : offset += (option.len.to_i + 2) end options end
Public Instance Methods
[]=(index, option)
click to toggle source
# File lib/lib/dhcp/options.rb, line 30 def []=(index, option) option = create_option(option) if include?(option) and @options[index].oid != option.oid @options[index] = option if option.oid == 0 else @options[index] = create_option(option) end end
add(option)
click to toggle source
# File lib/lib/dhcp/options.rb, line 26 def add(option) @options << create_option(option) end
Also aliased as: <<
del(oid)
click to toggle source
# File lib/lib/dhcp/options.rb, line 50 def del(oid) @options.delete_if{|option| option.oid.to_i == oid.to_i} end
include?(option)
click to toggle source
# File lib/lib/dhcp/options.rb, line 40 def include?(option) return ! select(option.oid).empty? if option.is_a?(Option) return ! select(option).empty? if option.is_a?(Integer) false end
pack()
click to toggle source
# File lib/lib/dhcp/options.rb, line 22 def pack self.map{|option| option.pack}.join('') end
select(oid)
click to toggle source
# File lib/lib/dhcp/options.rb, line 46 def select(oid) @options.select {|option| option.oid.to_i == oid.to_i} end
Protected Instance Methods
create_option(option)
click to toggle source
# File lib/lib/dhcp/options.rb, line 73 def create_option(option) if option.is_a? Array eval("Lib::DHCP::Option#{option[0].to_i}").new(option[1]) elsif option.is_a? Option option elsif option.is_a?(Integer) and (option == 0 or option == 255) eval("Lib::DHCP::Option#{option.to_i}").new(option.to_i) else Lib::DHCP::Option.unpack(option) end end