This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Wireshark : Ping using Jpcap

0

Hello All,

I made a basic program in java using Jpcap to ping a machine. However the problem is whenever I ping using Win 7 command prompt, it returns a ping reply. However using Jpcap, it doesn't send a reply to my ping request. However I came across a strange situation. On the other machine, which I am pinging, If I open a Wireshark console and monitor the packets, it shows a ICMP request and sends a reply then. However this is not working again if I close the wireshark !!

What is the problem here ?? Is it with some Win 7 firewall or some other issues ?

I have attached the code below :

JpcapSender sender=JpcapSender.openDevice(devices[index]);

ICMPPacket p=new ICMPPacket(); p.type=ICMPPacket.ICMP_ECHO; p.seq=1000; p.id=999; p.orig_timestamp=123; p.trans_timestamp=456; p.recv_timestamp=789; p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,1010101,100,IPPacket.IPPROTO_ICMP, InetAddress.getByName("192.168.101.18"),InetAddress.getByName("192.168.101.4")); p.data="data".getBytes();

EthernetPacket ether=new EthernetPacket(); ether.frametype=EthernetPacket.ETHERTYPE_IP; ether.src_mac=new byte[]{(byte)00,(byte)26,(byte)18,(byte)00,(byte)25,(byte)65};
ether.dst_mac=new byte[]{(byte)90,(byte)230,(byte)186,(byte)60,(byte)205,(byte)90}; p.datalink=ether;

//for(int i=0;i<10;i++) sender.sendPacket(p);

}

asked 24 Aug ‘12, 02:58

Somnath%20Paul's gravatar image

Somnath Paul
1111
accept rate: 0%


One Answer:

0

This question is not really related to Wireshark. I suggest:

If I open a Wireshark console and monitor the packets, it shows a ICMP request and sends a reply then. However this is not working again if I close the wireshark !!

IF this happens on the client (where your Jpcap code runs), I guess that you just loaded the WinPcap driver when you started Wireshark and that's the reason why it then works. In that case it's a WinPcap issue and you need to figure out why the Winpcap driver is not running per default.

http://www.winpcap.org/misc/faq.htm

You should also add some error detection code, to detect these kind of situations, when Jpcap is not able to receive/send packets.

Regards
Kurt

answered 24 Aug '12, 04:13

Kurt%20Knochner's gravatar image

Kurt Knochner ♦
24.8k1039237
accept rate: 15%

edited 24 Aug '12, 04:24