Class: PacketGen::PcapNG::SHB
- Inherits:
-
Block
- Object
- Types::Fields
- Block
- PacketGen::PcapNG::SHB
- Defined in:
- lib/packetgen/pcapng/shb.rb
Overview
SHB represents a Section Header Block (SHB) of a pcapng file.
SHB Definition
Int32 :type Default: 0x0A0D0D0A
Int32 :block_len
Int32 :magic Default: 0x1A2B3C4D # :big is 0x4D3C2C1A
Int16 :ver_major Default: 1
Int16 :ver_minor Default: 0
Int64 :section_len
String :options Default: ''
Int32 :block_len2
Constant Summary collapse
- MAGIC_INT32 =
Magic value to retrieve SHB
0x1A2B3C4D
- MAGIC_LITTLE =
Magic value (little endian version)
[MAGIC_INT32].pack('V')
- MAGIC_BIG =
Magic value (big endian version)
[MAGIC_INT32].pack('N')
- MIN_SIZE =
Minimum SHB size
7 * 4
- SECTION_LEN_UNDEFINED =
section_len
value for undefined length 0xffffffff_ffffffff
Instance Attribute Summary collapse
- #endian ⇒ :little, :big
-
#interfaces ⇒ Array<IDB>
readonly
Get interfaces for this section.
-
#magic ⇒ Integer
32-bit magic number.
- #options ⇒ Types::String
-
#section_len ⇒ Integer
64-bit section length.
-
#unknown_blocks ⇒ Array<UnknownBlock>
readonly
Get unsupported blocks given in pcapng file as raw data.
-
#ver_major ⇒ Integer
16-bit minor version number.
Attributes inherited from Block
Instance Method Summary collapse
-
#<<(idb) ⇒ self
Add a IDB to this section.
- #add_unknown_block(block) ⇒ Object
-
#initialize(options = {}) ⇒ SHB
constructor
A new instance of SHB.
-
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object.
-
#to_s ⇒ String
Return the object as a String.
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
25 26 27 |
# File 'lib/packetgen/pcapng/shb.rb', line 25 def endian @endian end |
#interfaces ⇒ Array<IDB> (readonly)
Get interfaces for this section
28 29 30 |
# File 'lib/packetgen/pcapng/shb.rb', line 28 def interfaces @interfaces end |
#magic ⇒ Integer
32-bit magic number
48 |
# File 'lib/packetgen/pcapng/shb.rb', line 48 define_field_before :block_len2, :magic, Types::Int32, default: MAGIC_INT32 |
#options ⇒ Types::String
64 |
# File 'lib/packetgen/pcapng/shb.rb', line 64 define_field_before :block_len2, :options, Types::String |
#section_len ⇒ Integer
64-bit section length
60 61 |
# File 'lib/packetgen/pcapng/shb.rb', line 60 define_field_before :block_len2, :section_len, Types::Int64, default: SECTION_LEN_UNDEFINED |
#unknown_blocks ⇒ Array<UnknownBlock> (readonly)
Get unsupported blocks given in pcapng file as raw data
31 32 33 |
# File 'lib/packetgen/pcapng/shb.rb', line 31 def unknown_blocks @unknown_blocks end |
Instance Method Details
#<<(idb) ⇒ self
Add a IDB to this section
111 112 113 114 115 |
# File 'lib/packetgen/pcapng/shb.rb', line 111 def <<(idb) @interfaces << idb idb.section = self self end |
#add_unknown_block(block) ⇒ Object
128 129 130 131 |
# File 'lib/packetgen/pcapng/shb.rb', line 128 def add_unknown_block(block) self.unknown_blocks << block block.section = self end |
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/packetgen/pcapng/shb.rb', line 92 def read(str_or_io) io = to_io(str_or_io) return self if io.eof? self[:type].read check_shb(io) %i[block_len magic ver_major ver_minor section_len].each do |attr| self[attr].read io.read(self[attr].sz) end handle_magic_and_check(self[:magic].to_s) (io) read_blocklen2_and_check(io) self end |
#to_s ⇒ String
Return the object as a String
119 120 121 122 123 124 125 126 |
# File 'lib/packetgen/pcapng/shb.rb', line 119 def to_s body = @interfaces.map(&:to_s).join self.section_len = body.size unless self.section_len == SECTION_LEN_UNDEFINED pad_field :options recalc_block_len super + body end |