class PacketGen::PcapNG::SPB

{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

Constants

MIN_SIZE

Minimum SPB size

Attributes

endian[RW]

@return [:little, :big]

interface[RW]

@return [IPB]

Public Class Methods

new(options={}) click to toggle source

@param [Hash] options @option options [:little, :big] :endian set block endianness @option options [Integer] :type @option options [Integer] :block_len block total length @option options [Integer] :orig_len actual length of the packet when it was

transmitted on the network

@option options [::String] :data @option options [::String] :options @option options [Integer] :block_len2 block total length

Calls superclass method PacketGen::PcapNG::Block::new
# 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

Public Instance Methods

options?() click to toggle source

Has this block options? @return [false] @since 2.7.0

# File lib/packetgen/pcapng/spb.rb, line 55
def options?
  false
end
read(str_or_io) click to toggle source

Reads a String or a IO to populate the object @param [::String,IO] str_or_io @return [self]

# 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_s() click to toggle source

Return the object as a String @return [String]

Calls superclass method
# File lib/packetgen/pcapng/spb.rb, line 80
def to_s
  pad_field :data
  recalc_block_len
  super
end

Private Instance Methods

compute_data_len() click to toggle source

Take care of IDB snaplen CAUTION: snaplen == 0 -> no capture limit

# File lib/packetgen/pcapng/spb.rb, line 90
def compute_data_len
  if interface && interface.snaplen.to_i.positive?
    [self[:orig_len].to_i, interface.snaplen.to_i].min
  else
    self[:orig_len].to_i
  end
end