My program must detect when an ethernet interface turn to RUNNING
state.
I can poll the running flag by using ioctl()
:
if( ioctl( dummy_fd, SIOCGIFFLAGS, &ifr ) != -1 )
return ifr.ifr_flags & IFF_RUNNING;
But want the information immediately without polling. Currently the program uses select()
for waiting other events. So it would be nice to use select()
for detecting state changes of interfaces.
There is a way to do it with select
, I did read about that from net. But I don't find that page anymore.
the kernel sends information about network interface changes over netlink; see e.g. here for an example http://softengcrunch.blogspot.cz/2010/12/communicating-with-kernel-via-netlink.html A quick and dirty hack would be to do the polling after any netlink event (when select wakes up on the netlink socket), without actually parsing the netlink packet ;)