Skip to contentSkip to conversation

Getting the MAC address of a client

DISCUSSION Lee Chin 3 participants 3 messages Oct 10, 2002

lore
Share & tools
lore

Lee Chin

author
#0 lore raw

Hello,
When my server application accepts a client socket connection, what is the easiest way to obtain the MAC address of the peer? I tried listing the ARP table but I did not see an entry for the IP address and MAC address of the client. I want to avoid having to ping the client to get the ARP table populated

Thanks
Lee

Signature · 12 lines
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

"Free price comparison tool gives you the best prices and cash back!"
http://www.bestbuyfinder.com/download.htm

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
#1 lore raw
Quoted 6 lines · Lee Chin

When my server application accepts a client socket connection, what is the easiest way to obtain the MAC address of the peer? I tried listing the ARP table but I did not see an entry for the IP address and MAC address of the client.

I want to avoid having to ping the client to get the ARP table populated

If you don't see the client's MAC address in the ARP table, that probably means that the client isn't on the same physical (Ethernet) network as the server. In which case, there's no way that you can obtain its MAC address.

BTW, pinging won't help in any case. If the client *does* happen to be on the same network as the server, the MAC address will have been retrieved in order to send the SYN+ACK.

Signature · 1 line
Glynn Clements <[email protected]>
#2 lore raw
In reply to Lee Chin
Quoted 3 lines · Lee Chin

Hello,
When my server application accepts a client socket connection, what is the easiest way to obtain the MAC address of the peer? I tried listing the ARP table but I did not see an entry for the IP address and MAC address of the client. I want to avoid having to ping the client to get the ARP table populated

The answer to your question depends on am omitted detail.

If the "peer" IS on the same Ethernet as the server, its MAC address should be in the arp table once any packets have been exchanged between server and client. The only exception would be a server so active that it had to flush the arp table to make room for newer entries between the time it accepted the last packet and the time you checked the arp table. If it is not showing up, then you'll have to give us more details if we are to figure out why.

If the "peer" is NOT on the same Ethernet as the server, there is no way (other than doing something in the application layer) to get its MAC address. MAC addresses are associated with the link layer (in this instance, the Ethernet frame), so do not cross routers (which operate at the network layer, in this instance, the IP datagram). In this case, just to be clear, ping'ing won't solve the problem.

There is one other, intermediate case that I know of. If your "peer" is connected to the server through a LAN that proxy-arps its IP address, the server's arp table should include an entry that associates the IP address with the router's IP address. I doubt this applies to your case, but I mention it just for completeness' sake. There may be other rare cases similar to this one.

--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski -- Han Solo
Palo Alto, California, USA [email protected]
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs