code: def packet2dict(packet, timestamp, *, data_link):
      
      def wrapper(packet):
          dict_ = dict()
          for field in packet.__hdr_fields__:
              dict_[field] = getattr(packet, field, None)
          payload = packet.data
          if not isinstance(payload, bytes):
              dict_[type(payload).__name__] = wrapper(payload)
          return dict_
      return {
          'timestamp': timestamp,
          'packet': packet.pack(),
          data_link.name: wrapper(packet),
      }
docs: Convert DPKT packet into dict.