Class: PacketGen::Header::IPv6::Options

Inherits:
Types::Array show all
Defined in:
lib/packetgen/header/ipv6/hop_by_hop.rb

Overview

Array of Option, for HopByHop IPv6 extension header

Author:

  • Sylvain Daubert

Constant Summary

Constants inherited from Types::Array

Types::Array::HUMAN_SEPARATOR

Instance Method Summary collapse

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

Parameters:

  • str (String)

Returns:

  • (self)


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_sString

Get options as a binary string. Add padding if needed.

Returns:

  • (String)


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