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

前端 未结 5 1054
旧巷少年郎
旧巷少年郎 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 11:58

    Remember, on Linux "everything" is a file.

    The best way would be to use the approved kernel<->userspace communication, namely sysfs, mounted at /sys. Network devices are linked at /sys/class/net

    If you wish to use the ioctl interface, look at man netdevice

提交回复
热议问题