[SOLVED] Remote Client Mac Address on socket descriptor
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi All,
I want to get the connected client MAC Address after accept() call. I can get the IP address of the client but i don't know how to get the client MAC Address in my this programme. Here I am Posting my Code. Any Guide Line or Solution will be appreciated.
It's technically none of your business what the mac address is. once you have crossed a layer 3 barrier, i.e. a router / firewall the MAC address of the client is not in the tcp/ip headers at all, and You'd only get it in the form of contextual data actually passed from the client of it's own volition.
Dear Acid_Kewpie,
Thanks for reply but i just only learn. you are right for remote connectivity, but i am just asking for local network.
Regards,
Nainesh
TCP is independent of any MAC level protocols. In practice, when using an ethernet link layer, the TCP stack uses ARP to obtain the MAC of the connected host or router. There is the SIOCGARP ioctl() service which may allow you to query the arp cache. When you've Googled 'linux ioctl SIOCGARP', you will find numerous instances of a code snippet which I was able make work on my RHEL 5 host.
If learning the MAC address of a specified host is your only objective, then the arp tool is probably what you want to use.
Dear rod,
Can i mean that there is no MAC Address in Packet which i will received on socket descriptor which is returned by accept call ? Should i have do the arp query to connected client ? if i getting your point, then please guide me in my code. i have also tried it with ioctl command after googling lots of.
You don't get to see the whole ethernet frame, only the payload part of the TCP or UDP packet. TCP works at a level above the datalink layer, and is fully independent of it. TCP could work over any number of datalink layers, some of which may not have a MAC or other distinguishing ID. If you have a currently connected client, and there is a MAC associated with the host, then almost by definition, the host will be fresh in the ARP cache, and you can query it. If the host is beyond a router, you will only see the MAC of the router.
--- rod.
Thanks Dear,
Now i have got your point. means if want to get the mac address of client then i have to make the raw socket and have to learn some about ioctl. i have seen the ioctl with SIOCGARP on google and i have tried it in my programme. but it sill give me error "Protocol Family Not Supported". So, can you give me source code which can fit in my above given source code or any simple server/client source code. It will be help full for me to learn. i am not able to join any academy to learn C programming.
Sorry to have left you for a while. I actually had trouble re-finding the code on the internet, after finding numerous instances on my first search. The version I had tried and tested was on a computer that was unavailable to me for some time. Anyway, here it is, and it works for me. There is a network device name hardcoded into the source code; edit as necessary
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.