Class: Caper::Offline

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

Overview

A wrapper class for pcap devices opened with open_offline()

Instance Attribute Summary collapse

Attributes inherited from CaptureWrapper

#handler

Attributes inherited from CommonWrapper

#pcap

Instance Method Summary collapse

Methods inherited from CaptureWrapper

#breakloop, #dispatch, #loop, #next, #old_next, #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.



29
30
31
32
33
34
35
# File 'lib/caper/offline.rb', line 29

def initialize(path, opts={}, &block)
  @path = path
  @errbuf = ErrorBuffer.create()
  @pcap = Caper.pcap_open_offline(File.expand_path(@path), @errbuf)
  raise(LibError, "pcap_open_offline(): #{@errbuf.to_s}") if @pcap.null?
  super(@pcap, opts, &block)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/caper/offline.rb', line 7

def path
  @path
end

Instance Method Details

#file_versionObject



41
42
43
# File 'lib/caper/offline.rb', line 41

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

#swapped?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/caper/offline.rb', line 37

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