Class: Rethtool

Inherits:
Object
  • Object
show all
Defined in:
lib/rethtool.rb

Overview

A (very) partial implementation of the functionality available in ethtool (and the associated ioctl interface) in pure Ruby.

Why? Because I like to do crazy things.

All the functionality you’re likely to actually want is in subclasses of Rethtool itself:

Rethtool::InterfaceSettings
  Get the settings (speed, duplex, etc) of an interface

Rethtool::LinkStatus
  Whether the link is up or down

Defined Under Namespace

Classes: EthtoolCmd, EthtoolValue, InterfaceSettings, LinkStatus

Constant Summary collapse

SIOCETHTOOL =

From /u/i/linux/sockios.h

0x8946
0x0000000a
ETHTOOL_CMD_GSET =
0x00000001

Class Method Summary collapse

Class Method Details

.ioctl(interface, ecmd) ⇒ Object

Issue an SIOCETHTOOL ioctl. ecmd must respond to #data (such as a CStruct subclass instance). The modified data will be unserialized and returned. The data you pass in WILL NOT be modified, you must capture the return value if you want any results.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rethtool.rb', line 31

def ioctl(interface, ecmd)
	sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)

	ifreq = [interface, ecmd.data].pack("a16p")

	sock.ioctl(SIOCETHTOOL, ifreq)

	rv = ecmd.class.new
	rv.data = ifreq.unpack("a16p")[1]
	rv
end