Take the 2-minute tour ×

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 :)

share|improve this question
Why are you caching something like that? Reading the file is likely to be plenty fast. What are you really trying to accomplish? –  bdonlan Sep 23 '11 at 20:10
The DeviceCache will be used by a socket-framework in order to take the "fastet" device to communicate. So if one of the devices are unplugged the system should change the device to the second fast one –  Ahnihmuhs Sep 23 '11 at 20:12
/proc/net/dev does not give media-connected information –  bdonlan Sep 23 '11 at 20:14
Is NetworkManager available on your distro of choice? –  bdonlan Sep 23 '11 at 20:14
but it lists all the plugged/installed devices like eth, wlan and ppp - which I use to connect to another socket. Or did I misunderstand that file? PS: AS this code should run on embedded systems, i can't install any other libraries as the standard ones in linux, so I assume NetworkManager is not installed either –  Ahnihmuhs Sep 23 '11 at 20:16
show 3 more comments

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
thanks for the answer, I was just using the wrong term to search for my problem, thanks a lot :> –  Ahnihmuhs Sep 23 '11 at 20:34
add comment

Your Answer


