Class: PacketFu::PcapNG::UnknownBlock
- Defined in:
- lib/packetfu/pcapng/unknown_block.rb
Overview
Pcapng::UnknownBlock is used to handle unsupported blocks of a pcapng file.
Constant Summary collapse
- MIN_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 ⇒ Object
Returns the value of attribute endian.
-
#section ⇒ Object
Returns the value of attribute section.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#init_fields(args = {}) ⇒ Object
Used by #initialize to set the initial fields.
-
#initialize(args = {}) ⇒ UnknownBlock
constructor
A new instance of UnknownBlock.
- #read(str_or_io) ⇒ Object
-
#to_s ⇒ Object
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(args = {}) ⇒ UnknownBlock
Returns a new instance of UnknownBlock.
15 16 17 18 19 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 15 def initialize(args={}) @endian = set_endianness(args[:endian] || :little) init_fields(args) super(args[:type], args[:block_len], args[:body], args[:block_len2]) end |
Instance Attribute Details
#block_len ⇒ Object
Returns the value of attribute block_len
7 8 9 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 7 def block_len @block_len end |
#block_len2 ⇒ Object
Returns the value of attribute block_len2
7 8 9 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 7 def block_len2 @block_len2 end |
#body ⇒ Object
Returns the value of attribute body
7 8 9 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 7 def body @body end |
#endian ⇒ Object
Returns the value of attribute endian.
10 11 12 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 10 def endian @endian end |
#section ⇒ Object
Returns the value of attribute section.
11 12 13 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 11 def section @section end |
#type ⇒ Object
Returns the value of attribute type
7 8 9 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 7 def type @type end |
Instance Method Details
#init_fields(args = {}) ⇒ Object
Used by #initialize to set the initial fields
22 23 24 25 26 27 28 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 22 def init_fields(args={}) args[:type] = @int32.new(args[:type] || 0) args[:block_len] = @int32.new(args[:block_len] || MIN_SIZE) args[:body] = StructFu::String.new(args[:body] || '') args[:block_len2] = @int32.new(args[:block_len2] || MIN_SIZE) args end |
#read(str_or_io) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 30 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 ⇒ Object
Return the object as a String
51 52 53 54 55 |
# File 'lib/packetfu/pcapng/unknown_block.rb', line 51 def to_s pad_field :body recalc_block_len to_a.map(&:to_s).join end |