I am working on Ubuntu. How can I get MAC address of my machine or an interface say eth0 using C program.
Much nicer than all this socket or shell madness is simply using sysfs for this:
the file /sys/class/net/eth0/address
carries your mac adress as simple string you can read with fopen()
/fscanf()
/fclose()
. Nothing easier than that.
And if you want to support other network interfaces than eth0 (and you probably want), then simply use opendir()
/readdir()
/closedir()
on /sys/class/net/
.