Solved

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

Posted on 2012-03-11
4
1,097 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 80

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot install .NET FRAMEWORK 4.61 or update KB2919355 on SERVER 2012 r2 27 1,084
DHCP on ASA 3 57
help!! No network & No Internet connectivity 4 67
CENTOS DHCP Server / PXE/TFTP 14 149
A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

789 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