-   Linux - Networking (
-   -   System call for getting MAC address (

Madhusudhan 02-09-2006 04:17 AM

System call for getting MAC address
Hi All,

Can anybody tell me which system call to use to get the MAC address/Hardware address of the machine..

Same thing can be got by ifconfig -a but i need system call for the same to use in the program....

Thanks and regards,

satinet 02-09-2006 04:50 AM

why not use ifconfig then and 'awk' or 'cut' out the relevant data??

please provide such an output and i will explain how to do it...

Madhusudhan 02-09-2006 05:01 AM

MAC address source code
Actually i wanted use it in a C program to get the MAC address.
So is there any way to get or else where to find the source code of the IFCONFIG ???

Can you please help me ??

thanks ,

satinet 02-09-2006 05:08 AM

oh thats's interesting. not sure to be honest. i thought you were shell scripting...

must be out there.... google? :-)

nx5000 02-09-2006 05:32 AM

This should work:

Open a socket
Prepare a ifreq structure with the name of the interface (eg eth0)
Pass the socket and the structure to ioctl , asking for ioctl SIOCGIFADDR
Then the MAC address is in ifreq.ifr_hwaddr, you can strcpy to your string

Madhusudhan 02-09-2006 10:06 PM

Thanks a lot !!!!!!!!!!!!!!!
This worked ,
using ioctl we can do it...
infact i got entire program itself in > Forums > Non-*NIX Forums > Programming forum....
name of the Post is "read IP address in C module progarm" by linux_lover2005.

All times are GMT -5. The time now is 06:21 PM.