Class: Capturing::Runner
- Inherits:
-
Object
show all
- Defined in:
- lib/capture.rb
Instance Method Summary
collapse
Constructor Details
#initialize(exec) ⇒ Runner
Returns a new instance of Runner.
8
9
10
11
12
|
# File 'lib/capture.rb', line 8
def initialize(exec)
@exec = exec
@pcaplet = Pcap::Capture.open_live(exec.device, exec.max_bytes, true, exec.timeout)
@pcaplet.setfilter(Pcap::Filter.new("port #{exec.port} and tcp", @pcaplet))
end
|
Instance Method Details
#destroy! ⇒ Object
31
32
33
|
# File 'lib/capture.rb', line 31
def destroy!
@pcaplet.close
end
|
#on_packet(data) ⇒ Object
27
28
29
|
# File 'lib/capture.rb', line 27
def on_packet(data)
raise NotImplementedError.new "on_packet(packet)"
end
|
#run! ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/capture.rb', line 14
def run!
@pcaplet.each_packet do |packet|
if packet.tcp? && packet.tcp_data_len > 0
@exec.logger.debug "Handle message packets: #{packet}"
begin
on_packet packet.tcp_data
rescue => e
@exec.logger.error e
end
end
end
end
|