pcap4j icon indicating copy to clipboard operation
pcap4j copied to clipboard

Having trouble retrieving package data

Open ogozman opened this issue 2 years ago • 2 comments

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?

ogozman avatar Apr 17 '23 10:04 ogozman

Same issue

FKammerer45 avatar Jul 17 '23 10:07 FKammerer45

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

ogozman avatar Jul 17 '23 12:07 ogozman