Module: PacketGen::PCAPRUBWrapper Private
- Defined in:
- lib/packetgen/pcaprub_wrapper.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Wrapper around PCAPRUB
Constant Summary collapse
- TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
timeout for PCAPRUB
1
- DEFAULT_SNAPLEN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default snaplen to use
0xffff
- DEFAULT_PROMISC =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default promisc value to use
false
Class Method Summary collapse
-
.capture(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, filter: nil, monitor: nil) {|packet_data| ... } ⇒ void
private
Capture packets from a network interface.
-
.inject(iface:, data:) ⇒ void
private
Inject given data onto wire.
-
.open_iface(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, monitor: nil) ⇒ PCAPRUB::Pcap
private
Open an interface for capturing.
-
.read_pcap(filename:) {|data| ... } ⇒ void
private
Read a PCAP file.
Class Method Details
.capture(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, filter: nil, monitor: nil) {|packet_data| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Capture packets from a network interface
53 54 55 56 57 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 53 def self.capture(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, filter: nil, monitor: nil, &block) pcap = self.open_iface(iface: iface, snaplen: snaplen, promisc: promisc, monitor: monitor) pcap.setfilter filter unless filter.nil? pcap.each_packet(&block) end |
.inject(iface:, data:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Inject given data onto wire
63 64 65 66 67 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 63 def self.inject(iface:, data:) pcap = self.open_iface(iface: iface) pcap.inject(data) pcap.close end |
.open_iface(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, monitor: nil) ⇒ PCAPRUB::Pcap
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Open an interface for capturing
32 33 34 35 36 37 38 39 40 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 32 def self.open_iface(iface:, snaplen: DEFAULT_SNAPLEN, promisc: DEFAULT_PROMISC, monitor: nil) pcap = PCAPRUB::Pcap.create(iface) pcap.setsnaplen(snaplen) pcap.setpromisc(promisc) pcap.settimeout(TIMEOUT) # Monitor MUST be set before pcap is activated pcap.setmonitor monitor unless monitor.nil? pcap.activate end |
.read_pcap(filename:) {|data| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Read a PCAP file
74 75 76 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 74 def self.read_pcap(filename:, &block) PCAPRUB::Pcap.open_offline(filename).each_packet(&block) end |