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

試著忘記壹切 提交于 2020-01-02 06:56:11

问题


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:


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.



来源:https://stackoverflow.com/questions/1659375/mac-ruby-cant-access-ioctl-of-socket-how-to-fix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!