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

Constants included from Types::LengthFrom

Types::LengthFrom::MAX_SZ_TO_READ

Instance Method Summary collapse

Methods inherited from Types::Array

#<<, #==, #[], #clear, #clear!, #delete, #delete_at, #each, #empty?, #first, #initialize, #initialize_copy, #last, #push, #read, set_of, set_of_klass, #size, #sz, #to_a, #to_human

Methods included from Types::LengthFrom

#initialize_length_from, #read_with_length_from, #sz_to_read

Methods included from Types::Fieldable

#format_inspect, #read, #sz, #to_human, #type_name

Constructor Details

This class inherits a constructor from PacketGen::Types::Array

Instance Method Details

#to_sString

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

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/packetgen/header/ipv6/hop_by_hop.rb', line 58

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