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) 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
38 39 40 41 |
# File 'lib/diy/live.rb', line 38 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 |
# 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 sleep 0.1 end DIY::Logger.debug "stopped loop recv..." end |
#net ⇒ Object
43 44 45 |
# File 'lib/diy/live.rb', line 43 def net @live.network + " / " + @live.netmask end |
#set_filter(reg) ⇒ Object
34 35 36 |
# File 'lib/diy/live.rb', line 34 def set_filter(reg) @live.set_filter(reg) end |