Class: PacketGen::PcapNG::Block Abstract
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::PcapNG::Block
- Defined in:
- lib/packetgen/pcapng/block.rb
Overview
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.
- #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 and block_len2 fields.
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?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
#initialize(options = {}) ⇒ Block
Returns a new instance of Block.
30 31 32 |
# File 'lib/packetgen/pcapng/block.rb', line 30 def initialize(={}) super end |
Instance Attribute Details
#block_len ⇒ Integer
32-bit block length
24 |
# File 'lib/packetgen/pcapng/block.rb', line 24 define_field :block_len, Types::Int32 |
#endian ⇒ :little, :big
15 16 17 |
# File 'lib/packetgen/pcapng/block.rb', line 15 def endian @endian end |
Instance Method Details
#options? ⇒ Boolean
Has this block option?
37 38 39 |
# File 'lib/packetgen/pcapng/block.rb', line 37 def @fields.key?(:options) && @fields[:options].sz.positive? end |
#pad_field(*fields) ⇒ void
This method returns an undefined value.
Pad given field to 32 bit boundary, if needed
51 52 53 54 55 56 57 |
# File 'lib/packetgen/pcapng/block.rb', line 51 def pad_field(*fields) fields.each do |field| obj = @fields[field] pad_size = (obj.sz % 4).zero? ? 0 : (4 - (obj.sz % 4)) obj << "\x00" * pad_size end end |
#recalc_block_len ⇒ void
This method returns an undefined value.
Calculate block length and update :block_len and block_len2 fields
43 44 45 46 |
# File 'lib/packetgen/pcapng/block.rb', line 43 def recalc_block_len len = fields.map { |f| @fields[f].to_s }.join.size self.block_len = self.block_len2 = len end |