From: Alan Johnson Date: 2008-11-29T04:21:54+09:00 Subject: [ruby-core:20154] Re: [Bug #743] Socket.gethostbyname returns odd values On Wed, Nov 26, 2008 at 5:04 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:19989] [Bug #743] Socket.gethostbyname returns odd values" > on Wed, 19 Nov 2008 18:58:25 +0900, Alan Johnson writes: > > |File bug743.patch added > | > |gethostbyname/gethostbyaddr seem to work oddly in many respects. > | > |1) Socket.gethostbyname works differently than TCPSocket.gethostbyname. The latter doesn't seem to have any real purpose for existing. > |2) The alias array is always empty. > |3) When a host has multiple IP addresses, they are tacked onto the end of the array. To more faithfully represent a struct hostent, the fourth array member should itself be an array of addresses (matching h_addr_list). > | > |These problems mostly seem to stem from the fact that instead of faithfully calling the underlying library implementation, they ALSO call getaddrinfo. > > It's implemented using getaddrinfo because at the time of coding (long > ago) it was virtually only way to support IPv6 addresses. And you > patch seems destruct IPv6 support. I'd happy to address above issues, > but we are not going to disable IPv6 support. > > matz. > > (Replying via mailing list because the topic has strayed from that of the bug report.) Forgive me if this sounds like a stupid question ... why do you care about ipv6 support in gethostbyname/gethostbyaddr? These functions (the POSIX ones, not ruby) are known for having poor ipv6 support, which is a major reason why getaddrinfo/getnameinfo exist, and those should be the preferred methods used by anyone needing ipv6. Trying to retroactively add support to gethostbyname leads to nonsensical results like the following: irb(main):002:0> Socket.gethostbyname('host1.example.com') => ["host1.example.com", [], 2, "\xC0\xA8\x01\x02", "\xC0\xA8\x01\x03", "\xC0\xA8\x01\x01", "\xFC\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", "\xFC\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02", "\xFC\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03"] Note that the address family is reported as 2 (AF_INET) but three of the results do not belong in that address family. As I understand it, the Socket class exists to provide low level support for the underlying socket implementation. It is confusing for Ruby's implementation of a function to behave differently from the platform's implementation. -- Alan