Class: DHCP::OptStaticRoutes
- Inherits:
-
OptListFixedData
- Object
- Opt
- OptData
- OptListData
- OptListFixedData
- DHCP::OptStaticRoutes
- Defined in:
- lib/dhcp/options.rb
Overview
Class for DHCP option 33 (static routes) - Use option 121 instead if possible WARNING: Option 33 can only handle class A, B, or C networks, not classless networks with an arbitrary netmask.
Instance Attribute Summary
Attributes inherited from OptData
Attributes inherited from Opt
Instance Method Summary collapse
Methods inherited from OptListFixedData
Methods inherited from OptListData
#append, #data=, #each, #get, #initialize, #set, #size, #split_data
Methods inherited from OptData
#get, #initialize, #opt_header, #set, #to_opt
Methods inherited from Opt
#initialize, #opt_header, #to_opt
Constructor Details
This class inherits a constructor from DHCP::OptListData
Instance Method Details
#bin_to_data(data) ⇒ Object
382 383 384 |
# File 'lib/dhcp/options.rb', line 382 def bin_to_data(data) [IPAddress::IPv4::parse_classful_data(data[0,4]).net.to_string, IPAddress::IPv4::parse_data(data[4,4]).to_s] end |
#data_to_bin(data) ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/dhcp/options.rb', line 367 def data_to_bin(data) raise "Invalid static route" unless data.is_a?(Array) && data.size == 2 net, gateway = *data net = IPAddress::IPv4.new(net) raise "Invalid classful static route network" unless net.network? raise "Invalid classful static route network" unless ( (net.a? && net.prefix == 8 ) || (net.b? && net.prefix == 16) || (net.c? && net.prefix == 24) ) gateway = IPAddress::IPv4.new("#{gateway}/#{net.prefix}") raise "Invalid classful static route gateway" unless gateway.member?(net) net.data + gateway.data end |
#is_list?(list) ⇒ Boolean
354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/dhcp/options.rb', line 354 def is_list?(list) raise "Invalid route list/entry" unless list.is_a?(Array) if list.size == 2 return false if list[0].is_a?(String) && list[1].is_a?(String) return true if list[0].is_a?(Array) && list[1].is_a?(Array) raise "Invalid route list/entry" end list.each do |item| raise "Invalid route list" unless item.is_a?(Array) && item[0].is_a?(String) && item[1].is_a?(String) end return true end |
#to_s ⇒ Object
386 387 388 |
# File 'lib/dhcp/options.rb', line 386 def to_s opt_header + '=[' + map{|i| i[0] + '=>' + i[1]}.join(',') + ']' end |