Class: DIY::Live
- Inherits:
-
Object
- Object
- DIY::Live
- Defined in:
- lib/diy/live.rb
Instance Attribute Summary collapse
-
#live ⇒ Object
readonly
Returns the value of attribute live.
Instance Method Summary collapse
- #break ⇒ Object
-
#initialize(device_name) ⇒ Live
constructor
A new instance of Live.
-
#inject(packet_str) ⇒ Object
(also: #send_packet)
发包.
- #loop(&block) ⇒ Object
- #net ⇒ Object
- #set_filter(reg) ⇒ Object
Constructor Details
#initialize(device_name) ⇒ Live
Returns a new instance of Live.
7 8 9 10 11 12 13 |
# File 'lib/diy/live.rb', line 7 def initialize(device_name) DIY::Logger.info( "Initialize Live: #{device_name}" ) @live = FFI::PCap::Live.new(:dev=>device_name, :handler => FFI::PCap::CopyHandler, :promisc => true, :timeout=>1) DIY::Logger.info( "Listen on: #{net} " ) @running = false @live.non_blocking= true end |
Instance Attribute Details
#live ⇒ Object (readonly)
Returns the value of attribute live.
14 15 16 |
# File 'lib/diy/live.rb', line 14 def live @live end |
Instance Method Details
#break ⇒ Object
39 40 41 42 |
# File 'lib/diy/live.rb', line 39 def break DIY::Logger.debug "stopping loop recv..." @running = false end |
#inject(packet_str) ⇒ Object Also known as: send_packet
发包
17 18 19 |
# File 'lib/diy/live.rb', line 17 def inject(packet_str) @live.send_packet(packet_str) end |
#loop(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/diy/live.rb', line 22 def loop(&block) @running = true while @running do @live.dispatch do |this, pkt| next unless pkt block.call(this, pkt) end block.call(nil, nil) # at least every 0.01 min do it. sleep 0.01 end DIY::Logger.debug "stopped loop recv..." end |
#net ⇒ Object
44 45 46 |
# File 'lib/diy/live.rb', line 44 def net @live.network + " / " + @live.netmask end |
#set_filter(reg) ⇒ Object
35 36 37 |
# File 'lib/diy/live.rb', line 35 def set_filter(reg) @live.set_filter(reg) end |