### Question:
PcapHandle { public void setDirection(PcapDirection direction) throws PcapNativeException, NotOpenException { if (direction == null) { throw new NullPointerException("direction must not be null."); } if (!open) { throw new NotOpenException(); } if (!handleLock.readLock().tryLock()) { throw new NotOpenException(); } try { if (!open) { throw new NotOpenException(); } int rc = NativeMappings.pcap_setdirection(handle, direction.getValue()); if (rc < 0) { throw new PcapNativeException("Failed to set direction: " + getError(), rc); } } finally { handleLock.readLock().unlock(); } } 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); PcapStat getStats(); List<DataLinkType> listDatalinks(); String getError(); void close(); @Override String toString(); static final Inet4Address PCAP_NETMASK_UNKNOWN; }### Answer:
@Test public void testSetDirection() throws Exception { if (System.getenv("TRAVIS") != null) { PcapNetworkInterface nif = Pcaps.getDevByName("any"); PcapHandle handle = nif.openLive(65536, PromiscuousMode.PROMISCUOUS, 10); handle.setDirection(PcapDirection.OUT); handle.setFilter("icmp", BpfCompileMode.OPTIMIZE); ProcessBuilder pb = new ProcessBuilder("/bin/ping", "www.google.com"); Process process = pb.start(); final List<Packet> packets = new ArrayList<Packet>(); handle.loop(3, new PacketListener() { @Override public void gotPacket(Packet packet) { packets.add(packet); } }); handle.close(); process.destroy(); assertEquals(3, packets.size()); assertTrue(packets.get(0).contains(IcmpV4EchoPacket.class)); assertTrue(packets.get(1).contains(IcmpV4EchoPacket.class)); assertTrue(packets.get(2).contains(IcmpV4EchoPacket.class)); } else { try { ph.setDirection(PcapDirection.OUT); fail(); } catch (PcapNativeException e) { assertTrue(e.getMessage().startsWith("Failed to set direction:")); } } }