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/
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…