Class: Xlat::Pcap
- Inherits:
-
Object
- Object
- Xlat::Pcap
- Defined in:
- lib/xlat/pcap.rb
Constant Summary collapse
- MAGIC =
nanosec timestamp
0xA1B23C4D- MAJOR =
2- MINOR =
4- LINKTYPE_RAW =
raw IP
101
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#snap_len ⇒ Object
readonly
Returns the value of attribute snap_len.
Instance Method Summary collapse
-
#initialize(io, snap_len: 0xffff) ⇒ Pcap
constructor
A new instance of Pcap.
- #write(packet, ts: Time.now) ⇒ Object
Constructor Details
#initialize(io, snap_len: 0xffff) ⇒ Pcap
Returns a new instance of Pcap.
7 8 9 10 11 12 |
# File 'lib/xlat/pcap.rb', line 7 def initialize(io, snap_len: 0xffff) @io = io @snap_len = snap_len write_header end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
5 6 7 |
# File 'lib/xlat/pcap.rb', line 5 def io @io end |
#snap_len ⇒ Object (readonly)
Returns the value of attribute snap_len.
5 6 7 |
# File 'lib/xlat/pcap.rb', line 5 def snap_len @snap_len end |
Instance Method Details
#write(packet, ts: Time.now) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/xlat/pcap.rb', line 33 def write(packet, ts: Time.now) caplen = [packet.size, @snap_len].min h = IO::Buffer.new(16) h.set_values(%i[u32 u32 u32 u32], 0, [ ts.to_i, ts.nsec, caplen, packet.size, ]) h.write(@io) packet.write(@io, caplen) end |