Question

How do i wait for a specific type of packet (ICMP echo request) through JPCAP. I use the following code to listen for arriving packets :

PacketCapture m_pcap = new PacketCapture();
m_pcap.open("\\Device\\NPF_{007262BD-....-7EE83D72EBEA}", true);
m_pcap.setFilter("proto ICMP", true);
m_pcap.addPacketListener(new PacketHandler());//PacketHandler just displays the packet contents
m_pcap.capture(-1);

Now since m_pcap.capture(-1) is used, capture will block forever. What i want is that it should wait till an ICMP echo request message is recieved from a specific IP address and then the blocking should end.

Was it helpful?

Solution

So, i found a solution for the problem. I can just call m_pcap.endCapture(); method to end the blocking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top