From: Rob Partington Date: 2001-09-30T20:17:09+09:00 Subject: [ruby-talk:21838] gethostbyname strangeness rjp> irb irb(main):001:0> require "socket" true irb(main):002:0> Socket.gethostbyname("www.rotten.com") SocketError: host not found from (irb):2:in `gethostbyname' from (irb):2 irb(main):003:0> rjp> host www.rotten.com www.rotten.com has address 216.218.248.130 The problem is this bit of ext/socket/socket.c, starting at line 1745 (taken from 1.6.5 sources, but it's the same in the stable-snapshot): else { setipaddr(host, (struct sockaddr *)&addr); } switch (addr.ss_family) { case AF_INET: { struct sockaddr_in *sin; sin = (struct sockaddr_in *)&addr; h = gethostbyaddr((char *)&sin->sin_addr, sizeof(sin->sin_addr), sin->sin_family); break; } The correct information is received in setipaddr from the getaddrinfo() call and returned to sock_s_gethostbyname. But then Ruby does a reverse lookup for some reason which fails for www.rotten.com and returns nothing. rjp> host 216.218.248.130 Host not found. Socket.gethostbyname() works only if there's a reverse for the IP address it gets from the getaddrinfo() call. This is preventing me using Ruby instead of Perl for a project since Perl handles this situation correctly. Is this behaviour broken, or intentional? The fix is fairly simple -- return the information from the getaddrinfo() call instead of trying to reverse it into a hostent struct. I've tried this on FreeBSD, OpenBSD/sparc, Linux and MacOS X, both 1.6.4 and 1.6.5. The MacOS X one works fine which makes me wonder if it's a "feature" in that library. Any suggestions? If people want me to send a patch to fix this, I will. -- rob partington % rjp@browser.org % http://lynx.browser.org/