class Pcaps {

  public static List<PcapNetworkInterface> findAllDevs() throws PcapNativeException {
    PointerByReference alldevsPP = new PointerByReference();
    PcapErrbuf errbuf = new PcapErrbuf();

    List<PcapNetworkInterface> ifList = new ArrayList<PcapNetworkInterface>();
    synchronized (lock) {
      int rc = NativeMappings.pcap_findalldevs(alldevsPP, errbuf);
      if (rc != 0) {
        StringBuilder sb = new StringBuilder(50);
        sb.append("Return code: ").append(rc).append(", Message: ").append(errbuf);
        throw new PcapNativeException(sb.toString(), rc);
      }
      if (errbuf.length() != 0) {
        logger.warn("{}", errbuf);
      }

      Pointer alldevsp = alldevsPP.getValue();
      if (alldevsp == null) {
        logger.info("No NIF was found.");
        return Collections.<PcapNetworkInterface>emptyList();
      }

      pcap_if pcapIf = new pcap_if(alldevsp);

      for (pcap_if pif = pcapIf; pif != null; pif = pif.next) {
        ifList.add(PcapNetworkInterface.newInstance(pif, true));
      }

      NativeMappings.pcap_freealldevs(pcapIf.getPointer());
    }

    logger.info("{} NIF(s) found.", ifList.size());
    return ifList;
  }

  private  Pcaps();

}