Class: PacketGen::Header::DHCPv6::Option
- Inherits:
-
BinStruct::Struct
- Object
- BinStruct::Struct
- PacketGen::Header::DHCPv6::Option
- Includes:
- BinStruct::Structable
- Defined in:
- lib/packetgen/header/dhcpv6/option.rb
Overview
Direct Known Subclasses
ClientID, ElapsedTime, IAAddr, IANA, IATA, ORO, Preference, RapidCommit, RelayMessage, ServerUnicast, StatusCode
Class Attribute Summary collapse
-
.data ⇒ String
variable length option data.
Instance Attribute Summary collapse
-
#length ⇒ Integer
16-bit option length.
-
#type ⇒ Integer
16-bit option type.
Class Method Summary collapse
-
.human_type ⇒ String
Get human-readable #type.
-
.initialize(options = {}) ⇒ Object
Create an Option.
-
.new(options = {}) ⇒ Option
Create a new Option object (or a subclass).
-
.subclasses ⇒ Hash
Get Option subclasses.
-
.to_human ⇒ String
Get a human-readable string for this option.
Class Attribute Details
.data ⇒ String
variable length option data.
35 36 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 35 define_attr :data, BinStruct::String, builder: ->(h, t) { t.new(length_from: h[:length]) } |
Instance Attribute Details
#length ⇒ Integer
16-bit option length. Length of data part.
30 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 30 define_attr :length, BinStruct::Int16 |
#type ⇒ Integer
16-bit option type
26 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 26 define_attr :type, BinStruct::Int16 |
Class Method Details
.human_type ⇒ String
Get human-readable #type
89 90 91 92 93 94 95 |
# 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 |
.initialize(options = {}) ⇒ Object
Create an Option
78 79 80 81 82 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 78 def initialize(={}) [:length] = [:data].to_s.size if [:data] super self.length = self.sz - 4 if [:data].nil? end |
.new(options = {}) ⇒ Option
Create a new Option object (or a subclass)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 57 def new(={}) return super unless self == Option case [:type] when Integer klass = Option.subclasses[[:type]] klass&.new() when String if DHCPv6.const_defined?([:type]) klass = DHCPv6.const_get([:type]) .delete(:type) klass.new() if klass < Option end else super end end |
.subclasses ⇒ Hash
Get Option subclasses
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/packetgen/header/dhcpv6/option.rb', line 41 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 |
.to_human ⇒ String
Get a human-readable string for this option
99 100 101 102 103 104 105 106 107 108 109 |
# 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 |