Class: PacketViaDMEM::CLI
- Inherits:
-
Object
- Object
- PacketViaDMEM::CLI
- Defined in:
- lib/packet_via_dmem/cli.rb
Defined Under Namespace
Classes: InvalidFile, NoFile
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 14 15 |
# File 'lib/packet_via_dmem/cli.rb', line 10 def initialize @opts = opts_parse @debug = @opts.debug? @log = Logger.new STDERR @log.level = Logger::INFO unless @debug end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
8 9 10 |
# File 'lib/packet_via_dmem/cli.rb', line 8 def debug @debug end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/packet_via_dmem/cli.rb', line 17 def run file = get_file if not @opts.stdin? dmem = PacketViaDMEM.new :received=>@opts.received?, :sent=>@opts.sent?, :log=>@log count = 0 block = Proc.new do |pkt| pop = false if pkt.type == :received next if @opts.sent? pop = @opts[:poprx] elsif pkt.type == :sent next unless (@opts.sent? or @opts.both?) pop = @opts[:poptx] end packet = @opts.original? ? pkt.pretty_original : pkt.pretty_packet packet = pkt.pretty pkt.pop(pop) if pop puts pkt.header.to_s count+=1 puts packet $stderr.puts pkt.popped.join(' ') if @opts.popped? puts end packets = @opts.stdin? ? dmem.stream($stdin, &block) : dmem.parse(file).each(&block) end |