Class: FFI::PCap::Dead

Inherits:
CommonWrapper show all
Defined in:
lib/ffi/pcap/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 FFI::PCap::DEFAULT_SNAPLEN



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ffi/pcap/dead.rb', line 32

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 = PCap.pcap_open_dead(@datalink.value, @snaplen)

  if @pcap.null?
    raise(LibError,"pcap_open_dead(): returned a null pointer",caller)
  end

  super(@pcap, opts, &block)
end

Instance Attribute Details

Returns the value of attribute datalink.



11
12
13
# File 'lib/ffi/pcap/dead.rb', line 11

def datalink
  @datalink
end