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



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

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

Instance Attribute Details

#bodyTypes::String

Returns:



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

define_field_before :block_len2, :body, Types::String

#endian:little, :big

Returns:

  • (:little, :big)


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

def endian
  @endian
end

#sectionSHB

Returns:



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

def section
  @section
end

Instance Method Details

#options?false

Has this block options?

Returns:

  • (false)

Since:

  • 2.7.0



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

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)


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

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)


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

def to_s
  pad_field :body
  recalc_block_len
  super
end