Trying to send an ARP(Address Resolution Protocol) Message with Socket

S

Shoveler

I'm trying to send an ARP to determine different devices on the
network. I need to see the MAC address of my devices on my LAN. With
the MAC I can determine if I need to talk to that devices. I figured
the ARP is the best we to find who is out there. I'm using C# and the
Raw SocketType. I run into the WSACancelBlockingCall problem. Here's
my code:

Socket MyPing = new Socket(AddressFamily.InterNetwork,
SocketType.Raw , ProtocolType.IP );

MyPing.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, true);

byte[] DataARP = new byte[] { 00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00,
0x01, 0x00, 0x13, 0x8f, 0x88, 0xe1, 0x51, 0xc0, 0xa8, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x00, 0x0a };

//Fake an IP Address so I can send with SendTo
IPAddress IP = new IPAddress(new byte[] { 192, 168, 1, 1
});
IPEndPoint IPEP = new IPEndPoint(IP, 5931);

//Local IP for Receiving
IPEndPoint Local = new IPEndPoint(IPAddress.Any, 0);
EndPoint EP = (EndPoint)Local;

MyPing.SendTo(DataARP, IPEP);





It's a very simple app. All I want to do is send data only with the
Eithernet II Header. I figured I need a Raw socket, but it's canceling
my sending. I'm debuging with Ethereal.
 
T

Tom Shelton

Shoveler said:
I'm trying to send an ARP to determine different devices on the
network. I need to see the MAC address of my devices on my LAN. With
the MAC I can determine if I need to talk to that devices. I figured
the ARP is the best we to find who is out there. I'm using C# and the
Raw SocketType. I run into the WSACancelBlockingCall problem. Here's
my code:

Socket MyPing = new Socket(AddressFamily.InterNetwork,
SocketType.Raw , ProtocolType.IP );

MyPing.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, true);

byte[] DataARP = new byte[] { 00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00,
0x01, 0x00, 0x13, 0x8f, 0x88, 0xe1, 0x51, 0xc0, 0xa8, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x00, 0x0a };

//Fake an IP Address so I can send with SendTo
IPAddress IP = new IPAddress(new byte[] { 192, 168, 1, 1
});
IPEndPoint IPEP = new IPEndPoint(IP, 5931);

//Local IP for Receiving
IPEndPoint Local = new IPEndPoint(IPAddress.Any, 0);
EndPoint EP = (EndPoint)Local;

MyPing.SendTo(DataARP, IPEP);





It's a very simple app. All I want to do is send data only with the
Eithernet II Header. I figured I need a Raw socket, but it's canceling
my sending. I'm debuging with Ethereal.

I'm no expert on raw sockets - I've never used them... But, didn't xp sp2
remove (or severly) limit access to raw sockets? Assuming your doing this
on an XP SP2 box :)
 
M

Markus Stoeger

Shoveler said:
I figured the ARP is the best we to find who is out there.

Have you considered sending a UDP broadcast to which your devices send a
reply?

hth,
Max
 
S

Shoveler

Markus said:
Have you considered sending a UDP broadcast to which your devices send a
reply?

hth,
Max

The devices I need to talk with do use UDP for communication, but I'd
rather try to find it by his MAC Address. If there's any other way to
retrieve the MAC within C#, I'm all ears. Is there a way to access the
ARP Cache in the system?
 
S

Shoveler

I'm no expert on raw sockets - I've never used them... But, didn't xp sp2
remove (or severly) limit access to raw sockets? Assuming your doing this
on an XP SP2 box :)

Yup, I'm using WinXP with SP2. I'm using C# 2005 Express Edition. I
was wondering if I upgraded to the Pro, I would be able to use all
Socket functions?
 
T

Tom Shelton

Shoveler said:
Yup, I'm using WinXP with SP2. I'm using C# 2005 Express Edition. I
was wondering if I upgraded to the Pro, I would be able to use all
Socket functions?

If you are indeed running into the XPSP2 raw socket limitations, then
upgrading to Pro won't help. This is a limitation of the OS. One way to
test is to try on a pre sp2 XP box.
 
S

Shoveler

Thanks for the info guys!

I'm already running XP Pro, I was thinking about the C#2005 Pro, but
the OS still limits it. I've downloaded a C# converted app of WinPcap.
It works great for downloading entire packets, so I now have access to
the MAC Address of each device on the LAN that sends a message. I
really don't need to send ARP commands, I'll just let to OS do it when
I ping.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top