Class: PacketGen::PcapNG::Block Abstract
- Inherits:
-
BinStruct::Struct
- Object
- BinStruct::Struct
- PacketGen::PcapNG::Block
- Defined in:
- lib/packetgen/pcapng/block.rb
Overview
This class is abstract.
Base class for all block types
Direct Known Subclasses
EPB, IDB, SHB, SPB, UnknownBlock
Instance Attribute Summary collapse
-
#block_len ⇒ Integer
32-bit block length.
-
#block_len2 ⇒ Integer
32-bit block length.
- #endian ⇒ :little, :big
-
#type ⇒ Integer
32-bit block type.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Block
constructor
A new instance of Block.
-
#options? ⇒ Boolean
Has this block option?.
-
#pad_field(*fields) ⇒ void
Pad given field to 32 bit boundary, if needed.
-
#recalc_block_len ⇒ void
Calculate block length and update
block_len
andblock_len2
fields.
Constructor Details
#initialize(options = {}) ⇒ Block
Returns a new instance of Block.
31 32 33 34 35 |
# File 'lib/packetgen/pcapng/block.rb', line 31 def initialize(={}) super endianness([:endian] || :little) recalc_block_len end |
Instance Attribute Details
#block_len ⇒ Integer
32-bit block length
25 |
# File 'lib/packetgen/pcapng/block.rb', line 25 define_attr :block_len, BinStruct::Int32 |
#block_len2 ⇒ Integer
32-bit block length
29 |
# File 'lib/packetgen/pcapng/block.rb', line 29 define_attr :block_len2, BinStruct::Int32 |
#endian ⇒ :little, :big
16 17 18 |
# File 'lib/packetgen/pcapng/block.rb', line 16 def endian @endian end |
#type ⇒ Integer
32-bit block type
21 |
# File 'lib/packetgen/pcapng/block.rb', line 21 define_attr :type, BinStruct::Int32 |
Instance Method Details
#options? ⇒ Boolean
Has this block option?
40 41 42 |
# File 'lib/packetgen/pcapng/block.rb', line 40 def @attributes.key?(:options) && @attributes[:options].sz.positive? end |
#pad_field(*fields) ⇒ void
This method returns an undefined value.
Pad given field to 32 bit boundary, if needed
55 56 57 58 59 60 |
# File 'lib/packetgen/pcapng/block.rb', line 55 def pad_field(*fields) fields.each do |field| obj = @attributes[field] obj << "\x00" * -(obj.sz % -4) end end |
#recalc_block_len ⇒ void
This method returns an undefined value.
Calculate block length and update block_len
and block_len2
fields
46 47 48 49 |
# File 'lib/packetgen/pcapng/block.rb', line 46 def recalc_block_len len = attributes.map { |f| @attributes[f].to_s }.join.size self.block_len = self.block_len2 = len end |