我在Ubuntu 16.04 X86上使用Jpcap ver.0.7(Keita Fujii)库,并且尝试使用getTCPData()提取数据包有效载荷数据,但是该方法丢失了。

这是我的代码

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);

    }
}
}


任何帮助,将不胜感激。

最佳答案

实际上,有两个名称相同的类似项目:


Jpcap by藤田圭太
Sourceforge上的JPcap


它们是独立开发的,而我正在使用第一个,这就是缺少此方法的原因。
 Sourceforge上的Jpcap具有更多功能。

09-26 18:16