16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pcap_tools/packet_processors/tcp.rb', line 16
def inject index, packet
stream_index = packet[:stream]
if stream_index
if packet[:tcp_flags][:syn] && packet[:tcp_flags][:ack] === false
@streams[stream_index] = {
:first => packet,
:data => [],
:tcp_lost_segment => false,
}
elsif packet[:tcp_flags][:fin] || packet[:tcp_flags][:rst]
if @streams[stream_index]
current = {:index => stream_index, :data => @streams[stream_index][:data]}
@stream_processors.each do |p|
current = p.process_stream current
break unless current
end
@streams.delete stream_index
end
else
if @streams[stream_index]
packet[:type] = (packet[:from] == @streams[stream_index][:first][:from] && packet[:from_port] == @streams[stream_index][:first][:from_port]) ? :out : :in
packet.delete :tcp_flags
@streams[stream_index][:data] << packet if packet[:size] > 0
if packet[:tcp_lost_segment]
@streams.delete stream_index
$stderr.puts "Ignoring tcp stream #{stream_index}, tcp segments are missing"
end
end
end
end
end
|