| 1 | require 'rethtool' |
| 2 | require 'rethtool/ethtool_value' |
| 3 | |
| 4 | # Retrieve the current link status of an interface. |
| 5 | # |
| 6 | # Usage is very simple: |
| 7 | # |
| 8 | # LinkStatus.new("eth0").up? |
| 9 | # |
| 10 | # or |
| 11 | # |
| 12 | # LinkStatus.new("eth0").down? |
| 13 | # |
| 14 | class Rethtool::LinkStatus |
| 15 | def initialize(interface) |
| 16 | cmd = Rethtool::EthtoolValue.new |
| 17 | cmd.cmd = Rethtool::ETHTOOL_CMD_GSET |
| 18 | |
| 19 | @status = Rethtool.ioctl(interface, cmd).value |
| 20 | end |
| 21 | |
| 22 | def down? |
| 23 | @status == 0 |
| 24 | end |
| 25 | |
| 26 | def up? |
| 27 | !down? |
| 28 | end |
| 29 | end |