API

Conversations

Hi,
how do i get the wireshark conversations using jNetPcap for both TCP and UDP...?

can anyone help me out..!

Thanks!

JBufferHandler and loopInBackground

I am planning to use jnetpcap-1.3 to sniff packets on the machine. My requirement is to sniff all packets and store some meta-data about each packet in the database for further processing.

I picked up the Classic example which works. I want to loop in background so using PcapUtils.loopInBackground and since it uses JBufferHandler, I provided one but it never enters the nextPacket method.

My commented code works but since the pcap.loop() method is a blocking method it does not suit my requirement as I am listening on all the devices of the machine.

    public static void main(final String[] args) throws InterruptedException {
        List alldevs = new ArrayList();
        StringBuilder errbuf = new StringBuilder();

        int findStatus = Pcap.findAllDevs(alldevs, errbuf);
        for (PcapIf device : alldevs) {
            Pcap pcap = Pcap.openLive(device.getName(), 64 * 1024, Pcap.MODE_PROMISCUOUS, 10000, errbuf);

            /**PcapPacketHandler jpacketHandler = new PcapPacketHandler() {
                public void nextPacket(final PcapPacket packet, final String message) {
                    System.out.println("reached here");
                }
            };
            pcap.loop(-1, jpacketHandler, null);*/

            JBufferHandler jBufferHandler = new JBufferHandler() {
                public void nextPacket(final PcapHeader header, final JBuffer buffer, final String message) {
                    System.out.println("reached here");
                }
            };

            PcapUtils.loopInBackground(pcap, -1, jBufferHandler, null);
        }
    }

Got NullPointerException when coping a packet

I'm using JnetPcap ver 1.3. The jar file was downloaded from the download page, native libs were recompiled locally.

My nextPacket implementation contains new packet allocation and copy of recieved buffer into the new allocated memory.

While transferFrom I get NullPointerException, without stack trace. At Eclipse, the stack is:
NullPointerException.(String) line: 63
JMemory.transferTo(JMemory, int, int, int) line: not available [native method]
PcapPacket(JMemory).transferTo(JMemory) line: not available
PcapPacket(JBuffer).transferTo(JBuffer) line: not available
PcapPacket(JBuffer).transferFrom(JBuffer) line: not available
AgentBasePacketsListener.nextPacket(JPacket, PrintStream) line: 1693

The code is:
@Override
public void nextPacket(JPacket packet, PrintStream user) {
JPacket jbuf = new PcapPacket(packet.getTotalSize());
jbuf.transferFrom(packet);
statistics.incReceivedAddCount();
for (AgentBasePacketHandlerManager handler :agentPacketHandlers.values()) {
if (handler != null) {
if (handler.passPacket(packet) == true) {
statistics.incHandledOKCount();
}
else {
statistics.incHandledIgnoreCount();
}
}
else {
statistics.incReceivedIgnoreCount();
}
}
}