On Linux: how can I programmatically determine if a NIC interface is enabled and plugged in?

前端 未结 5 1056
旧巷少年郎
旧巷少年郎 2021-02-05 11:51

I want to determine if a network card is enabled, up, and plugged in. Basically, I want to know if the network card will work. I need this information from with a C++ program, a

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 12:12

    Run through the output of getifaddrs, you can use the link layer for the MAC address to identify an adapter and check the ifa_flags for IFF_UP. Use AF_NETLINK for notifications about interface changes.

提交回复
热议问题