I know that I can poll the link state via the SIOCETHTOOL/ETHTOOL_GLINK ioctl but this would require to endlessly request the state. The same goes for parsing /var/log/messages. So my questin is, is there any way under Linux to wait on a state change of the ethernet cable from userspace?
Asked
Active
Viewed 2,499 times
2 Answers
7
How about ifplugd
?
ifplugd
is a Linux daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected.
(There is also netplugd
, but it was discontinued.)

sr_
- 15,384
0
The solution of sr_ is better than mine, but you could use those ioctls with sleep
to avoid the endless stressing of the resources. Write a loop which investigates if there is the questioned link up/down, then do something/nothing in either cases, and then sleep
a few seconds. It will generate just a little load on your system.

vakufo
- 667
:)
– sr_ Mar 09 '12 at 14:46