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); DataLinkType getDlt(); void setDlt(DataLinkType dlt); boolean isOpen(); String getFilteringExpression(); TimestampPrecision getTimestampPrecision(); void setDirection(PcapDirection direction); Timestamp getTimestamp(); Integer getOriginalLength(); int getSnapshot(); SwappedType isSwapped(); int getMajorVersion(); int getMinorVersion(); BpfProgram compileFilter(String bpfExpression, BpfCompileMode mode, Inet4Address netmask); void setFilter(String bpfExpression, BpfCompileMode mode, Inet4Address netmask); void setFilter(String bpfExpression, BpfCompileMode mode); void setFilter(BpfProgram prog); void setBlockingMode(BlockingMode mode); BlockingMode getBlockingMode(); Packet getNextPacket(); byte[] getNextRawPacket(); Packet getNextPacketEx(); byte[] getNextRawPacketEx(); void loop(int packetCount, PacketListener listener); void loop(int packetCount, PacketListener listener, Executor executor); void loop(int packetCount, RawPacketListener listener); void loop(int packetCount, RawPacketListener listener, Executor executor); int dispatch(int packetCount, PacketListener listener); int dispatch(int packetCount, PacketListener listener, Executor executor); int dispatch(int packetCount, RawPacketListener listener); int dispatch(int packetCount, RawPacketListener listener, Executor executor); PcapDumper dumpOpen(String filePath); void loop(int packetCount, PcapDumper dumper); void breakLoop(); void sendPacket(Packet packet); void sendPacket(byte[] bytes); void sendPacket(byte[] bytes, int len); PcapStat getStats(); List<DataLinkType> listDatalinks(); String getError(); @Override void close(); @Override String toString(); static final Inet4Address PCAP_NETMASK_UNKNOWN; }
@Test public void testListDatalinks() throws Exception { List<DataLinkType> list = ph.listDatalinks(); assertNotNull(list); assertEquals(1, list.size()); assertEquals(DataLinkType.EN10MB, list.get(0)); }