class PacketGen::PcapNG::IDB
{IDB} represents a Interface Description Block
(IDB
) of a pcapng file.
IDB
Definition¶ ↑
Int32 :type Default: 0x00000001 Int32 :block_len Int16 :link_type Default: 1 Int16 :reserved Default: 0 Int64 :snaplen Default: 0 (no limit) String :options Int32 :block_len2
@author Sylvain Daubert
Constants
- MIN_SIZE
Minimum
IDB
size- OPTION_IF_TSRESOL
Option code for if_tsresol option
Attributes
@return [:little, :big]
@return [Array<EPB,SPB>]
@return [SHB]
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] :link_type @option options [Integer] :reserved @option options [Integer] :snaplen maximum number of octets captured from
each packet
@option options [::String] :options @option options [Integer] :block_len2 block total length
PacketGen::PcapNG::Block::new
# File lib/packetgen/pcapng/idb.rb, line 61 def initialize(options={}) super endianness(options[:endian] || :little) @packets = [] @options_decoded = false recalc_block_len self.type = options[:type] || PcapNG::IDB_TYPE.to_i end
Public Instance Methods
Add a xPB to this section @param [EPB,SPB] xpb @return [self]
# File lib/packetgen/pcapng/idb.rb, line 89 def <<(xpb) @packets << xpb xpb.interface = self self end
Reads a String or a IO to populate the object @param [::String,IO] str_or_io @return [self]
# File lib/packetgen/pcapng/idb.rb, line 73 def read(str_or_io) io = to_io(str_or_io) return self if io.eof? %i[type block_len link_type reserved snaplen].each do |attr| self[attr].read io.read(self[attr].sz) end self[:options].read io.read(self.block_len - MIN_SIZE) read_blocklen2_and_check(io) self end
Return the object as a String @return [String]
# File lib/packetgen/pcapng/idb.rb, line 108 def to_s pad_field :options recalc_block_len super << @packets.map(&:to_s).join end
Give timestamp resolution for this interface @param [Boolean] force if true
, force decoding even if already done @return [Float]
# File lib/packetgen/pcapng/idb.rb, line 98 def ts_resol(force: false) if @options_decoded && !force @ts_resol else decode_ts_resol end end
Private Instance Methods
# File lib/packetgen/pcapng/idb.rb, line 116 def decode_ts_resol tsresol = search_for_ts_resol_opt(self[:options]) @options_decoded = true return @ts_resol = 1E-6 if tsresol.nil? @ts_resol = if (tsresol & 0x80).zero? 10**-tsresol else 2**-(tsresol & 0x7f) end end
# File lib/packetgen/pcapng/idb.rb, line 128 def search_for_ts_resol_opt(options) packstr = endian == :little ? 'v' : 'n' idx = 0 while idx < options.length opt_code, opt_len = options[idx, 4].unpack("#{packstr}2") return options[idx + 4, 1].unpack1('C') if opt_code == OPTION_IF_TSRESOL && opt_len == 1 idx += 4 + opt_len end end