class PacketGen::Header::DHCPv6::Option
A DHCPv6
consists of:
-
a {#type} ({Types::Int16}),
-
a {#length} ({Types::Int16}),
-
and a {#data} ({Types::String}).
Subclasses handles known options. These subclasses may remove {#data} field to replace it by specific option field(s). @author Sylvain Daubert
Public Class Methods
new(options={})
click to toggle source
Create a new Option
object (or a subclass) @param [Hash] options @return [Option]
Calls superclass method
# File lib/packetgen/header/dhcpv6/option.rb, line 55 def new(options={}) if self == Option case options[:type] when Integer klass = Option.subclasses[options[:type]] klass&.new(options) when String if DHCPv6.const_defined?(options[:type]) klass = DHCPv6.const_get(options[:type]) options.delete :type klass.new(options) if klass < Option end else super end else super end end
new(options={})
click to toggle source
Create an Option
@param [Hash] options
Calls superclass method
# File lib/packetgen/header/dhcpv6/option.rb, line 78 def initialize(options={}) options[:length] = options[:data].to_s.size if options[:data] super self.length = self.sz - 4 if options[:data].nil? end
subclasses()
click to toggle source
Get Option
subclasses @return [Hash]
# File lib/packetgen/header/dhcpv6/option.rb, line 39 def subclasses return @klasses if defined? @klasses @klasses = [] DHCPv6.constants.each do |cst| klass = DHCPv6.const_get(cst) next unless klass.is_a?(Class) && (klass < Option) @klasses[klass.new.type] = klass end @klasses end
Public Instance Methods
human_type()
click to toggle source
Get human-readable {#type} @return [String]
# File lib/packetgen/header/dhcpv6/option.rb, line 89 def human_type if self.instance_of?(Option) "option#{type}" else self.class.to_s.sub(/.*::/, '') end end
to_human()
click to toggle source
Get a human-readable string for this option @return [String]
# File lib/packetgen/header/dhcpv6/option.rb, line 99 def to_human str = +"#{human_type}:" if respond_to?(:human_data) && !human_data.empty? str << human_data elsif !self[:data].nil? str << data.inspect else # No data: only give option name human_type end end