Class: PacketGen::PcapNG::UnknownBlock

Inherits:
Block show all
Defined in:
lib/packetgen/pcapng/unknown_block.rb

Overview

UnknownBlock is used to handle unsupported blocks of a pcapng file.

Author:

  • Sylvain Daubert

Constant Summary collapse

MIN_SIZE =

Minimum Iblock size

12

Instance Attribute Summary collapse

Attributes inherited from Block

#block_len, #type

Instance Method Summary collapse

Methods inherited from Block

#pad_field, #recalc_block_len

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, fields, #fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, update_field

Constructor Details

#initialize(options = {}) ⇒ UnknownBlock

Returns a new instance of UnknownBlock.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :endian (:little, :big)

    set block endianness

  • :type (Integer)
  • :block_len (Integer)

    block total length

  • :body (::String)
  • :block_len2 (Integer)

    block total length


30
31
32
33
34
# File 'lib/packetgen/pcapng/unknown_block.rb', line 30

def initialize(options={})
  super
  endianness(options[:endian] || :little)
  recalc_block_len
end

Instance Attribute Details

#bodyTypes::String

Returns:


23
# File 'lib/packetgen/pcapng/unknown_block.rb', line 23

define_field_before :block_len2, :body, Types::String

#endian:little, :big

Returns:

  • (:little, :big)

17
18
19
# File 'lib/packetgen/pcapng/unknown_block.rb', line 17

def endian
  @endian
end

#sectionSHB

Returns:


19
20
21
# File 'lib/packetgen/pcapng/unknown_block.rb', line 19

def section
  @section
end

Instance Method Details

#options?false

Has this block options?

Returns:

  • (false)

Since:

  • 2.7.0


39
40
41
# File 'lib/packetgen/pcapng/unknown_block.rb', line 39

def options?
  false
end

#read(str_or_io) ⇒ self

Reads a String or a IO to populate the object

Parameters:

  • str_or_io (::String, IO)

Returns:

  • (self)

46
47
48
49
50
51
52
53
54
55
56
# File 'lib/packetgen/pcapng/unknown_block.rb', line 46

def read(str_or_io)
  io = to_io(str_or_io)
  return self if io.eof?

  self[:type].read io.read(4)
  self[:block_len].read io.read(4)
  self[:body].read io.read(self[:block_len].to_i - MIN_SIZE)
  read_blocklen2_and_check(io)

  self
end

#to_sString

Return the object as a String

Returns:

  • (String)

60
61
62
63
64
# File 'lib/packetgen/pcapng/unknown_block.rb', line 60

def to_s
  pad_field :body
  recalc_block_len
  super
end