code: def tcp_reassembly(packet, *, count=NotImplemented):
      
      if getattr(packet, 'ip', None):
          ip = packet['ip']
      elif getattr(packet, 'ip6', None):
          ip = packet['ip6']
      else:
          return False, None
      tcp = getattr(ip, 'tcp', None)
      if tcp is not None:
          flags = bin(tcp.flags)[2:].zfill(8)
          data = dict(
              bufid=(
                  ipaddress.ip_address(ip.src),                   # source IP address
                  ipaddress.ip_address(ip.dst),                   # destination IP address
                  tcp.sport,                                      # source port
                  tcp.dport,                                      # destination port
              ),
              num=count,                                          # original packet range number
              ack=tcp.ack,                                        # acknowledgement
              dsn=tcp.seq,                                        # data sequence number
              rst=bool(int(flags[5])),                            # reset connection flag
              syn=bool(int(flags[6])),                            # synchronise flag
              fin=bool(int(flags[7])),                            # finish flag
              payload=bytearray(tcp.pack()[tcp.__hdr_len__:]),    # raw bytearray type payload
          )
          raw_len = len(tcp.data)                                 # payload length, header excludes
          data['first'] = tcp.seq                                 # this sequence number
          data['last'] = tcp.seq + raw_len                        # next (wanted) sequence number
          data['len'] = raw_len                                   # payload length, header excludes
          return True, data
      return False, None
docs: Make data for TCP reassembly.