[英]Get event for NIC/ethernet card link status on linux
Is there any API(or special file) on Linux that provides an event on the change in link status of an ethernet card without polling ? Linux上是否有任何API(或特殊文件)在没有轮询的情况下提供有关以太网卡链路状态变化的事件? ie when you plug in/out the cable ?
即当你插入/拔出电缆?
如果此文件/sys/class/net/eth0/carrier
为1,则接口eth0
具有carrier。
You can get link up/down events via netlink. 您可以通过netlink获取链接上/下事件。 You would create a
PF_NETLINK
socket, bind to the RTMGRP_LINK
group, and wait for RTM_NEWLINK
/ RTM_DELLINK
messages. 您将创建
PF_NETLINK
套接字,绑定到RTMGRP_LINK
组,并等待RTM_NEWLINK
/ RTM_DELLINK
消息。 Link up events have IFF_RUNNING
and IFF_LOWER_UP
set in ifinfomsg.flags
, while link down events have both flags cleared (funnily enough, I'm getting RTM_NEWLINK
messages for both type of events). 链接事件在
IFF_RUNNING
设置了IFF_RUNNING
和IFF_LOWER_UP
,而链接ifinfomsg.flags
事件都清除了两个标志(有趣的是,我收到了两种类型事件的RTM_NEWLINK
消息)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.