Class: Caper::Dead

Inherits:
CommonWrapper show all
Defined in:
lib/caper/dead.rb

Overview

A wrapper class for pcap devices opened with open_dead()

Instance Attribute Summary collapse

Attributes inherited from CommonWrapper

#pcap

Instance Method Summary collapse

Methods inherited from CommonWrapper

#close, #closed?, #compile, #geterr, #open_dump, #ready?, #snaplen, #supported_datalinks, #to_ptr

Constructor Details

#initialize(opts = {}, &block) ⇒ Dead

Creates a fake pcap interface for compiling filters or opening a capture for output.

Parameters:

  • opts (Hash) (defaults to: {})

    Options are ignored and passed to the super-class except those below.

Options Hash (opts):

  • :datalink (optional, String, Symbol, Integer)

    The link-layer type for pcap. nil is equivalent to 0 (aka DLT_NULL).

  • :snaplen (optional, Integer)

    The snapshot length for the pcap object. Defaults to Caper::DEFAULT_SNAPLEN

Raises:



23
24
25
26
27
28
29
30
# File 'lib/caper/dead.rb', line 23

def initialize(opts={}, &block)
  dl = opts[:datalink] || DataLink.new(0)
  @datalink = dl.kind_of?(DataLink) ? dl : DataLink.new(dl)
  @snaplen  = opts[:snaplen] || DEFAULT_SNAPLEN
  @pcap = Caper.pcap_open_dead(@datalink.value, @snaplen)
  raise(LibError, "pcap_open_dead(): returned a null pointer") if @pcap.null?
  super(@pcap, opts, &block)
end

Instance Attribute Details

Returns the value of attribute datalink.



6
7
8
# File 'lib/caper/dead.rb', line 6

def datalink
  @datalink
end