def make_tcp_sessions_ng(session): connection = None # key == directed_key reverse_connection = None for ip,tcp in session: directed_key = TCPSession.directed_key(ip.src,ip.dst,tcp.sport,tcp.dport) not_repeat = None while not not_repeat: if not connection: connection=TCPSession(directed_key) reversed_key = TCPSession.directed_key(ip.dst,ip.src,tcp.dport,tcp.sport) reverse_connection=TCPSession(reversed_key) connection.pair = reverse_connection reverse_connection.pair = connection tcp.string_flags = tcp_flags(tcp.flags) #tcp.partof=set() if directed_key == connection.directed_key: not_repeat=connection.packet(tcp) elif directed_key == reverse_connection.directed_key: not_repeat=reverse_connection.packet(tcp) else: assert False if not not_repeat: yield (connection,reverse_connection) connection=None reverse_connection=None yield (connection,reverse_connection)
def print_packet(file, tcp, direction_hint=None): if direction_hint is None: display_key = TCPSession.split_key(tcp.connection.directed_key) display_key = " %s : %s -> %s : %s " % display_key else: if direction_hint==tcp.connection.directed_key: display_key = " --> " else: display_key = " <-- " string_flags = tcp_flags(tcp.flags) retr = ' ' if tcp.retransmit_original is not None: retr = 'R' if 'A' in string_flags: ack = tcp.adjusted_ack else: ack='' acked=getattr(tcp,'acked_by',None) if acked is not None: acked=acked.num sacked=getattr(tcp,'acked_sacked_by',None) if sacked is not None: sacked=sacked.num if sacked == acked: sacked = '' else: sacked = "/"+str(sacked) acked = str(acked) sacked_acked='' if len(tcp.data)>0 or 'S' in string_flags: sacked_acked=acked+sacked rtt = tcp.rtt if rtt is not None and abs(rtt)>1000: rtt = str(rtt/1000)+'s' rtt = "[%4s]" % rtt else: rtt='' adjusted_sack=getattr(tcp,'adjusted_sack', '') print >> file, "%10d %7s %f %ls %4d %4s %7ds %7sa %5s %10s %s" % (tcp.num, rtt, tcp.ts, display_key, len(tcp.data), string_flags, getattr(tcp,'adjusted_seq',-1), ack, retr, sacked_acked, adjusted_sack), partof = getattr(tcp,'partof',None) if partof is not None: for http, partkind in partof.iteritems(): print >> file, "%2s" % partkind, print >> file, http.method, if hasattr(http,'status'): print >> file, http.status, if hasattr(http,'uri'): print >> file, http.uri, if getattr(http,'reqid',None): print >> file, http.reqid, print >> file, ""
def print_packet(file, tcp, direction_hint=None): if direction_hint is None: display_key = TCPSession.split_key(tcp.connection.directed_key) display_key = " %s : %s -> %s : %s " % display_key else: if direction_hint == tcp.connection.directed_key: display_key = " --> " else: display_key = " <-- " string_flags = tcp_flags(tcp.flags) retr = ' ' if tcp.retransmit_original is not None: retr = 'R' if 'A' in string_flags: ack = tcp.adjusted_ack else: ack = '' acked = getattr(tcp, 'acked_by', None) if acked is not None: acked = acked.num sacked = getattr(tcp, 'acked_sacked_by', None) if sacked is not None: sacked = sacked.num if sacked == acked: sacked = '' else: sacked = "/" + str(sacked) acked = str(acked) sacked_acked = '' if len(tcp.data) > 0 or 'S' in string_flags: sacked_acked = acked + sacked rtt = tcp.rtt if rtt is not None and abs(rtt) > 1000: rtt = str(rtt / 1000) + 's' rtt = "[%4s]" % rtt else: rtt = '' adjusted_sack = getattr(tcp, 'adjusted_sack', '') print >> file, "%10d %7s %f %ls %4d %4s %7ds %7sa %5s %10s %s" % ( tcp.num, rtt, tcp.ts, display_key, len(tcp.data), string_flags, getattr(tcp, 'adjusted_seq', -1), ack, retr, sacked_acked, adjusted_sack), partof = getattr(tcp, 'partof', None) if partof is not None: for http, partkind in partof.iteritems(): print >> file, "%2s" % partkind, print >> file, http.method, if hasattr(http, 'status'): print >> file, http.status, if hasattr(http, 'uri'): print >> file, http.uri, if getattr(http, 'reqid', None): print >> file, http.reqid, print >> file, ""