Class: PacketGen::PcapNG::SPB

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

Overview

SPB represents a 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, #block_len2, #type

Instance Method Summary collapse

Methods inherited from Block

#pad_field, #recalc_block_len

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
# File 'lib/packetgen/pcapng/spb.rb', line 46

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

Instance Attribute Details

#dataBinStruct::String

Returns:

  • (BinStruct::String)


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

define_attr_before :block_len2, :data, BinStruct::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_attr_before :block_len2, :orig_len, BinStruct::Int32, default: 0

Instance Method Details

#options?false

Has this block options?

Returns:

  • (false)

Since:

  • 2.7.0



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

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)


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

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)


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

def to_s
  pad_field(:data)
  recalc_block_len
  super
end