Class: 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 ( high)
Int32 :tsl ( 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 ⇒ BinStruct::String
- #endian ⇒ :little, :big
- #interface ⇒ IPB
-
#interface_id ⇒ Integer
32-bit interface ID.
- #options ⇒ BinStruct::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
#block_len, #block_len2, #type
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.
-
#timestamp=(time) ⇒ Time
Set timestamp from a Time object.
-
#to_s ⇒ String
Return the object as a String.
Methods inherited from Block
#options?, #pad_field, #recalc_block_len
Constructor Details
#initialize(options = {}) ⇒ EPB
Returns a new instance of EPB.
75 76 77 78 |
# File 'lib/packetgen/pcapng/epb.rb', line 75 def initialize(={}) super self.type = [:type] || PcapNG::EPB_TYPE.to_i end |
Instance Attribute Details
#cap_len ⇒ Integer
32-bit capture length
49 |
# File 'lib/packetgen/pcapng/epb.rb', line 49 define_attr_before :block_len2, :cap_len, BinStruct::Int32, default: 0 |
#data ⇒ BinStruct::String
56 |
# File 'lib/packetgen/pcapng/epb.rb', line 56 define_attr_before :block_len2, :data, BinStruct::String |
#endian ⇒ :little, :big
30 31 32 |
# File 'lib/packetgen/pcapng/epb.rb', line 30 def endian @endian end |
#interface ⇒ IPB
32 33 34 |
# File 'lib/packetgen/pcapng/epb.rb', line 32 def interface @interface end |
#interface_id ⇒ Integer
32-bit interface ID
37 |
# File 'lib/packetgen/pcapng/epb.rb', line 37 define_attr_before :block_len2, :interface_id, BinStruct::Int32, default: 0 |
#options ⇒ BinStruct::String
59 |
# File 'lib/packetgen/pcapng/epb.rb', line 59 define_attr_before :block_len2, :options, BinStruct::String |
#orig_len ⇒ Integer
32-bit original length
53 |
# File 'lib/packetgen/pcapng/epb.rb', line 53 define_attr_before :block_len2, :orig_len, BinStruct::Int32, default: 0 |
#tsh ⇒ Integer
high 32-bit timestamp value
41 |
# File 'lib/packetgen/pcapng/epb.rb', line 41 define_attr_before :block_len2, :tsh, BinStruct::Int32, default: 0 |
#tsl ⇒ Integer
low 32-bit imestamp value
45 |
# File 'lib/packetgen/pcapng/epb.rb', line 45 define_attr_before :block_len2, :tsl, BinStruct::Int32, default: 0 |
Instance Method Details
#read(str_or_io) ⇒ self
Reads a String or a IO to populate the object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/packetgen/pcapng/epb.rb', line 83 def read(str_or_io) io = to_io(str_or_io) return self if io.eof? i[type block_len interface_id tsh tsl cap_len orig_len].each do |attr| self[attr].read(io.read(self[attr].sz)) end self[:data].read(io.read(self.cap_len)) (io) read_blocklen2_and_check(io) self end |
#timestamp ⇒ Time
Return timestamp as a Time object
99 100 101 |
# File 'lib/packetgen/pcapng/epb.rb', line 99 def Time.at((self.tsh << 32 | self.tsl) * ts_resol) end |
#timestamp=(time) ⇒ Time
Set timestamp from a Time object
106 107 108 109 110 111 |
# File 'lib/packetgen/pcapng/epb.rb', line 106 def (time) tstamp = (time.to_r / ts_resol).to_i self.tsh = (tstamp & 0xffffffff00000000) >> 32 self.tsl = tstamp & 0xffffffff time end |
#to_s ⇒ String
Return the object as a String
115 116 117 118 119 |
# File 'lib/packetgen/pcapng/epb.rb', line 115 def to_s pad_field(:data, :options) recalc_block_len super end |