Question

I read some questions here but couldn't really find the specific problem I'am faced with here...

I need to implement a "DeviceCache" in a particular project which caches all device-names found in /proc/net/dev . The Language is C/++

So I thought about a seperate thread looking every X seconds in the directory mentioned above but was encouraged to find a more direct way. How can I register a method of my process to the device manager of linux? Is there a similar way like events/signals?

I looked in other sites but couldn't find any helpful code... Im relatively new to Linux-programming but willing to learn new things :)

Was it helpful?

Solution

Based on your comments, what you really want is to track which network interfaces are operational at any given time.

The only true way to determine if a network interface is up is to test it - after all, the router on the other end may be down. You could send pings out periodically, for example.

However, if you just want to know if the media goes down (ie, the network cable is unplugged), take a look at these SO questions:

If you just want to be notified of the actual hardware-level registration of interfaces (eg, when a USB NIC is plugged in), you can use udev events if your platform has udev; otherwise, I believe there's another netlink category for hardware addition/removal events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top