class Packetz::Capture

Overview

The Capture class is responsible for all of the supported capturing operations provided by LibPcap in a clean, friendly API.

Simply start a new capture object called cap, with all the defaults:

cap = Packetz::Capture.new

If you want to start customizing the capture object during initialization, you have a few ways to do that to change the #interface, #snapshot_length, #promiscuous_mode and #timeout_ms values of a capture.

Listen specifically on the en0 network interface:

cap = Packetz::Capture.new("en0")

Listen with alll the default options, but in promiscuous mode:

cap = Packetz::Capture.new(promiscuous_mode = true)

Change the default snapshot length from 65535 to half that size.

cap = Packetz::Capture.new(snapshot_length: 65535/2)

Defined in:

packetz/capture.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(interface : String = Packetz.interfaces.default, snapshot_length : Int32 = 65535, promiscuous_mode : Bool | Int32 = 0, timeout_ms : Int32 = 1, monitor_mode : Bool = false) #

The #initialize method takes care of setting up a new Capture object.


[View source]

Instance Method Detail

def each(&) #

[View source]
def enable_monitor_mode! #

[View source]
def immediate_mode! #

[View source]
def immediate_mode=(value : Int32) #

[View source]
def immediate_mode=(value : Bool) #

[View source]
def immediate_mode? #

[View source]
def interface : String #

Provides access to underlying interface string.


[View source]
def interface=(interface : String) #

Set the network interface to a given string.


[View source]
def microsecond_timestamp_precision! #

[View source]
def microsecond_timestamp_precision? #

[View source]
def monitor_mode : Bool #

[View source]
def monitor_mode=(value : Bool) #

[View source]
def monitor_mode? #

[View source]
def nanosecond_timestamp_precision! #

[View source]
def nanosecond_timestamp_precision? #

[View source]
def next #

[View source]
def non_blocking_mode! #

[View source]
def non_blocking_mode=(value : Int32) #

[View source]
def non_blocking_mode=(value : Bool) #

[View source]
def non_blocking_mode? #

[View source]
def promiscuous_mode #

[View source]
def promiscuous_mode! #

[View source]
def promiscuous_mode=(value : Bool) #

[View source]
def promiscuous_mode=(value : Int32) #

[View source]
def promiscuous_mode? #

[View source]
def reset! #

[View source]
def snapshot_length : Int32 #

[View source]
def snapshot_length=(value : Int32) #

[View source]
def start! #

Handles activating the actual packet capturing.


[View source]
def started? #

[View source]
def stop! #

[View source]
def stopped? #

[View source]
def supports_monitor_mode? #

[View source]
def timeout_ms : Int32 #

[View source]
def timeout_ms=(value : Int32) #

[View source]
def timestamp_precision #

[View source]