C/C++ Linux MAC Address of all interfaces

故事扮演 提交于 2019-12-04 04:46:14
jørgensen

You should stop using net-tools and the archaic ioctl interface, and start on using the modern Netlink/sysfs interfaces. You have no less than 5 possibilities:

  • write your own Netlink-interfacing code
  • your own NL code, in combination utilizing libmnl (-> see rtnl-link-dump in Examples
  • or utilize autonomous libs like libnl3
  • parse text output of ip -o link (-o is to get output meant for text parsing, unlike ifconfig)
  • or use sysfs and just look at /sys/class/net/eth0/address

You can find a solution here: Get mac address given a specific interface

You can just skip the specific interface part.

Maybe not as elegant, but you could capture & parse the results from ifconfig, since it sounds like it has just what you are looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!