Mac + Ruby: Can't access ioctl of Socket? How

2019-05-16 11:56发布

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 it do: gets mac-address of interface.

Works on Debian as expected. But on Mac OS X, im getting error: ``ioctl': Operation not supported on socket (Errno::EOPNOTSUPP)`

Is there anyway to fix/pass this error message & get working ioctl on Sockets?

1条回答
冷血范
2楼-- · 2019-05-16 12:07

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

"Following function[s] are not available at Mac OS X:

1) POSIX Timer Library (-librt Real Time) 2) ioctl with command SIOCGIFHWADDR - To get the Mac Address of the network interface."

C'est la vie.

查看更多
登录 后发表回答