code: def decode_file(fname):
      
      if _debug: decode_file._debug("decode_file %r", fname)
  
      if not pcap:
          raise RuntimeError("failed to import pcap")
  
      # create a pcap object, reading from the file
      p = pcap.pcap(fname)
  
      # loop through the packets
      for i, (timestamp, data) in enumerate(p):
          try:
              pkt = decode_packet(data)
              if not pkt:
                  continue
          except Exception as err:
              if _debug: decode_file._debug("    - exception decoding packet %d: %r", i+1, err)
              continue
  
          # save the packet number (as viewed in Wireshark) and timestamp
          pkt._number = i + 1
          pkt._timestamp = timestamp
  
          yield pkt
docs: Given the name of a pcap file, open it, decode the contents and yield each packet.