Class: Pcapz::Capture::Linux

Inherits:
Object
  • Object
show all
Defined in:
lib/pcapz/capture_types/linux.rb

Instance Method Summary collapse

Constructor Details

#initialize(interface = Interfacez.default) ⇒ Linux

Returns a new instance of Linux.



4
5
6
7
8
9
# File 'lib/pcapz/capture_types/linux.rb', line 4

def initialize(interface = Interfacez.default)
  @interface   = interface
  @buffer_size = 0
  @file        = nil
  configure_socket
end

Instance Method Details

#fileObject



26
27
28
# File 'lib/pcapz/capture_types/linux.rb', line 26

def file
  @file
end

#next_packetObject



17
18
19
20
21
22
23
24
# 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

#packetsObject



11
12
13
14
15
# File 'lib/pcapz/capture_types/linux.rb', line 11

def packets
  until @file.closed?
    yield next_packet
  end
end

#stop!Object



30
31
32
33
34
# File 'lib/pcapz/capture_types/linux.rb', line 30

def stop!
  return nil if stopped?
  @file.close
  stopped?
end

#stopped?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pcapz/capture_types/linux.rb', line 36

def stopped?
  @file.closed?
end