@Test
public void testSetDirection() throws Exception {

  if (System.getenv("TRAVIS") != null) {
    // run only on Travis CI
    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:"));
    }
  }
}