Hi - I'm having some difficulties migrating from Java 8 to Java 11 with jnetpcap. We have a test suite that I believe worked very reliable with Java 8, but going to Java 11 exhibits a lot of issues even in basic use-cases such as offline looping and counting how many packets were found:
@Test
public void test() {
AtomicInteger counter = new AtomicInteger(0);
PcapPacketHandler<String> packetHandler = new PcapPacketHandler<String>() {
@Override
public void nextPacket(final PcapPacket jPacket, final String o) {
counter.incrementAndGet();
}
};
StringBuilder errorBuffer = new StringBuilder();
final Pcap pcap = Pcap.openOffline("dumpcap.pcap", errorBuffer);
final int result = pcap.loop(5000, packetHandler, null);
pcap.close();
System.out.println("Result: " + result);
System.out.println("Counted packets: " + counter.get());
System.out.println(errorBuffer);
assertEquals(1289, counter.get());
}
The above code works sometimes, but sometimes it does not. Interestingly, if I put a loop around the entire test, if it works, it consistently keeps working for hundreds of iterations, if it is not working, it already fails during the first iteration. To me this indicates that something isn't loaded / setup properly initially. The test fails either because the counter is still 0, or (with later jnetpcap versions - see below) because the application just crashes with an output like the following:
Previously in Java 8 we were using the following dependency. I tried upgrading to the newer versions because our tests were unstable with this version in Java 11. The packet count often was 0 instead of the expected number:
Which version of jnetpcap is currently recommended when Java 11 is used?
Are there any known issues with Java 11 on Windows regarding packet filtering?
How can I debug this issue further?
Update
It seems the nextEx(...) API doesn't suffer from the same issues as the pcapLoop(...) API. E.g. using the old library version 1.4.r1425-1e I can successfully read all packets using the nextEx-API even with Java 11. I assume, that I can't use the nextEx API for live capturing / filtering though, correct?
Hi - I'm having some difficulties migrating from Java 8 to Java 11 with jnetpcap. We have a test suite that I believe worked very reliable with Java 8, but going to Java 11 exhibits a lot of issues even in basic use-cases such as offline looping and counting how many packets were found:
The above code works sometimes, but sometimes it does not. Interestingly, if I put a loop around the entire test, if it works, it consistently keeps working for hundreds of iterations, if it is not working, it already fails during the first iteration. To me this indicates that something isn't loaded / setup properly initially. The test fails either because the counter is still 0, or (with later jnetpcap versions - see below) because the application just crashes with an output like the following:
I'm currently trying with the following dependency on Windows 10 amd64:
Previously in Java 8 we were using the following dependency. I tried upgrading to the newer versions because our tests were unstable with this version in Java 11. The packet count often was 0 instead of the expected number:
Update It seems the
nextEx(...)
API doesn't suffer from the same issues as thepcapLoop(...)
API. E.g. using the old library version 1.4.r1425-1e I can successfully read all packets using thenextEx
-API even with Java 11. I assume, that I can't use thenextEx
API for live capturing / filtering though, correct?Update2
nextEx(...)
API indeed works fine and also works for live capturing / filtering. See a sample here: https://stackoverflow.com/a/76572647/606513