Class: PacketGen::PcapNG::Block Abstract

Inherits:
Types::Fields show all
Defined in:
lib/packetgen/pcapng/block.rb

Overview

This class is abstract.

Base class for all block types

Author:

  • Sylvain Daubert

Direct Known Subclasses

EPB, IDB, SHB, SPB, UnknownBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

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?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

#initialize(options = {}) ⇒ Block

Returns a new instance of Block.



30
31
32
# File 'lib/packetgen/pcapng/block.rb', line 30

def initialize(options={})
  super
end

Instance Attribute Details

#block_lenInteger

32-bit block length

Returns:

  • (Integer)


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

define_field :block_len, Types::Int32

#endian:little, :big

Returns:

  • (:little, :big)


15
16
17
# File 'lib/packetgen/pcapng/block.rb', line 15

def endian
  @endian
end

#typeInteger

32-bit block type

Returns:

  • (Integer)


20
# File 'lib/packetgen/pcapng/block.rb', line 20

define_field :type, Types::Int32

Instance Method Details

#options?Boolean

Has this block option?

Returns:

  • (Boolean)

Since:

  • 2.7.0



37
38
39
# File 'lib/packetgen/pcapng/block.rb', line 37

def options?
  @fields.key?(:options) && @fields[:options].sz.positive?
end

#pad_field(*fields) ⇒ void

This method returns an undefined value.

Pad given field to 32 bit boundary, if needed

Parameters:

  • fields (Array<Symbol>)

    block fields to pad



51
52
53
54
55
56
57
# File 'lib/packetgen/pcapng/block.rb', line 51

def pad_field(*fields)
  fields.each do |field|
    obj = @fields[field]
    pad_size = (obj.sz % 4).zero? ? 0 : (4 - (obj.sz % 4))
    obj << "\x00" * pad_size
  end
end

#recalc_block_lenvoid

This method returns an undefined value.

Calculate block length and update :block_len and block_len2 fields



43
44
45
46
# File 'lib/packetgen/pcapng/block.rb', line 43

def recalc_block_len
  len = fields.map { |f| @fields[f].to_s }.join.size
  self.block_len = self.block_len2 = len
end