How to get a notification from Linux when the set of network interfaces changes

Hi all,

My program sends (and receives) IPv6 multicast packets (ff02::blah) over all of the local Ethernet links; at startup it calls getifaddrs() to find out what Ethernet devices are available to be multicast over.

This all works fine; my problem arises when the user changes the set of active Ethernet devices (e.g. by plugging or unplugging an Ethernet cable, or by enabling/disabling WiFi). When this happens, the list of Ethernet devices I cached at program startup is out-of-date; my program is likely now trying to send multicast packets over a network device that is no longer available; or conversely it may be failing to send multicast packets over a new network device that just became available.

In any case, what I need is some way for my program to be notified when the set of available network interfaces changes; when I get that notification I can then call getifaddrs() again and assemble a new list of network interfaces to use. With a bit of googling I was able to discover how to get this notification under MacOS/X (via the System Configuration framework) and under Windows XP (via NotifyAddrChange() and/or NotifyIpInterfaceChange()). I still haven't discovered the Linux way to do this, however, short of brute-forcing it by running a polling loop that calls getifaddrs() every few seconds and compares the results to the previous set. Perhaps someone knows how this is done?

Thanks,
Jeremy

 

 

I think you should be able to do that with an AF_NETLINK socket... See "man 7 netlink";
they show example code that uses a NETLINK_ROUTE socket to listen for interface
create/delete/up/down events... (You might also want to read RFC 3549 and
this old LJ article ...)

I wonder if you might also able to do it by setting up inotify/dnotify monitoring on
"/proc/net/dev"? I don't know if that works on proc files, though...

 

http://www.developerweb.net/forum/showthread.php?t=6035

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值