class PacketGen::Header::IPv6::Options

Array of {Option}, for {HopByHop} IPv6 extension header @author Sylvain Daubert

Public Instance Methods

to_s() click to toggle source

Get options as a binary string. Add padding if needed. @return [String]

Calls superclass method
# File lib/packetgen/header/ipv6/hop_by_hop.rb, line 57
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

Private Instance Methods

real_type(opt) click to toggle source
# File lib/packetgen/header/ipv6/hop_by_hop.rb, line 78
def real_type(opt)
  opt.type.zero? ? Pad1 : opt.class
end