I am trying to write a packet sniffer in Java using an old tutorial I found online but having trouble debugging. I am getting an error stating my class pktSniffer is not inheriting an abstract method.
import jpcap.*;
import jpcap.packet.Packet;
import jpcap.PacketReceiver;
public class pktSniffer implements Pa开发者_高级运维cketReceiver {
public void handlePacket(Packet packet){
System.out.println(packet);
}
public static void main(String[] args) throws java.io.IOException{
NetworkInterface[] lists=jpcap.JpcapCaptor.getDeviceList();
System.out.println("\n\t\t***Network Sniffer***\n");
System.out.println("Found the following devices : ");
for(NetworkInterface s: lists)
{
System.out.println("Name: " + s.name +" Description: " + s.description);
}
JpcapCaptor jpcap=JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[1],1000,false,20);
jpcap.loopPacket(-1,new pktSniffer());
}
}
not inheriting an abstract method
Are you sure that the error wasn't that you are not implementing an abstact method?
According to:
- http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/javadoc/jpcap/PacketReceiver.html
and
- http://code.google.com/p/jdc-client/source/browse/trunk/JDC-Client+1.0/src/jpcap/PacketReceiver.java?r=8
your method should be called receivePacket
instead of handlePacket
精彩评论