pcap4j
pcap4j copied to clipboard
Having trouble retrieving package data
Hello, I am trying to capture and parse packets, for this I need to retrieve the metadata from them, however, no matter what layer types i put into get() function, i always get null.
Here is a snippet of my code:
while (handle.isOpen()) {
Packet packet;
try {
packet = handle.getNextPacketEx();
if (packet != null) {
UdpPacket udpPacket = packet.get(UdpPacket.class);
System.out.println(udpPacket);
}
} catch (EOFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Am I doing something wrong?
Same issue
Hey, I have forgotten to close the issue and write what helped me. Essentially, i have not understood at first that i need to add packet factories to class path separaterly. So the solution for me was the same as here https://github.com/kaitoy/pcap4j/issues/244
I my case I used gradle and all needed to do was to add packetfactories package to gradle dependencies. Hope this helps