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.


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

def initialize(options={})
  super
end

Instance Attribute Details

#block_lenInteger

32-bit block length

Returns:

  • (Integer)

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

define_field :block_len, Types::Int32

#endian:little, :big

Returns:

  • (:little, :big)

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

def endian
  @endian
end

#typeInteger

32-bit block type

Returns:

  • (Integer)

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

define_field :type, Types::Int32

Instance Method Details

#options?Boolean

Has this block option?

Returns:

  • (Boolean)

Since:

  • 2.7.0


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

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


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

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


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

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