Class: Caper::Dumper

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

Overview

See pcap_dumper_t in pcap.h

A pcap_dumper, or Caper::Dumper is handled opaquely so that it can be implemented differently on different platforms. In Caper, 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.



11
12
13
# File 'lib/caper/dumper.rb', line 11

def initialize(dumper)
  @dumper = dumper
end

Instance Method Details

#_write(header, bytes) ⇒ Object



15
16
17
# File 'lib/caper/dumper.rb', line 15

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

#closeObject



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

def close
  Caper.pcap_dump_close(@dumper)
end

#flushObject



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

def flush
  Caper.pcap_dump_flush(@dumper)
end

#tellObject



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

def tell
  Caper.pcap_dump_ftell(@dumper)
end

#write(*args) ⇒ Object



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

def write(*args)
  if args.first.is_a? Packet
    write_pkt(*args)
  else
    _write(*args)
  end
end

#write_pkt(pkt) ⇒ Object



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

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