Class: PacketGen::PcapNG::EPB
- Inherits:
-
Block
- Object
- Types::Fields
- Block
- PacketGen::PcapNG::EPB
- Defined in:
- lib/packetgen/pcapng/epb.rb
Overview
EPB represents a Enhanced Packet Block (EPB) of a pcapng file.
EPB Definition
Int32 :type Default: 0x00000006
Int32 :block_len
Int32 :interface_id
Int32 :tsh (timestamp high)
Int32 :tsl (timestamp low)
Int32 :cap_len
Int32 :orig_len
String :data
String :options
Int32 :block_len2
Constant Summary collapse
- MIN_SIZE =
Minimum EPB size
8 * 4
Instance Attribute Summary collapse
-
#cap_len ⇒ Integer
32-bit capture length.
- #data ⇒ Types::String
- #endian ⇒ :little, :big
- #interface ⇒ IPB
-
#interface_id ⇒ Integer
32-bit interface ID.
- #options ⇒ Types::String
-
#orig_len ⇒ Integer
32-bit original length.
-
#tsh ⇒ Integer
high 32-bit timestamp value.
-
#tsl ⇒ Integer
low 32-bit imestamp value.
Attributes inherited from Block
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ EPB
constructor
A new instance of EPB.
-
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object.
-
#timestamp ⇒ Time
Return timestamp as a Time object.
-
#to_s ⇒ String
Return the object as a String.
Methods inherited from Block
#has_options?, #options?, #pad_field, #recalc_block_len
Methods inherited from Types::Fields
#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #inspect, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, update_field
Constructor Details
Instance Attribute Details
#cap_len ⇒ Integer
32-bit capture length
48 |
# File 'lib/packetgen/pcapng/epb.rb', line 48 define_field_before :block_len2, :cap_len, Types::Int32, default: 0 |
#data ⇒ Types::String
55 |
# File 'lib/packetgen/pcapng/epb.rb', line 55 define_field_before :block_len2, :data, Types::String |
#endian ⇒ :little, :big
29 30 31 |
# File 'lib/packetgen/pcapng/epb.rb', line 29 def endian @endian end |
#interface ⇒ IPB
31 32 33 |
# File 'lib/packetgen/pcapng/epb.rb', line 31 def interface @interface end |
#interface_id ⇒ Integer
32-bit interface ID
36 |
# File 'lib/packetgen/pcapng/epb.rb', line 36 define_field_before :block_len2, :interface_id, Types::Int32, default: 0 |
#options ⇒ Types::String
58 |
# File 'lib/packetgen/pcapng/epb.rb', line 58 define_field_before :block_len2, :options, Types::String |
#orig_len ⇒ Integer
32-bit original length
52 |
# File 'lib/packetgen/pcapng/epb.rb', line 52 define_field_before :block_len2, :orig_len, Types::Int32, default: 0 |
Instance Method Details
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/packetgen/pcapng/epb.rb', line 84 def read(str_or_io) io = if str_or_io.respond_to? :read str_or_io else 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[:interface_id].read io.read(4) self[:tsh].read io.read(4) self[:tsl].read io.read(4) self[:cap_len].read io.read(4) self[:orig_len].read io.read(4) self[:data].read io.read(self[:cap_len].to_i) data_pad_len = (4 - (self[:cap_len].to_i % 4)) % 4 io.read data_pad_len = self[:block_len].to_i - self[:cap_len].to_i - data_pad_len -= MIN_SIZE self[:options].read io.read() self[:block_len2].read io.read(4) check_len_coherency self end |
#timestamp ⇒ Time
Return timestamp as a Time object
113 114 115 |
# File 'lib/packetgen/pcapng/epb.rb', line 113 def Time.at((self[:tsh].to_i << 32 | self[:tsl].to_i) * ts_resol) end |
#to_s ⇒ String
Return the object as a String
119 120 121 122 123 |
# File 'lib/packetgen/pcapng/epb.rb', line 119 def to_s pad_field :data, :options recalc_block_len super end |