class PcapHandle implements Closeable {

  public List<DataLinkType> listDatalinks() throws PcapNativeException, NotOpenException {
    if (!open) {
      throw new NotOpenException();
    }

    List<DataLinkType> list;
    if (!handleLock.readLock().tryLock()) {
      throw new NotOpenException();
    }
    try {
      if (!open) {
        throw new NotOpenException();
      }

      PointerByReference dltBufPP = new PointerByReference();
      int rc = NativeMappings.pcap_list_datalinks(handle, dltBufPP);
      if (rc < 0) {
        throw new PcapNativeException(getError(), rc);
      }

      Pointer dltBufP = dltBufPP.getValue();
      list = new ArrayList<DataLinkType>(rc);
      for (int i : dltBufP.getIntArray(0, rc)) {
        list.add(DataLinkType.getInstance(i));
      }
      NativeMappings.pcap_free_datalinks(dltBufP);
    } finally {
      handleLock.readLock().unlock();
    }

    return list;
  }

    PcapHandle(Pointer handle, TimestampPrecision timestampPrecision);
  private  PcapHandle(Builder builder);

}