class PacketGen::Header::IP::Option
Constants
Public Class Methods
build(options={})
click to toggle source
Factory to build an option from its type @return [Option]
# File lib/packetgen/header/ip/option.rb, line 88 def self.build(options={}) type = options.delete(:type) klass = case type when String types.key?(type) ? IP.const_get(type) : self when Integer types.value?(type) ? IP.const_get(types.key(type)) : self else self end klass.new(options) end
new(options={})
click to toggle source
Calls superclass method
# File lib/packetgen/header/ip/option.rb, line 101 def initialize(options={}) unless options[:type] opt_name = self.class.to_s.gsub(/.*::/, '') options[:type] = Option.const_get("#{opt_name}_TYPE") if Option.const_defined? "#{opt_name}_TYPE" end super self.length = sz if respond_to?(:length) && options[:length].nil? end
types()
click to toggle source
@return [Hash]
# File lib/packetgen/header/ip/option.rb, line 73 def self.types return @types if defined? @types @types = {} Option.constants.each do |cst| next unless cst.to_s.end_with? '_TYPE' optname = cst.to_s.sub(/_TYPE/, '') @types[optname] = Option.const_get(cst) end @types end
Public Instance Methods
to_human()
click to toggle source
Get a human readable string @return [String]
# File lib/packetgen/header/ip/option.rb, line 119 def to_human str = self.instance_of?(Option) ? +"unk-#{type}" : self.class.to_s.sub(/.*::/, '') str << ":#{self[:data].to_s.inspect}" if respond_to?(:length) && (length > 2) && !self[:data].to_s.empty? str end
to_s()
click to toggle source
Get binary string. Set {#length} field. @return [String]
Calls superclass method
PacketGen::Types::Fieldable#to_s
# File lib/packetgen/header/ip/option.rb, line 112 def to_s self.length = super.size if respond_to? :length super end