Class: PacketGen::PcapNG::IDB
- Inherits:
-
Block
- Object
- Types::Fields
- Block
- PacketGen::PcapNG::IDB
- Defined in:
- lib/packetgen/pcapng/idb.rb
Overview
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
Constant Summary collapse
- MIN_SIZE =
Minimum IDB size
5 * 4
- OPTION_IF_TSRESOL =
Option code for if_tsresol option
9
Instance Attribute Summary collapse
- #endian ⇒ :little, :big
-
#link_type ⇒ Integer
16-bit link type.
- #options ⇒ Types::String
- #packets ⇒ Array<EPB,SPB>
-
#reserved ⇒ Integer
16-bit reserved field.
- #section ⇒ SHB
-
#snaplen ⇒ Integer
32-bit snap length.
Attributes inherited from Block
Instance Method Summary collapse
-
#<<(xpb) ⇒ self
Add a xPB to this section.
-
#initialize(options = {}) ⇒ IDB
constructor
A new instance of IDB.
-
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object.
-
#to_s ⇒ String
Return the object as a String.
-
#ts_resol(force: false) ⇒ Float
Give timestamp resolution for this interface.
Methods inherited from Block
#options?, #pad_field, #recalc_block_len
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, update_field
Constructor Details
Instance Attribute Details
#endian ⇒ :little, :big
30 31 32 |
# File 'lib/packetgen/pcapng/idb.rb', line 30 def endian @endian end |
#link_type ⇒ Integer
16-bit link type
39 |
# File 'lib/packetgen/pcapng/idb.rb', line 39 define_field_before :block_len2, :link_type, Types::Int16, default: 1 |
#options ⇒ Types::String
50 |
# File 'lib/packetgen/pcapng/idb.rb', line 50 define_field_before :block_len2, :options, Types::String |
#packets ⇒ Array<EPB,SPB>
34 35 36 |
# File 'lib/packetgen/pcapng/idb.rb', line 34 def packets @packets end |
Instance Method Details
#<<(xpb) ⇒ self
Add a xPB to this section
90 91 92 93 94 |
# File 'lib/packetgen/pcapng/idb.rb', line 90 def <<(xpb) @packets << xpb xpb.interface = self self end |
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/packetgen/pcapng/idb.rb', line 74 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 |
#to_s ⇒ String
Return the object as a String
109 110 111 112 113 |
# File 'lib/packetgen/pcapng/idb.rb', line 109 def to_s pad_field :options recalc_block_len super << @packets.map(&:to_s).join end |
#ts_resol(force: false) ⇒ Float
Give timestamp resolution for this interface
99 100 101 102 103 104 105 |
# File 'lib/packetgen/pcapng/idb.rb', line 99 def ts_resol(force: false) if @options_decoded && !force @ts_resol else decode_ts_resol end end |