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.
-
.write_pcap(filename:, packets:) ⇒ void
private
Write binary packets to 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
55 56 57 58 59 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 55 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
65 66 67 68 69 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 65 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
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 33 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 pcap 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
76 77 78 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 76 def self.read_pcap(filename:, &block) PCAPRUB::Pcap.open_offline(filename).each_packet(&block) end |
.write_pcap(filename:, packets:) ⇒ 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.
Write binary packets to a PCAP file
86 87 88 89 90 91 92 |
# File 'lib/packetgen/pcaprub_wrapper.rb', line 86 def self.write_pcap(filename:, packets:) PCAPRUB::Pcap.dump_open(filename) do |pcap| packets.each do |packet| pcap.dump(packet) end end end |