How to get notified when an eth interface goes link down?

We have an application managing TCP socket that are created with socket() and listen(). As TCP sockets are created, we keep a list of the host and port info. When a socket is closed, we clear the host and port info from our list. When the ethernet port gets disconnected (link down), the host and port info may no longer be valid. Flushing our list based on an inactivity timer is not a good option. We would like to flush the list when we lose the ethernet link.

My question is: How can our application get notified when the ethernet link that our listen socket is bound to goes link down without having to poll the driver with a devctrl() call.

Many thanks in advance for any advice or relevant info.

  • Ken

Are you not using SO_KEEPALIVE as one of your socket options? Then specify a TCP_KEEPALIVE time for how often it checks the connection is ‘alive’. You can then close down and clean up when you are told a connection is dead. All for the cost of a bit of extra network traffic.

There is no real mechanism to tell you when the link is truly down. You can probably setup io_notify() to get notified when it goes down as far as QNX is concerned (ie cable unplugged). But that would just tell you if the cable was unplugged from the back of the QNX machine. It wouldn’t tell you if the cable was unplugged from the router side or the router itself was powered down and so on.


Thank you Tim. I will look into io_notify().

Yes, we are using keep alives, but there is a trade-off with how short the keep alive is versus having slow connections dropped too early.


  • Ken

As I mentioned, io-notify will only help you when the cable is unplugged locally from the QNX machine. I would imagine that to be a very rare case (other than when you are testing) in real life.

Note: The TCP Keepalive time has nothing to do network speed and isn’t affected by slow connections unless your remote side is across the world over satellite where responses may be delayed by longer than the TCP stack expects. The Keepalive time is just how often you check that the remote side is still alive. For most applications I would think once a minute (maybe very aggressively at 10 seconds) is plenty to do a housekeeping check for dead connections unless you have a LOT of connections happening regularly and are very memory constrained with regards to having old ones lurking around.