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



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

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:



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

define_field_before :block_len2, :data, Types::String

#endian:little, :big

Returns:

  • (:little, :big)


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

def endian
  @endian
end

#interfaceIPB

Returns:

  • (IPB)


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

def interface
  @interface
end

#orig_lenInteger

32-bit original length

Returns:

  • (Integer)


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

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



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

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)


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

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)


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

def to_s
  pad_field :data
  recalc_block_len
  super
end