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

Inherits:
BinStruct::Array
  • Object
show all
Defined in:
lib/packetgen/header/ipv6/hop_by_hop.rb

Overview

Array of Option, for HopByHop IPv6 extension header

Author:

  • Sylvain Daubert

Since:

  • 2.4.0

Instance Method Summary collapse

Instance Method Details

#to_sString

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

Returns:

  • (String)

Since:

  • 2.4.0



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/packetgen/header/ipv6/hop_by_hop.rb', line 64

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