Module: Orion6Rep::Interface

Defined in:
lib/orion6_rep/interface.rb

Constant Summary collapse

SIOCGIFHWADDR =

From bits/ioctls.h

0x8927
SIOCGIFADDR =

Get hardware address

0x8915
SIOCGIFBRDADDR =

Get PA address

0x8919

Class Method Summary collapse

Class Method Details

.broadcast_address(iface) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/orion6_rep/interface.rb', line 37

def broadcast_address(iface)
  socket = UDPSocket.new
  buf = [iface, ""].pack('a16h16')
  socket.ioctl(SIOCGIFBRDADDR, buf)
  socket.close
  to_ipaddr4(buf[20..23])
end

.get_active_interfaces_namesObject



17
18
19
# File 'lib/orion6_rep/interface.rb', line 17

def get_active_interfaces_names
  System.get_ifaddrs.keys.collect{|iface| iface.to_s}
end

.hw_address(iface) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/orion6_rep/interface.rb', line 21

def hw_address(iface)
  socket = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
  buf = [iface, ""].pack('a16h16')
  socket.ioctl(SIOCGIFHWADDR, buf)
  socket.close
  to_etheraddr(buf[18..23])
end

.ip_address(iface) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/orion6_rep/interface.rb', line 29

def ip_address(iface)
  socket = UDPSocket.new
  buf = [iface, ""].pack('a16h16')
  socket.ioctl(SIOCGIFADDR, buf)
  socket.close
  to_ipaddr4(buf[20..23])
end