LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   System call for getting MAC address (http://www.linuxquestions.org/questions/linux-networking-3/system-call-for-getting-mac-address-413354/)

Madhusudhan 02-09-2006 03: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,
Madhusudhan

satinet 02-09-2006 03: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 04: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 ,
Madhusudhan

satinet 02-09-2006 04: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 04: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 09:06 PM

Thanks a lot !!!!!!!!!!!!!!!
This worked ,
using ioctl we can do it...
infact i got entire program itself in LinuxQuestions.org > 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 03:30 AM.