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
@return [:little, :big]
@return [IPB]
Public Class Methods
@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
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
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
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
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
Return the object as a String @return [String]
# File lib/packetgen/pcapng/epb.rb, line 116 def to_s pad_field :data, :options recalc_block_len super end
Private Instance Methods
# 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
# File lib/packetgen/pcapng/epb.rb, line 124 def ts_resol if !defined?(@interface) || @interface.nil? 1E-6 else @interface.ts_resol end end