Solved

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

Posted on 2012-03-11
4
1,064 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
4 Comments
 
LVL 78

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 39

Expert Comment

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now