Solved

Need to get the MAC address of a peer from a socket (Win32)

Posted on 2012-03-11
4
1,131 Views
Last Modified: 2012-03-12
I need to determine the MAC address that a UDP socket packet came in from. I don't care if it came across a router and the MAC address is the router. I cannot wait until later (and use ARP, for example), and I cannot use the IP address. This is a custom DHCP server on a Win32 client (not the built-in DHCP server on Windows' server OS's), so the peers will all be using 0.0.0.0 and multiple ones may be connecting at the same time, so when I respond by giving them an IP address to use, I will need to know who I was talking to.

Also, I want to be able to support IP address reservations. That means I need the MAC address of the peer before I even respond, and again, there might be different clients all at the same time (each with its own socket), so this needs to be based on the socket.

Everything I've found talks about getting the local MAC address, which doesn't help, or using WMI or ARP, which doesn't help.

I can assume Ethernet.

Any help is greatly appreciated. Thanks.
0
Comment
Question by:spongyryno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 37709126
You need raw sockets for this, and you look in the L2 layer and in the dhcp request it has the MAC address in it already. http://www.tcpipguide.com/free/t_DataLinkLayerLayer2.htm
0
 
LVL 40

Expert Comment

by:noci
ID: 37709163
winpcap might be a usable tool.
http://www.winpcap.org/install/default.htm
0
 
LVL 36

Accepted Solution

by:
mccarl earned 500 total points
ID: 37709403
You say that this is a custom DHCP server, but is it using the standard DHCP protocol? If so, you need to look more closely at the protocol specs (or even wikipedia's simple version might be enough). The client's MAC address is given in the UDP packet's data area. And you don't respond directly back to this MAC address, the server sends another UDP broadcast for the client to hear. It is all done at the UDP/IP layer, you don't need raw sockets or direct MAC addressing or anything like that.
0
 

Author Closing Comment

by:spongyryno
ID: 37712036
Thanks, I don't know how I overlooked that the MAC address what already in the packet structure. The fact that it uses 16 bytes instead of 6, and only uses 6 of them, is what threw me off.

WinPCap doesn't help. I need to do this programmatically (and I don't want to need to install some 3rd party softeware on each server). Raw sockets are not necessary.

Problem solved. Thanks everyone who responded.
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question