class

Pcap::Capture

Inherits Iterator / Enumerable / Reference / Object

Constants

DEFAULT_NETMASK = 4294967040_u32
DEFAULT_OPTIMIZE = 1
DEFAULT_PROMISC = 1
DEFAULT_SNAPLEN = 1500
DEFAULT_TIMEOUT_MS = 1000

Constructors

new(pcap : LibPcap::PcapT)
Source

Class methods

open_dead(linktype : Int32 = DEFAULT_LINKTYPE, snaplen : Int32 = DEFAULT_SNAPLEN)
Source
open_live(device : String, snaplen : Int32 = DEFAULT_SNAPLEN, promisc : Int32 = DEFAULT_PROMISC, timeout_ms : Int32 = DEFAULT_TIMEOUT_MS)
Source
open_offline(file : String)
Source

Instance methods

callback
Source
callback=(callback : Pcap::Packet -> _)
Source
callback?
Source
close
Source
compile(filter, optimize = DEFAULT_OPTIMIZE, netmask = DEFAULT_NETMASK)
Source
get?

reads the next packet, and

  • trys again if read timeouted
  • returns Pcap::Packet if exists
  • returns nil if EOF reached (maybe read in offline mode)
  • raises Pcap::Error on error
Source
loop(count : Int32 = -1, &callback : Pcap::Packet -> )

calls pcap_loop that fetches all packets in the next buffer, and loop forever.

Source
next

called via iterator

Source
next_ex

calls pcap_next_ex that reads the next packet and returns a success/failure indication.

Source
set_promisc(flag : Bool)
Source
setfilter(filter : String, optimize : Int32 = DEFAULT_OPTIMIZE, netmask : UInt32 = DEFAULT_NETMASK)
Source