Class: PacketGen::PcapNG::SPB

Inherits:
Block show all
Defined in:
lib/packetgen/pcapng/spb.rb

Overview

SPB represents a Section Simple Packet Block (SPB) of a pcapng file.

Pcapng::SPB Definition

Int32   :type           Default: 0x00000003
Int32   :block_len
Int32   :orig_len
String  :data
Int32   :block_len2

Author:

  • Sylvain Daubert

Constant Summary collapse

MIN_SIZE =

Minimum SPB size

4 * 4

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 = {}) ⇒ SPB

Returns a new instance of SPB.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :endian (:little, :big)

    set block endianness

  • :type (Integer)
  • :block_len (Integer)

    block total length

  • :orig_len (Integer)

    actual length of the packet when it was transmitted on the network

  • :data (::String)
  • :options (::String)
  • :block_len2 (Integer)

    block total length



46
47
48
49
50
51
# File 'lib/packetgen/pcapng/spb.rb', line 46

def initialize(options={})
  super
  endianness(options[:endian] || :little)
  recalc_block_len
  self.type = options[:type] || PcapNG::SPB_TYPE.to_i
end

Instance Attribute Details

#dataTypes::String

Returns:



35
# File 'lib/packetgen/pcapng/spb.rb', line 35

define_field_before :block_len2, :data, Types::String

#endian:little, :big

Returns:

  • (:little, :big)


25
26
27
# File 'lib/packetgen/pcapng/spb.rb', line 25

def endian
  @endian
end

#interfaceIPB

Returns:

  • (IPB)


27
28
29
# File 'lib/packetgen/pcapng/spb.rb', line 27

def interface
  @interface
end

#orig_lenInteger

32-bit original length

Returns:

  • (Integer)


32
# File 'lib/packetgen/pcapng/spb.rb', line 32

define_field_before :block_len2, :orig_len, Types::Int32, default: 0

Instance Method Details

#options?false

Has this block options?

Returns:

  • (false)

Since:

  • 2.7.0



56
57
58
# File 'lib/packetgen/pcapng/spb.rb', line 56

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)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/packetgen/pcapng/spb.rb', line 63

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[:orig_len].read io.read(4)
  data_len = compute_data_len
  self[:data].read io.read(data_len)
  remove_padding(io, data_len)
  read_blocklen2_and_check(io)

  self.type ||= PcapNG::IDB_TYPE.to_i
  self
end

#to_sString

Return the object as a String

Returns:

  • (String)


81
82
83
84
85
# File 'lib/packetgen/pcapng/spb.rb', line 81

def to_s
  pad_field :data
  recalc_block_len
  super
end