Class: PacketGen::PcapNG::UnknownBlock
- Defined in:
- lib/packetgen/pcapng/unknown_block.rb
Overview
UnknownBlock is used to handle unsupported blocks of a pcapng file.
Constant Summary collapse
- MIN_SIZE =
Minimum Iblock size
12
Instance Attribute Summary collapse
-
#block_len ⇒ Object
Returns the value of attribute block_len.
-
#block_len2 ⇒ Object
Returns the value of attribute block_len2.
-
#body ⇒ Object
Returns the value of attribute body.
- #endian ⇒ :little, :big
- #section ⇒ SHB
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#has_options? ⇒ false
Has this block option?.
-
#init_fields(options = {}) ⇒ Hash
Used by #initialize to set the initial fields.
-
#initialize(options = {}) ⇒ UnknownBlock
constructor
A new instance of UnknownBlock.
- #read(str_or_io) ⇒ self
-
#to_s ⇒ String
Return the object as a String.
Methods included from Block
Methods included from StructFu
#clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(options = {}) ⇒ UnknownBlock
Returns a new instance of UnknownBlock.
22 23 24 25 26 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 22 def initialize(={}) @endian = set_endianness([:endian] || :little) init_fields() super([:type], [:block_len], [:body], [:block_len2]) end |
Instance Attribute Details
#block_len ⇒ Object
Returns the value of attribute block_len
5 6 7 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 5 def block_len @block_len end |
#block_len2 ⇒ Object
Returns the value of attribute block_len2
5 6 7 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 5 def block_len2 @block_len2 end |
#body ⇒ Object
Returns the value of attribute body
5 6 7 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 5 def body @body end |
#endian ⇒ :little, :big
10 11 12 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 10 def endian @endian end |
#section ⇒ SHB
12 13 14 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 12 def section @section end |
#type ⇒ Object
Returns the value of attribute type
5 6 7 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 5 def type @type end |
Instance Method Details
#has_options? ⇒ false
Has this block option?
42 43 44 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 42 def false end |
#init_fields(options = {}) ⇒ Hash
Used by #initialize to set the initial fields
32 33 34 35 36 37 38 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 32 def init_fields(={}) [:type] = @int32.new([:type] || 0) [:block_len] = @int32.new([:block_len] || MIN_SIZE) [:body] = StructFu::String.new([:body] || '') [:block_len2] = @int32.new([:block_len2] || MIN_SIZE) end |
#read(str_or_io) ⇒ self
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 49 def read(str_or_io) if str_or_io.respond_to? :read io = str_or_io else io = StringIO.new(force_binary(str_or_io.to_s)) end return self if io.eof? self[:type].read io.read(4) self[:block_len].read io.read(4) self[:body].read io.read(self[:block_len].to_i - MIN_SIZE) self[:block_len2].read io.read(4) unless self[:block_len].to_i == self[:block_len2].to_i raise InvalidFileError, 'Incoherency in Header Block' end self end |
#to_s ⇒ String
Return the object as a String
71 72 73 74 75 |
# File 'lib/packetgen/pcapng/unknown_block.rb', line 71 def to_s pad_field :body recalc_block_len to_a.map(&:to_s).join end |