Mac + Ruby: unable to access ioctl socket? How to fix?

Good time of day.

Ruby Code:

def hw_address(iface)
    sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM,0)

    buf = [iface,""].pack('a16h16')
    sock.ioctl(SIOCGIFHWADDR, buf);

    sock.close

    return buf[18..24].to_etheraddr
end

puts hw_address('lo0')

What he does: gets the mac address of the interface.

Powered by Debian, as expected. But on Mac OS X it becomes an error for them: `` ioctl ': the operation is not supported on the socket (Errno :: EOPNOTSUPP) `

Do I still need to fix / pass this error message and get work ioctlon sockets?

+3
source share
1 answer

http://hintsforums.macworld.com/showthread.php?t=97909

"The following [s] is not available on Mac OS X:

1) POSIX timer library (-librt Real Time) 2) ioctl with the SIOCGIFHWADDR command - to get the MAC address of the network interface.

C'est la vie.

0

Source: https://habr.com/ru/post/1721658/


All Articles