class PacketGen::PcapNG::EPB

{EPB} represents a Enhanced Packet Block (EPB) of a pcapng file.

EPB Definition

Int32   :type           Default: 0x00000006
Int32   :block_len
Int32   :interface_id
Int32   :tsh (timestamp high)
Int32   :tsl (timestamp low)
Int32   :cap_len
Int32   :orig_len
String  :data
String  :options
Int32   :block_len2

@author Sylvain Daubert

Constants

MIN_SIZE

Minimum EPB 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] :interface_id specifies the interface this packet

comes from

@option options [Integer] :tsh timestamp (high nibbles) @option options [Integer] :tsl timestamp (low nibbles) @option options [Integer] :cap_len number of octets captured from the packet @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/epb.rb, line 74
def initialize(options={})
  super
  endianness(options[:endian] || :little)
  recalc_block_len
  self.type = options[:type] || PcapNG::EPB_TYPE.to_i
end

Public Instance Methods

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/epb.rb, line 84
def read(str_or_io)
  io = to_io(str_or_io)
  return self if io.eof?

  %i[type block_len interface_id tsh tsl cap_len orig_len].each do |attr|
    self[attr].read io.read(self[attr].sz)
  end
  self[:data].read io.read(self.cap_len)
  read_options(io)
  read_blocklen2_and_check(io)

  self
end
timestamp() click to toggle source

Return timestamp as a Time object @return [Time]

# File lib/packetgen/pcapng/epb.rb, line 100
def timestamp
  Time.at((self.tsh << 32 | self.tsl) * ts_resol)
end
timestamp=(time) click to toggle source

Set timestamp from a Time object @param [Time] time @return [Time] time

# File lib/packetgen/pcapng/epb.rb, line 107
def timestamp=(time)
  tstamp = (time.to_r / ts_resol).to_i
  self.tsh = (tstamp & 0xffffffff00000000) >> 32
  self.tsl = tstamp & 0xffffffff
  time
end
to_s() click to toggle source

Return the object as a String @return [String]

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

Private Instance Methods

read_options(io) click to toggle source
# File lib/packetgen/pcapng/epb.rb, line 132
def read_options(io)
  data_pad_len = remove_padding(io, self.cap_len)
  options_len = self.block_len - self.cap_len - data_pad_len - MIN_SIZE
  self[:options].read io.read(options_len)
end
ts_resol() click to toggle source
# File lib/packetgen/pcapng/epb.rb, line 124
def ts_resol
  if !defined?(@interface) || @interface.nil?
    1E-6
  else
    @interface.ts_resol
  end
end