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 ? 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. You would create a PF_NETLINK
socket, bind to the RTMGRP_LINK
group, and wait for RTM_NEWLINK
/ RTM_DELLINK
messages. 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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.