Class: FFI::PCap::Dumper

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/pcap/dumper.rb

Overview

See pcap_dumper_t in pcap.h.

A pcap_dumper, Dumper is handled opaquely so that it can be implemented differently on different platforms. In FFI::PCap, we simply wrap the pcap_dumper_t pointer with a ruby interface.

Instance Method Summary collapse

Constructor Details

#initialize(dumper) ⇒ Dumper

Returns a new instance of Dumper.



12
13
14
# File 'lib/ffi/pcap/dumper.rb', line 12

def initialize(dumper)
  @dumper = dumper
end

Instance Method Details

#_write(header, bytes) ⇒ Object



16
17
18
# File 'lib/ffi/pcap/dumper.rb', line 16

def _write(header, bytes)
  PCap.pcap_dump(@dumper, header, bytes)
end

#closeObject



39
40
41
# File 'lib/ffi/pcap/dumper.rb', line 39

def close
  PCap.pcap_dump_close(@dumper)
end

#flushObject



35
36
37
# File 'lib/ffi/pcap/dumper.rb', line 35

def flush
  PCap.pcap_dump_flush(@dumper)
end

#tellObject



31
32
33
# File 'lib/ffi/pcap/dumper.rb', line 31

def tell
  PCap.pcap_dump_ftell(@dumper)
end

#write(*args) ⇒ Object



20
21
22
23
24
25
# File 'lib/ffi/pcap/dumper.rb', line 20

def write(*args)
  case args.first
  when Packet then write_pkt(*args)
  else             _write(*args)
  end
end

#write_pkt(pkt) ⇒ Object



27
28
29
# File 'lib/ffi/pcap/dumper.rb', line 27

def write_pkt(pkt)
  _write(pkt.header, pkt.body_ptr)
end