Class: PacketGen::PcapNG::Block Abstract

Inherits:
BinStruct::Struct
  • Object
show all
Defined in:
lib/packetgen/pcapng/block.rb

Overview

This class is abstract.

Base class for all block types

Author:

  • Sylvain Daubert

  • LemonTree55

Direct Known Subclasses

EPB, IDB, SHB, SPB, UnknownBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Block

Returns a new instance of Block.



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

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

Instance Attribute Details

#block_lenInteger

32-bit block length

Returns:

  • (Integer)


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

define_attr :block_len, BinStruct::Int32

#block_len2Integer

32-bit block length

Returns:

  • (Integer)


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

define_attr :block_len2, BinStruct::Int32

#endian:little, :big

Returns:

  • (:little, :big)


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

def endian
  @endian
end

#typeInteger

32-bit block type

Returns:

  • (Integer)


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

define_attr :type, BinStruct::Int32

Instance Method Details

#options?Boolean

Has this block option?

Returns:

  • (Boolean)

Since:

  • 2.7.0



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

def options?
  @attributes.key?(:options) && @attributes[: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>)

    fields to pad

Author:

  • LemonTree55



55
56
57
58
59
60
# File 'lib/packetgen/pcapng/block.rb', line 55

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

#recalc_block_lenvoid

This method returns an undefined value.

Calculate block length and update block_len and block_len2 fields



46
47
48
49
# File 'lib/packetgen/pcapng/block.rb', line 46

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