From: Roger Pack Date: 2007-12-21T16:48:39+09:00 Subject: Re: Socket.gethostbyname and Reverse Lookups: A Strange and Terrible Saga > Note, I'm not altogether surprised it worked for you on OS X, > because it also used to work on all my previous linux OS's I still > have available for testing... But something has apparently changed > recently. The thing that got me was ipv6 versus ipv4. My code was class Socket class << self def getIP hostName ipInt = gethostbyname(hostName)[3] return "%d.%d.%d.%d" % [ipInt[0], ipInt[1], ipInt[2], ipInt[3]] end def getHostIP return getIP(Socket.gethostname()) end alias gethostip getHostIP end end run Socket.getHostIP and it works fine on Linux. Run it on OSX, and then the lookup returns and ipv6 addy (at least on my machine), and no ipv4's, so the string creation above returned half an ipv6 addy--not too useful. Appears that Socket.getaddrinfo(Socket.gethostname, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) Yields a more reliable, 'understandable' output. My vote would be for the 'not cross-ip version friendly' gethostbyname to be replaced by this or something along those lines, but that's just me. Take care. -Roger