class Pcapz::Capture::Linux
Public Class Methods
new(interface = Interfacez.default)
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 4 def initialize(interface = Interfacez.default) @interface = interface @buffer_size = 0 @file = nil configure_socket end
Public Instance Methods
file()
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 26 def file @file end
next_packet()
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 17 def next_packet @file.recvfrom_nonblock(@buffer_size)[0] rescue IO::WaitReadable IO.select([@file]) retry rescue Interrupt exit end
packets() { |next_packet| ... }
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 11 def packets until @file.closed? yield next_packet end end
stop!()
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 30 def stop! return nil if stopped? @file.close stopped? end
stopped?()
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 36 def stopped? @file.closed? end
Private Instance Methods
configure_socket(interface: @interface)
click to toggle source
# File lib/pcapz/capture_types/linux.rb, line 42 def configure_socket(interface: @interface) @file = Socket.new(Socket::PF_PACKET, Socket::SOCK_RAW, 0x03_00) @file.setsockopt(Socket::SOL_SOCKET, Socket::SO_BINDTODEVICE, interface) @buffer_size = 65535 rescue @file.close unless @file.nil? or @file.closed? raise "Unable to create network listener on #{@interface}!" end