How to get local IP and MAC address C

shaggy picture shaggy · Jul 20, 2011 · Viewed 28k times · Source

Possible Duplicate:
Linux / C++: Get the IP Address of local computer

I am trying to get my local computer's IP and MAC addresses of all interfaces, but I can not really succeed. I need to get it together, so I know which IP belongs to which MAC.

I went through a lot of searching on google and even here, but I can not really find a C code for this.

Could you please help me?

Thanks in advance! I would really appreciate that!

Answer

bitbucket picture bitbucket · Jul 20, 2011

On relatively recent versions of Linux, you can just read the contents of /sys/class/net/eth0/address (substituting any network interface name for eth0) to get the hardware address of an interface.