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

后端 未结 3 854
不知归路
不知归路 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:04

    Yes, open a netlink socket and listen to the RTMGRP_LINK (network interface create/delete/up/down events) multicast groups.

    The netlink man page here has a specific example to do this.

提交回复
热议问题