?
Solved

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

Posted on 2012-03-11
4
Medium Priority
?
1,146 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 82

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes you might need to configure routing based not only on destination IP address, but also on a combination of destination IP address (or hostname) and destination port number. I will describe a method how to accomplish this with free tools. …
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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 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