Class: Jruby::Pcap::LiveHandle

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jruby-pcap/live_handle.rb

Instance Method Summary collapse

Constructor Details

#initialize(interface) ⇒ LiveHandle

Returns a new instance of LiveHandle.



9
10
11
# File 'lib/jruby-pcap/live_handle.rb', line 9

def initialize(interface)
  @interface = interface
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jruby-pcap/live_handle.rb', line 13

def each
  handle = @interface.open_live(1024, PcapNetworkInterface::PromiscuousMode::PROMISCUOUS, 0)
  while true do
    next_packet = handle.next_packet_ex
    if next_packet
      yield Packet.new(next_packet, handle)
    else
      break
    end
  end
end