@Test public void testOpenLive() throws Exception { PcapHandle handle; try { handle = Pcaps.findAllDevs().get(0).openLive(55555, PromiscuousMode.PROMISCUOUS, 100); } catch (IndexOutOfBoundsException e) { return; } catch (PcapNativeException e) { assertTrue( "The exception should complain about permission to capture.", e.getMessage().contains("You don't have permission to capture on that device")); return; } assertNotNull(handle); assertTrue(handle.isOpen()); logger.info(handle.toString()); }
public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis) throws PcapNativeException { if (mode == null) { StringBuilder sb = new StringBuilder(); sb.append("mode: ").append(mode); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); Pointer handle = NativeMappings.pcap_open_live(name, snaplen, mode.getValue(), timeoutMillis, errbuf); if (handle == null || errbuf.length() != 0) { throw new PcapNativeException(errbuf.toString()); } if (timeoutMillis == 0 && Platform.isSolaris()) { timeval to = new timeval(); to.tv_sec = new NativeLong(0); to.tv_usec = new NativeLong(0); int rc = PcapLibrary.INSTANCE.strioctl( NativeMappings.getFdFromPcapT(handle), NativeMappings.SBIOCSTIME, to.size(), to.getPointer()); if (rc < 0) { throw new PcapNativeException( "SBIOCSTIME: " + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0)); } } return new PcapHandle(handle, TimestampPrecision.MICRO); }
PcapNetworkInterface { public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis) throws PcapNativeException { if (mode == null) { StringBuilder sb = new StringBuilder(); sb.append("mode: ").append(mode); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); Pointer handle = NativeMappings.pcap_open_live(name, snaplen, mode.getValue(), timeoutMillis, errbuf); if (handle == null || errbuf.length() != 0) { throw new PcapNativeException(errbuf.toString()); } if (timeoutMillis == 0 && Platform.isSolaris()) { timeval to = new timeval(); to.tv_sec = new NativeLong(0); to.tv_usec = new NativeLong(0); int rc = PcapLibrary.INSTANCE.strioctl( NativeMappings.getFdFromPcapT(handle), NativeMappings.SBIOCSTIME, to.size(), to.getPointer()); if (rc < 0) { throw new PcapNativeException( "SBIOCSTIME: " + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0)); } } return new PcapHandle(handle, TimestampPrecision.MICRO); } }
PcapNetworkInterface { public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis) throws PcapNativeException { if (mode == null) { StringBuilder sb = new StringBuilder(); sb.append("mode: ").append(mode); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); Pointer handle = NativeMappings.pcap_open_live(name, snaplen, mode.getValue(), timeoutMillis, errbuf); if (handle == null || errbuf.length() != 0) { throw new PcapNativeException(errbuf.toString()); } if (timeoutMillis == 0 && Platform.isSolaris()) { timeval to = new timeval(); to.tv_sec = new NativeLong(0); to.tv_usec = new NativeLong(0); int rc = PcapLibrary.INSTANCE.strioctl( NativeMappings.getFdFromPcapT(handle), NativeMappings.SBIOCSTIME, to.size(), to.getPointer()); if (rc < 0) { throw new PcapNativeException( "SBIOCSTIME: " + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0)); } } return new PcapHandle(handle, TimestampPrecision.MICRO); } private  PcapNetworkInterface(pcap_if pif, boolean local); }
PcapNetworkInterface { public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis) throws PcapNativeException { if (mode == null) { StringBuilder sb = new StringBuilder(); sb.append("mode: ").append(mode); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); Pointer handle = NativeMappings.pcap_open_live(name, snaplen, mode.getValue(), timeoutMillis, errbuf); if (handle == null || errbuf.length() != 0) { throw new PcapNativeException(errbuf.toString()); } if (timeoutMillis == 0 && Platform.isSolaris()) { timeval to = new timeval(); to.tv_sec = new NativeLong(0); to.tv_usec = new NativeLong(0); int rc = PcapLibrary.INSTANCE.strioctl( NativeMappings.getFdFromPcapT(handle), NativeMappings.SBIOCSTIME, to.size(), to.getPointer()); if (rc < 0) { throw new PcapNativeException( "SBIOCSTIME: " + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0)); } } return new PcapHandle(handle, TimestampPrecision.MICRO); } private  PcapNetworkInterface(pcap_if pif, boolean local); String getName(); String getDescription(); List<PcapAddress> getAddresses(); ArrayList<LinkLayerAddress> getLinkLayerAddresses(); boolean isLoopBack(); boolean isUp(); boolean isRunning(); boolean isLocal(); PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
PcapNetworkInterface { public PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis) throws PcapNativeException { if (mode == null) { StringBuilder sb = new StringBuilder(); sb.append("mode: ").append(mode); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); Pointer handle = NativeMappings.pcap_open_live(name, snaplen, mode.getValue(), timeoutMillis, errbuf); if (handle == null || errbuf.length() != 0) { throw new PcapNativeException(errbuf.toString()); } if (timeoutMillis == 0 && Platform.isSolaris()) { timeval to = new timeval(); to.tv_sec = new NativeLong(0); to.tv_usec = new NativeLong(0); int rc = PcapLibrary.INSTANCE.strioctl( NativeMappings.getFdFromPcapT(handle), NativeMappings.SBIOCSTIME, to.size(), to.getPointer()); if (rc < 0) { throw new PcapNativeException( "SBIOCSTIME: " + NativeMappings.pcap_strerror(NativeMappings.ERRNO_P.getInt(0)).getString(0)); } } return new PcapHandle(handle, TimestampPrecision.MICRO); } private  PcapNetworkInterface(pcap_if pif, boolean local); String getName(); String getDescription(); List<PcapAddress> getAddresses(); ArrayList<LinkLayerAddress> getLinkLayerAddresses(); boolean isLoopBack(); boolean isUp(); boolean isRunning(); boolean isLocal(); PcapHandle openLive(int snaplen, PromiscuousMode mode, int timeoutMillis); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }