How can I monitor the NIC status(up/down) in a C program without polling the kernel?

后端 未结 3 856
不知归路
不知归路 2020-12-02 12:25

Now I need to get the status of the NIC(up or down) in the real time. That means I have to catch the kernel interrupt when the NIC up or down in a blocked loop.

The

3条回答
  •  情歌与酒
    2020-12-02 13:13

    Have you tried monitoring the /sys/class/net/eth0/operstate file with select or poll function? As far as I can tell sysfs files should behave the same with respect to polling as regular files: whenever a change occurs you should get a notification on the file handle that something has changed and you should be able to respond accordingly.

提交回复
热议问题