6

I am trying unsuccessfully so far to send an ARP packet I have created with Packet.Net using SharpPcap. The problem is even though I send the packet using device.SendPacket it doesn't actually get sent, and I have no idea why.

This is my code:

ARPPacket arpPacket = new ARPPacket(ARPOperation.Request, PhysicalAddress.Parse("000000000000"), targetIpAddress, device.Interface.MacAddress, myIpAddress);
EthernetPacket ethPacket = new EthernetPacket(device.Interface.MacAddress, PhysicalAddress.Parse("FFFFFFFFFFFF"), EthernetPacketType.Arp);
ethPacket.PayloadPacket = arpPacket;
device.Open();
device.SendPacket(ethPacket);
device.Close();

By the way, it is important that I send my own ARP packets and not just use the SharpPcap ARP class.

Cokegod
  • 8,256
  • 10
  • 29
  • 47
  • Have you used Wireshark on the sending computer to see what packet is being sent? Have you tried using Pcap.Net (if not, why did you tag this question with Pcap.Net)? – brickner Jan 05 '13 at 08:39
  • Yes I have used Wireshark and filtering for 'arp' I didn't find my packet. The Pcap.Net tag was by mistake (meant it to be a Packet.Net tag, changed it now), and if I won't find a solution I will use Pcap.Net, but I like Packet.Net and SharpPcap much more. – Cokegod Jan 06 '13 at 17:05

2 Answers2

5
public static void ARP(IPAddress ipAddress , LivePcapDevice device)
{
if (ipAddress == null )
throw new Exception("ARP IP address Cannot be null");
var ethernetPacket = new PacketDotNet.EthernetPacket(device.Addresses[1].Addr.hardwareAddress, PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF"), PacketDotNet.EthernetPacketType.Arp);

var arpPacket = new PacketDotNet.ARPPacket(PacketDotNet.ARPOperation.Request, PhysicalAddress.Parse("00-00-00-00-00-00"), ipAddress , device.Addresses[1].Addr.hardwareAddress, device.Addresses[0].Addr.ipAddress );
ethernetPacket.PayloadPacket = arpPacket;

device.SendPacket(ethernetPacket);
}

Try this function, from: http://stolenpackets.net/?p=29

Vahid Farahmand
  • 2,528
  • 2
  • 14
  • 20
  • WOW! I almost gave up on using SharpPcap but this actually works! Although I have no idea why this code works and mine doesn't, but I will look into that. Anyway, thanks a lot! – Cokegod Jan 26 '13 at 23:13
  • PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF") was the missing magic – Jon Canning Jan 12 '23 at 22:11
2

looking at this code there is no ethernetpacket involved

ARPPacket arpPacket = new ARPPacket(ARPOperation.Request, PhysicalAddress.Parse("000000000000"), targetIpAddress, device.Interface.MacAddress, myIpAddress);
arpPacket.ARPTargetProtoAddress = destIP;
arpPacket.DestinationHwAddress = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
device.Open();
device.SendPacket(arpPacket);
device.Close();
Firo
  • 30,626
  • 4
  • 55
  • 94
  • Tells me that "'PacketDotNet.ARPPacket' does not contain a definition for 'ARPTargetProtoAddress'" and same with 'DestinationHwAddress'. Probably because the code in your link is from SharpPcap version 2.1.2 while I am using the latest version which is 4.1.0. – Cokegod Jan 13 '13 at 20:11