Class: PacketFu::Write

Inherits:
Object
  • Object
show all
Defined in:
lib/packetfu/pcap.rb

Overview

Write is largely deprecated. It was current in PacketFu 0.2.0, but isn't all that useful in 0.3.0 and beyond. Expect it to go away completely by version 1.0, as working with PacketFu::PcapFile directly is generally going to be more rewarding.

Class Method Summary collapse

Class Method Details

.append(args = {}) ⇒ Object

Shorthand method for appending to a file. Also shouldn't use.


600
601
602
# File 'lib/packetfu/pcap.rb', line 600

def append(args={})
  array_to_file(args.merge(:append => true))
end

.array_to_file(args = {}) ⇒ Object Also known as: a2f

array_to_file is a largely deprecated function for writing arrays of pcaps to a file. Use PcapFile#array_to_file instead.


571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/packetfu/pcap.rb', line 571

def array_to_file(args={})
  filename = args[:filename] || args[:file] || args[:out] || :nowrite
  arr = args[:arr] || args[:array] || []
  ts = args[:ts] || args[:timestamp] || args[:time_stamp] || Time.now.to_f
  ts_inc = args[:ts_inc] || args[:timestamp_increment] || args[:time_stamp_increment]
  byte_order = args[:byte_order] || args[:byteorder] || args[:endian] || args[:endianness] || :little
  append = args[:append]
  Read.set_byte_order(byte_order) if [:big, :little].include? byte_order
  pf = PcapFile.new
  pf.array_to_file(:endian => PacketFu.instance_variable_get(:@byte_order),
                   :arr => arr,
                   :ts => ts,
                   :ts_inc => ts_inc)
  if filename && filename != :nowrite
    if append
      pf.append(filename)
    else
      pf.write(filename)
    end
    return [filename,pf.to_s.size,arr.size,ts,ts_inc]
  else
    return [nil,pf.to_s.size,arr.size,ts,ts_inc]
  end

end

.format_packets(args = {}) ⇒ Object

format_packets: Pretty much totally deprecated.


558
559
560
561
562
563
564
565
566
567
# File 'lib/packetfu/pcap.rb', line 558

def format_packets(args={})
  arr = args[:arr] || args[:array] || []
  ts = args[:ts] || args[:timestamp] || Time.now.to_i
  ts_inc = args[:ts_inc] || args[:timestamp_increment]
  pkts = PcapFile.new.array_to_file(:endian => PacketFu.instance_variable_get(:@byte_order),
                                    :arr => arr,
                                    :ts => ts,
                                    :ts_inc => ts_inc)
  pkts.body
end