javanetwork-programmingubuntu-16.04jpcapnetbeans-8.1

JPCAP: Trying to extract the payload data but getTCPData() method is missing


I'm using Jpcap ver.0.7 (Keita Fujii) library on Ubuntu 16.04 X86 and I'm trying to extract packet payload data using getTCPData() but the method is missing.

This is my code

import java.io.BufferedOutputStream;
import jpcap.PacketReceiver;
import jpcap.packet.ICMPPacket;
import jpcap.packet.IPPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;
import jpcap.packet.UDPPacket;

class PacketPrinter implements PacketReceiver, PacketListener {
    //this method is called every time Jpcap captures a packet


@Override
public void receivePacket(Packet packet) {
    if (packet instanceof TCPPacket) {
        TCPPacket pac = (TCPPacket) packet;
        byte[] data;
        data = pac.getTCPData();

        System.out.println("TCP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip + " dest port : " + pac.dst_port + " src port : " + pac.src_port);

    } else if (packet instanceof UDPPacket) {
        UDPPacket pac = (UDPPacket) packet;
        pac.
        System.out.println("UDP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip + " dest port : " + pac.dst_port + " src port : " + pac.src_port);

    } else if (packet instanceof ICMPPacket) {
        ICMPPacket pac = (ICMPPacket) packet;
        System.out.println("ICMP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip);

    } else if (packet instanceof IPPacket) {
        IPPacket pac = (IPPacket) packet;
        System.out.println("IP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip);

    }
}
}

Any help would be appreciated.


Solution

  • Actually there are two similar projects with the same name:

    They are independently developed and I'm using the first one ,that's why this method is missing. Jpcap on sourceforge has more features.