Class: FFI::PCap::Offline

Inherits:
CaptureWrapper show all
Defined in:
lib/ffi/pcap/offline.rb

Overview

A wrapper class for pcap devices opened with open_offline.

Constant Summary

Constants inherited from CaptureWrapper

CaptureWrapper::DEFAULT_COUNT

Instance Attribute Summary collapse

Attributes inherited from CaptureWrapper

#handler

Attributes inherited from CommonWrapper

#pcap

Instance Method Summary collapse

Methods inherited from CaptureWrapper

#breakloop, #dispatch, #fileno, #loop, #next, #old_next, #selectable_fd, #selectable_io, #set_filter

Methods inherited from CommonWrapper

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

Constructor Details

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

Creates a pcap interface for reading saved capture files.

Parameters:

  • path (String)

    The path to the file to open.

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

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

Options Hash (opts):

  • :path (ignored)

    The :path option will be overridden with the value of the path argument. If specified in opts, its value will be ignored.

Raises:

  • (LibError)

    On failure, an exception is raised with the relevant error message from libpcap.



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

def initialize(path, opts={}, &block)
  @path   = path
  @errbuf = ErrorBuffer.new
  @pcap   = PCap.pcap_open_offline(File.expand_path(@path), @errbuf)

  if @pcap.null?
    raise(LibError,"pcap_open_offline(): #{@errbuf}",caller)
  end

  super(@pcap, opts, &block)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/ffi/pcap/offline.rb', line 10

def path
  @path
end

Instance Method Details

#file_versionObject



49
50
51
# File 'lib/ffi/pcap/offline.rb', line 49

def file_version
  "#{PCap.pcap_major_version(_pcap)}.#{PCap.pcap_minor_version(_pcap)}"
end

#swapped?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ffi/pcap/offline.rb', line 45

def swapped?
  PCap.pcap_is_swapped(_pcap) == 1 ? true : false
end