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

Direct Known Subclasses

EPB, IDB, SHB, SPB, UnknownBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Types::Fields

#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, #force_binary, inherited, #inspect, #read, #sz, #to_h, #to_s

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

#has_options?Boolean

Has this block option?

Returns:

  • (Boolean)


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

def has_options?
  @fields.has_key?(:options) && @fields[:options].sz > 0
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



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

def pad_field(*fields)
  fields.each do |field|
    unless @fields[field].size % 4 == 0
      @fields[field] << "\x00" * (4 - (@fields[field].size % 4))
    end
  end
end

#recalc_block_lenvoid

This method returns an undefined value.

Calculate block length and update :block_len and block_len2 fields



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

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