Packet Decoding

java.lang.NullPointerException: jmemory not initialized

I'm using jnetpcap1.2rc5 on a windows platform with Java 6 update 17

I'm writing a capture application to read offline captures that I've captured using jnetpcap on a seperate application. When loading the saved capture file i read the packets from the file as follows

/* capture packets using the Pcap object and pass to the packet capturer */
result = pCapturer.dispatch(100, bufHandler, "PacketCapturer");

and the code is packet is processed by the JBufferHandler

In the nextPacket method I scan for Ethernet and check if the packet is an IP packet with

public void nextPacket( PcapHeader pheader, JBuffer jbuffer, String t ){
/* scan the packet to determine what data it contains */
pkt.scan( Ethernet.ID );

/* check if it is an IP packet */
if ( pkt.hasHeader( ip ) ) {

When i try to get a value from the last captured packet i get the exception

Exception in thread "Thread-4" java.lang.NullPointerException: jmemory not initialized
at org.jnetpcap.nio.JMemory.size(

I'm at a loss to understand why this happens and why only on the last captured packet. By using pkt.hasHeader(ip), doesnt the IP data get scanned and decoded? and shouldn't it be available for reading right away?

Any help in understanding this would be appreciated.


About read Audio from capture file

Hi All!!

i was looking for the Trhead, and i try to use the code showed there but unsucessfuly.. the program read the flows and make the "AU" files, but there are not audible ... y decode wih wireshark and i cant to get the audio file..

u cant help me to idetify what im doing wrong?

thank u Smile

This is my code...

package com.tpmex.jsniffer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapBpfProgram;
import org.jnetpcap.PcapTask;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.JRegistry;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.PcapPacketHandler;
import org.jnetpcap.protocol.voip.Rtp;
import org.jnetpcap.protocol.voip.Sdp;
import org.jnetpcap.protocol.voip.Sip;

import org.jnetpcap.protocol.voip.SipHandler;

 * @author Mark Bednarczyk
 * @author Sly Technologies, Inc.
public class decode    {

public static void main(String[] args) {
        try {
            new decode().SKIP_testRtpAudioExtract();
        } catch (IOException ex) {
            Logger.getLogger(decode.class.getName()).log(Level.SEVERE, null, ex);

public static Iterable getIterable(final String file) {
		return new Iterable() {

			public Iterator iterator() {
				return getPcapPacketIterator(file, 0, Integer.MAX_VALUE);


	public static Iterator getPcapPacketIterator(final String file,
			final int start, final int end) {
		return getPcapPacketIterator(file, start, end, null);

Decoded .au file from undecoded Rtp Packets getPayload()


I followed the below discussion

I got .au file but its not playing in Windows media player.
I know that getPayload() method will return undecoded packets, how to decode that packet and how will get ".au" audio file from that Payload raw data.

Can you please help me for the same.


How to decode undecoded packet which we get from getPayload method from PcapPacket?


How to decode and get the .au audio file from undecoded packtes which i got from getPayload() method.


New to packet capture analysis


I am new to packet capturing and analysis and I am trying to use jnetpcap libraries with java code to open file.pcap which was captures by wire shark.

I used the code below, but I don't think that I am on the right track. My requirement is to load the pcap file and convert it to byte[].

      System.out.println("In MAIN");
        StringBuilder sb = new StringBuilder();

        int snaplen = 64 * 1024;           // Capture all packets, no trucation
        int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
        int timeout = 10 * 1000;           // 10 seconds in millis

        Pcap pcap=null;

        try {
            pcap = Pcap.openOffline("C:\\myFile.pcap", sb);

        } catch (Exception e) {
        System.out.println("After pcap openOffline");

        if (pcap == null) {
            System.out.println("pcap == null");
        System.out.println("pcap.src: " + sb.toString());

Any help will be appreciated and I will continue to look through the tutorials.