Recently, I'm using Jnetpcap to send/receive raw packet over network.
Jnetpcap provides sending packets by Pcap.sendPacket()
. This method gets raw buffer or bytes to send.
On the other hand, there is org.jnetpcap.protocol.*
classes which wraps protocol headers, and we can use them to decode captured packets.
When I use below code to make a Ip4
packet, It causes NullPointerException:
import org.jnetpcap.protocol.network.Ip4;
public class Test {
public static void main(String[] args) {
Ip4 ip4 = new Ip4();
ip4.ttl(10);
}
}
Error:
Exception in thread "main" java.lang.NullPointerException
at org.jnetpcap.nio.JBuffer.check(Unknown Source)
at org.jnetpcap.nio.JBuffer.setUByte(Unknown Source)
at org.jnetpcap.protocol.network.Ip4.ttl(Unknown Source)
at jaeger.Test.main(Test.java:17)
How can I build that packet and then send it by Pcap.sendPacket()
?
Note: I'm really not interested in preparing packets byte by byte... C/C++ libpcap and Jpcap have working functionality, but I want use Jnetpcap!