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(); static List<PcapNetworkInterface> findAllDevs(); static PcapNetworkInterface getDevByAddress(InetAddress addr); static PcapNetworkInterface getDevByName(String name); static String lookupDev(); static Inet4NetworkAddress lookupNet(String devName); static PcapHandle openOffline(String filePath); static PcapHandle openOffline(String filePath, TimestampPrecision precision); static PcapHandle openDead(DataLinkType dlt, int snaplen); static PcapHandle openDead(DataLinkType dlt, int snaplen, TimestampPrecision precision); static BpfProgram compileFilter(
      int snaplen,
      DataLinkType dlt,
      String bpfExpression,
      BpfCompileMode mode,
      Inet4Address netmask); static DataLinkType dataLinkNameToVal(String name); static String dataLinkTypeToName(DataLinkType dlt); static String dataLinkValToName(int dataLinkVal); static String dataLinkTypeToDescription(DataLinkType dlt); static String dataLinkValToDescription(int dataLinkVal); static String strError(int error); static String libVersion(); static String toBpfString(InetAddress inetAddr); static String toBpfString(MacAddress macAddr);  }
@Test public void testFindAllDevs() throws Exception { List<PcapNetworkInterface> devs = Pcaps.findAllDevs(); assertNotNull(devs); assertTrue(devs.size() != 0 || !System.getProperty("user.name").equals("root")); for (PcapNetworkInterface dev : devs) { logger.info(dev.toString()); } }