@Test public void testSendPacket() throws Exception { if (System.getenv("TRAVIS") != null) { PcapNetworkInterface nif = Pcaps.getDevByName("lo"); final PcapHandle handle = nif.openLive(65536, PromiscuousMode.PROMISCUOUS, 10); byte[] sendingRawPacket = new byte[50]; sendingRawPacket[0] = 1; sendingRawPacket[1] = 2; sendingRawPacket[2] = 3; sendingRawPacket[3] = 4; sendingRawPacket[4] = 5; Packet sendingPacket = UnknownPacket.newPacket(sendingRawPacket, 0, sendingRawPacket.length); ExecutorService pool = Executors.newSingleThreadExecutor(); final byte[] result = new byte[sendingRawPacket.length]; final FutureTask<byte[]> future = new FutureTask<byte[]>( new Runnable() { @Override public void run() {} }, result); pool.execute( new Runnable() { @Override public void run() { try { handle.loop( -1, new RawPacketListener() { @Override public void gotPacket(byte[] p) { if (p[0] == 1 && p[1] == 2 && p[2] == 3 && p[3] == 4 && p[4] == 5) { assertEquals(result.length, p.length); System.arraycopy(p, 0, result, 0, result.length); future.run(); } } }); } catch (PcapNativeException e) { } catch (InterruptedException e) { } catch (NotOpenException e) { } } }); Thread.sleep(1000); handle.sendPacket(sendingPacket); future.get(5, TimeUnit.SECONDS); handle.breakLoop(); handle.close(); assertArrayEquals(sendingRawPacket, result); } }
public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException { if (packet == null) { throw new NullPointerException("packet may not be null"); } sendPacket(packet.getRawData()); }
PcapHandle implements Closeable { public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException { if (packet == null) { throw new NullPointerException("packet may not be null"); } sendPacket(packet.getRawData()); } }
PcapHandle implements Closeable { public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException { if (packet == null) { throw new NullPointerException("packet may not be null"); } sendPacket(packet.getRawData()); } PcapHandle(Pointer handle, TimestampPrecision timestampPrecision); private  PcapHandle(Builder builder); }
PcapHandle implements Closeable { public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException { if (packet == null) { throw new NullPointerException("packet may not be null"); } sendPacket(packet.getRawData()); } 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(); }
PcapHandle implements Closeable { public void sendPacket(Packet packet) throws PcapNativeException, NotOpenException { if (packet == null) { throw new NullPointerException("packet may not be null"); } sendPacket(packet.getRawData()); } 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; }