Module: Ethernet

Defined in:
lib/ethernet.rb,
lib/ethernet/devices.rb,
lib/ethernet/frame_socket.rb,
lib/ethernet/provisioning.rb,
lib/ethernet/devices_linux.rb,
lib/ethernet/devices_darwin.rb,
lib/ethernet/raw_socket_factory.rb,
lib/ethernet/raw_socket_factory_linux.rb,
lib/ethernet/raw_socket_factory_darwin.rb

Overview

:nodoc: namespace

Defined Under Namespace

Modules: Devices, Provisioning, RawSocketFactory Classes: FrameSocket

Class Method Summary collapse

Class Method Details

.devicesObject

Hash mapping Ethernet device names to their MAC addresses.



6
7
8
# File 'lib/ethernet.rb', line 6

def self.devices
  Hash[Ethernet::Devices.all.map { |dev| [dev, Ethernet::Devices.mac(dev)] }]
end

.provisionObject

Allow non-root users to create low-level Ethernet sockets.

This is a security risk, because Ethernet sockets can be used to spy on all traffic on the machine’s network. This should not be called on production machines.

Returns true for success, false otherwise. If the call fails, it is most likely because it is not run by root / Administrator.



27
28
29
# File 'lib/ethernet.rb', line 27

def self.provision
  Ethernet::Provisioning.usermode_sockets
end

.raw_socket(eth_device = nil, ether_type = nil) ⇒ Object

A socket that sends and receives raw Ethernet frames.

Args:

eth_device:: device name for the Ethernet card, e.g. 'eth0'
ether_type:: only receive Ethernet frames with this protocol number


36
37
38
# File 'lib/ethernet.rb', line 36

def self.raw_socket(eth_device = nil, ether_type = nil)
  Ethernet::RawSocketFactory.socket eth_device, ether_type
end

.socket(eth_device, ether_type) ⇒ Object

Ethernet socket that abstracts away frames.

Args:

eth_device:: device name for the Ethernet card, e.g. 'eth0'
ether_type:: 2-byte Ethernet packet type number


15
16
17
# File 'lib/ethernet.rb', line 15

def self.socket(eth_device, ether_type)
  Ethernet::FrameSocket.new eth_device, ether_type
end