Class: PacketGen::Header::IPv6::Options
- Inherits:
-
Types::Array
- Object
- Types::Array
- PacketGen::Header::IPv6::Options
- Defined in:
- lib/packetgen/header/ipv6/hop_by_hop.rb
Overview
Constant Summary
Constants inherited from Types::Array
Instance Method Summary collapse
-
#read(str) ⇒ self
Populate object from a binary string.
-
#to_s ⇒ String
Get options as a binary string.
Methods inherited from Types::Array
#<<, #==, #[], #clear, #clear!, #delete, #delete_at, #each, #empty?, #first, #force_binary, #initialize, #initialize_copy, #last, #push, set_of, #size, #sz, #to_a, #to_human
Constructor Details
This class inherits a constructor from PacketGen::Types::Array
Instance Method Details
#read(str) ⇒ self
Populate object from a binary string
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/packetgen/header/ipv6/hop_by_hop.rb', line 52 def read(str) clear return self if str.nil? force_binary str klass = self.class.class_eval { @klass } until str.empty? obj = klass.new.read(str) obj = Pad1.new.read(str) if obj.type.zero? self.push obj str.slice!(0, obj.sz) end self end |
#to_s ⇒ String
Get options as a binary string. Add padding if needed.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/packetgen/header/ipv6/hop_by_hop.rb', line 68 def to_s str = super case (str.size + 2) % 8 when 0 return str when 7 # only on byte needed: use pad1 option self << Pad1.new str << [0].pack('C') else # use padn option len = 8 - 2 - (str.size % 8) - 2 padn = Option.new(type: 'padn', value: "\x00" * len) self << padn str << padn.to_s end str end |