File: link_status.rb

package info (click to toggle)
ruby-rethtool 0.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 148 kB
  • sloc: ruby: 167; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 455 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'rethtool'
require 'rethtool/ethtool_value'

# Retrieve the current link status of an interface.
#
# Usage is very simple:
#
#   LinkStatus.new("eth0").up?
#
# or
#
#   LinkStatus.new("eth0").down?
#
class Rethtool::LinkStatus
	def initialize(interface)
		cmd = Rethtool::EthtoolValue.new
		cmd.cmd = Rethtool::ETHTOOL_CMD_GSET
		
		@status = Rethtool.ioctl(interface, cmd).value
	end
	
	def down?
		@status == 0
	end
	
	def up?
		!down?
	end
end