class PacketFu::PcapNG::UnknownBlock

Pcapng::UnknownBlock is used to handle unsupported blocks of a pcapng file.

Constants

MIN_SIZE

Attributes

endian[RW]
section[RW]

Public Class Methods

new(args={}) click to toggle source
Calls superclass method
# File lib/packetfu/pcapng/unknown_block.rb, line 15
def initialize(args={})
  @endian = set_endianness(args[:endian] || :little)
  init_fields(args)
  super(args[:type], args[:block_len], args[:body], args[:block_len2])
end

Public Instance Methods

init_fields(args={}) click to toggle source

Used by initialize to set the initial fields

# File lib/packetfu/pcapng/unknown_block.rb, line 22
def init_fields(args={})
  args[:type]  = @int32.new(args[:type] || 0)
  args[:block_len] = @int32.new(args[:block_len] || MIN_SIZE)
  args[:body] = StructFu::String.new(args[:body] || '')
  args[:block_len2] = @int32.new(args[:block_len2] || MIN_SIZE)
  args
end
read(str_or_io) click to toggle source
# File lib/packetfu/pcapng/unknown_block.rb, line 30
def read(str_or_io)
  if str_or_io.respond_to? :read
    io = str_or_io
  else
    io = StringIO.new(force_binary(str_or_io.to_s))
  end
  return self if io.eof?

  self[:type].read io.read(4)
  self[:block_len].read io.read(4)
  self[:body].read io.read(self[:block_len].to_i - MIN_SIZE)
  self[:block_len2].read io.read(4)
  
  unless self[:block_len].to_i == self[:block_len2].to_i
    raise InvalidFileError, 'Incoherency in Header Block'
  end

  self
end
to_s() click to toggle source

Return the object as a String

# File lib/packetfu/pcapng/unknown_block.rb, line 51
def to_s
  pad_field :body
  recalc_block_len
  to_a.map(&:to_s).join
end