Module: PacketGen::Pcap Private

Defined in:
lib/packetgen/pcap.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.

Module to read/write PCAP files

Since:

  • 3.1.4

API:

  • private

Class Method Summary collapse

Class Method Details

.read(filename) ⇒ Array<Packet>

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.

Read a PCAP file

Parameters:

Returns:

Since:

  • 3.1.4

API:

  • private



20
21
22
23
24
25
26
27
28
29
# File 'lib/packetgen/pcap.rb', line 20

def self.read(filename)
  packets = []
  PCAPRUBWrapper.read_pcap(filename: filename) do |raw_packet|
    packet = PacketGen.parse(raw_packet.to_s)
    next if packet.nil?

    packets << packet
  end
  packets
end

.write(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

Parameters:

Since:

  • 4.0.0

API:

  • private



37
38
39
# File 'lib/packetgen/pcap.rb', line 37

def self.write(filename, packets)
  PCAPRUBWrapper.pcap_write(filename, packets.map(&:to_s))
end