问题描述
在运行这个从 pcaps 文件计算数据包的 java 代码期间。 :
// Counting the number of packets in pcap files.
// User defined package
//package jnt;
import java.io.File;
import org.jnetpcap.Pcap;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.JPacketHandler;
public class PacketCounter {
// Path of the folder having pcap files
// generated by Wireshark(change accordingly)
static String folderpath
= "./pcapfiles/";
static double count = 0;
static double globalcount = 0;
// main function starts here
public static void main(String[] args)
{
// Making the object of a file
// and giving that object address
// of the pcap folder
File file = new File(folderpath);
// Making file array which is used
// to access each file
// inside the folder one-by-one
File[] files = file.listFiles();
// Accessing each file
// one-by-one of files array
for (File f : files) {
// Getting each pcap file name
String FILENAME
= folderpath + f.getName();
// StringBuilder is used to get
// error messages in case
// if any error occurs
StringBuilder errbuf = new StringBuilder();
// Making Pcap object an opening pcap file
// in offline mode and passing pcap filename
// and StringBuilder object to the function
Pcap pcap = Pcap.openOffline(FILENAME,errbuf);
// Here pcap object is used to start a loop
// for capturing each packet of an
// each pcap file(as a pcap file can
// have many packets) one at a time,here -1
// indicates eof(end of file) i.e
// until every packet is captured execute the
// loop,we can also give some value
// instead of -1 which will indicate the
// number of packets to execute
// in each pcap file
pcap.loop(-1,new JPacketHandler() {
// nextPacket is override function
// of JPacketHandler( Handler which is
// use to receive fully decoded packets)
public void nextPacket(JPacket packet,StringBuilder errbuf)
{
// counter to count the number of packet
// in each pcap file
count++;
}
},errbuf);
System.out.println("File : " + f.getName()
+ " Number of Packets : "
+ count);
// Global counter to count the total number
// of packets in all pcap file
globalcount = globalcount + count;
count = 0;
}
System.out.println("Total Packets in folder : "
+ globalcount);
}
}
从https://www.geeksforgeeks.org/packet-capturing-using-jnetpcap-in-java/获取
Error showing in this image,also below.
javac -cp jnetpcap.jar PacketCounter.java
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
PacketCounter.java:64: error: <anonymous PacketCounter$1> is not abstract and does not override abstract method nextPacket(JPacket,Object) in JPacketHandler
pcap.loop(-1,new JPacketHandler() {
^
Note: PacketCounter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
请帮我运行这段代码。
操作系统:Kali linux
Java 版本:openjdk 11.0.11-ea 2021-04-20 OpenJDK 运行时环境(构建 11.0.11-ea+4-post-Debian-1) OpenJDK 64 位服务器 VM(构建 11.0.11-ea+4-post-Debian-1,混合模式,共享)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)