Class: PacketGen::PcapNG::SHB
- Defined in:
- lib/packetgen/pcapng/shb.rb
Overview
SHB represents a Section Header Block (SHB) of a pcapng file. A SHB contains IDB, which contain EPB and/or SPB.
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 ⇒ BinStruct::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
#block_len, #block_len2, #type
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
Constructor Details
Instance Attribute Details
#endian ⇒ :little, :big
26 27 28 |
# File 'lib/packetgen/pcapng/shb.rb', line 26 def endian @endian end |
#interfaces ⇒ Array<IDB> (readonly)
Get interfaces for this section
29 30 31 |
# File 'lib/packetgen/pcapng/shb.rb', line 29 def interfaces @interfaces end |
#magic ⇒ Integer
32-bit magic number
49 |
# File 'lib/packetgen/pcapng/shb.rb', line 49 define_attr_before :block_len2, :magic, BinStruct::Int32, default: MAGIC_INT32 |
#options ⇒ BinStruct::String
65 |
# File 'lib/packetgen/pcapng/shb.rb', line 65 define_attr_before :block_len2, :options, BinStruct::String |
#section_len ⇒ Integer
64-bit section length
61 62 |
# File 'lib/packetgen/pcapng/shb.rb', line 61 define_attr_before :block_len2, :section_len, BinStruct::Int64, default: SECTION_LEN_UNDEFINED |
#unknown_blocks ⇒ Array<UnknownBlock> (readonly)
Get unsupported blocks given in pcapng file as raw data
32 33 34 |
# File 'lib/packetgen/pcapng/shb.rb', line 32 def unknown_blocks @unknown_blocks end |
#ver_major ⇒ Integer
16-bit minor version number
53 |
# File 'lib/packetgen/pcapng/shb.rb', line 53 define_attr_before :block_len2, :ver_major, BinStruct::Int16, default: 1 |
Instance Method Details
#<<(idb) ⇒ self
Add a IDB to this section
110 111 112 113 114 |
# File 'lib/packetgen/pcapng/shb.rb', line 110 def <<(idb) @interfaces << idb idb.section = self self end |
#add_unknown_block(block) ⇒ Object
127 128 129 130 |
# File 'lib/packetgen/pcapng/shb.rb', line 127 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/packetgen/pcapng/shb.rb', line 91 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
118 119 120 121 122 123 124 125 |
# File 'lib/packetgen/pcapng/shb.rb', line 118 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 |