class Pcap::Capture

Included Modules

Defined in:

pcap/capture.cr

Constant Summary

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

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pcap : LibPcap::PcapT) #

[View source]

Class Method Detail

def self.open_dead(linktype : Int32 = DEFAULT_LINKTYPE, snaplen : Int32 = DEFAULT_SNAPLEN) #

[View source]
def self.open_live(device : String, snaplen : Int32 = DEFAULT_SNAPLEN, promisc : Int32 = DEFAULT_PROMISC, timeout_ms : Int32 = DEFAULT_TIMEOUT_MS) #

[View source]
def self.open_offline(file : String) #

[View source]

Instance Method Detail

def callback #

def callback=(callback : Pcap::Packet -> _) #

[View source]
def callback? : Pcap::Packet -> Nil #

def close #

[View source]
def compile(filter, optimize = DEFAULT_OPTIMIZE, netmask = DEFAULT_NETMASK) #

[View source]
def get? : Packet | Nil #

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

[View source]
def loop(count : Int32 = -1, &callback : Pcap::Packet -> ) #

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


[View source]
def next #

called via iterator


[View source]
def next_ex : NextError | Packet #

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


[View source]
def set_promisc(flag : Bool) #

[View source]
def setfilter(filter : String, optimize : Int32 = DEFAULT_OPTIMIZE, netmask : UInt32 = DEFAULT_NETMASK) #

[View source]