Need to get the MAC address of a peer from a socket (Win32)
Posted on 2012-03-11
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.