def next_connection_packets(piter, linktype=1):
 first_ft = None
 for (ts, raw) in piter:
  ft = flowtuple_from_raw(raw, linktype)
  if (not first_ft):
   first_ft = ft
  (sip, dip, sport, dport, proto) = ft
  if (not ((first_ft == ft) or (first_ft == (dip, sip, dport, sport, proto)))):
   break
  (yield {'src': sip, 'dst': dip, 'sport': sport, 'dport': dport, 'raw': payload_from_raw(raw, linktype).encode('base64'), 'direction': (first_ft == ft)})

def next_connection_packets ( piter , linktype = 1 ) : first_ft = None for ( ts , raw ) in piter : ft = flowtuple_from_raw ( raw , linktype ) if ( not first_ft ) : first_ft = ft ( sip , dip , sport , dport , proto ) = ft if ( not ( ( first_ft == ft ) or ( first_ft == ( dip , sip , dport , sport , proto ) ) ) ) : break ( yield { 'src' : sip , 'dst' : dip , 'sport' : sport , 'dport' : dport , 'raw' : payload_from_raw ( raw , linktype ) . encode ( 'base64' ) , 'direction' : ( first_ft == ft ) } )
extract all packets belonging to the same flow from a pcap packet iterator .