Since updating from r795, I am now getting an exception when scanning a packet created with JMemoryPacket(byte[]).
Exception in thread "Thread-16" java.lang.IllegalArgumentException: wirelen < buffer len
at org.jnetpcap.packet.JScanner.scan(Native Method)
at org.jnetpcap.packet.JScanner.scan(JScanner.java:357)
at org.jnetpcap.packet.JScanner.scan(JScanner.java:335)
The problem appears that scan now expects that the "wirelen" of the packet to have been set. I do not see a way to specify the wire length of the packet, either from the constructor or from a setter.
Looking at the two forms of the JMemoryPacket constructors, JMemoryPacket(byte[] buffer) and JMemoryPacket(int id, byte[] buffer), the later is setting "wirelen" [header.setWirelen(buffer.length);]. Is that line simply missing from the other constructor?
Yes, wirelen was supposed to be set by the constructor. Looking at the other constructors, several others are missing that line as well.
You can set it manually though using JMemoryPacket.getCaptureHeader().setWirelen(int).
The string of relatively small bugs we've been discovering stems from the changes made to native scanner. The scanner was changed to take into accout:
[pre][header][gap][payload][post]
for every single header. Before it was simply
[header]
The expanded structure maintains all of these properties (lengths in implementation) for every header. The calculation must take into account "wirelen" or the length of the entire packet before libpcap/kernel/bpf did any truncation to it.
No good deed goes unpunished.
Fix is official checked in for this (Bug#2828030).
I'm not sure if you noticed, but I started creating a jUnit testcase for every bug reported in the tests/ source tree. This will allow a before and after view of the bug. It will also ensure that that any bug already fixed does not resurface. Also adds a bunch of new jUnit test cases that always stress something new. Can never have enough of those:
http://jnetpcap.svn.sourceforge.net/viewvc/jnetpcap/jnetpcap/trunk/tests...
There is a test suite setup to run them all and its a nice thing to have part of the release/build process.