Module: PacketGen::PcapNG::Block
- Included in:
- EPB, IDB, SHB, SPB, UnknownBlock
- Defined in:
- lib/packetgen/pcapng/block.rb
Overview
Mixin module to declare some common methods for block classes.
Instance Method Summary collapse
-
#has_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.
Instance Method Details
#has_options? ⇒ Boolean
Has this block option?
14 15 16 |
# File 'lib/packetgen/pcapng/block.rb', line 14 def self[:options].size > 0 end |
#pad_field(*fields) ⇒ void
This method returns an undefined value.
Pad given field to 32 bit boundary, if needed
28 29 30 31 32 33 34 |
# File 'lib/packetgen/pcapng/block.rb', line 28 def pad_field(*fields) fields.each do |field| unless self[field].size % 4 == 0 self[field] << "\x00" * (4 - (self[field].size % 4)) end end end |
#recalc_block_len ⇒ void
This method returns an undefined value.
Calculate block length and update :block_len and block_len2 fields
20 21 22 23 |
# File 'lib/packetgen/pcapng/block.rb', line 20 def recalc_block_len len = to_a.map(&:to_s).join.size self[:block_len].value = self[:block_len2].value = len end |