Class: Pcapz::Capture::BSD
- Inherits:
-
Object
- Object
- Pcapz::Capture::BSD
- Defined in:
- lib/pcapz/capture_types/bsd.rb
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(interface = Interfacez.default) ⇒ BSD
constructor
A new instance of BSD.
- #next_packet ⇒ Object
- #packets ⇒ Object
- #stop! ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(interface = Interfacez.default) ⇒ BSD
Returns a new instance of BSD.
4 5 6 7 8 9 10 |
# File 'lib/pcapz/capture_types/bsd.rb', line 4 def initialize(interface = Interfacez.default) @interface = interface @buffer_size = 0 @file = nil @internal_buffer = nil configure_bpf_dev end |
Instance Method Details
#file ⇒ Object
39 40 41 |
# File 'lib/pcapz/capture_types/bsd.rb', line 39 def file @file end |
#next_packet ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pcapz/capture_types/bsd.rb', line 18 def next_packet @internal_buffer.resume rescue Interrupt exit rescue @internal_buffer = Fiber.new do loop do begin buffer = @file.read_nonblock(@buffer_size) while buffer.size > 0 Fiber.yield buffer.slice!(0,(((buffer.slice(12,4).unpack('L')[0])+18) + 3 & ~3))[18..-1] end rescue IO::WaitReadable IO.select([@file]) retry end end end retry end |
#packets ⇒ Object
12 13 14 15 16 |
# File 'lib/pcapz/capture_types/bsd.rb', line 12 def packets until @file.closed? yield next_packet end end |
#stop! ⇒ Object
43 44 45 46 47 |
# File 'lib/pcapz/capture_types/bsd.rb', line 43 def stop! return nil if stopped? @file.close stopped? end |
#stopped? ⇒ Boolean
49 50 51 |
# File 'lib/pcapz/capture_types/bsd.rb', line 49 def stopped? @file.closed? end |