On Sep 4, 2006, at 10:48 PM, <noreply / rubyforge.org>  
<noreply / rubyforge.org> wrote:

> Bugs item #5627, was opened at 2006-09-05 00:48
> You can respond by visiting:
> http://rubyforge.org/tracker/? 
> func=detail&atid=1698&aid=5627&group_id=426
>
> Category: Standard Library
> Group: 1.8.5
> Status: Open
> Resolution: None
> Priority: 3
> Submitted By: Roy Wright (royw)
> Assigned to: Nobody (None)
> Summary: gem_server fails with getnameinfo: ai_family not supported
>
> Initial Comment:
> system info:
> gentoo x86
> dev-lang/ruby-1.8.5  USE="doc examples socks5 tcltk threads -cjk - 
> debug -ipv6"
>
> If gem_server is ran on a system without IPV6 support it will  
> generate the following error:
>
> 2006-09-04 16:49:30] INFO  WEBrick 1.3.1
> [2006-09-04 16:49:30] INFO  ruby 1.8.5 (2006-08-25) [i686-linux]
> /usr/lib/ruby/1.8/webrick/utils.rb:63:in `getaddrinfo':  
> getnameinfo: ai_family
> not supported (SocketError)
>         from /usr/lib/ruby/1.8/webrick/utils.rb:63:in  
> `create_listeners'
>         from /usr/lib/ruby/1.8/webrick/server.rb:75:in `listen'
>         from /usr/lib/ruby/1.8/webrick/server.rb:63:in `initialize'
>         from /usr/lib/ruby/1.8/webrick/httpserver.rb:24:in  
> `initialize'
>         from /usr/bin/gem_server:351:in `new'
>         from /usr/bin/gem_server:351
>
> The cause is this line in /usr/lib/ruby/1.8/webrick/utils.rb:
>
>       res = Socket::getaddrinfo(address, port,
>                                 Socket::AF_UNSPEC,   # address family
>                                 Socket::SOCK_STREAM, # socket type
>                                 0,                   # protocol
>                                 Socket::AI_PASSIVE)  # flag
>
> The problem is the Socket::AF_UNSPEC which is apparently causing  
> getaddrinfo to
> try some IPv6 processing.  Substituting Socket::AF_INET will let  
> gem_server run just fine.
>
> According to the Socket.getaddrinfo documentation, "You will  
> usually pass either nil or Socket::AF_UNSPEC, allowing the IPv6  
> information to be returned first if host is reachable via IPv6, and  
> IPv4 information otherwise."  I think this is assuming that the  
> underlying OS has IPv6 support.

When AF_UNSPEC (PF_UNSPEC on OS X) is passed in for the address  
family getaddrinfo should only return an IPv4 struct addrinfo when  
only IPv4 is supported:

      ai_family      The protocol family that should be used.  When  
ai_family
                     is set to PF_UNSPEC, it means the caller will  
accept any
                     protocol family supported by the operating system.

On FreeBSD 4.10 (IPv4 only) I get:

$ ruby
require 'socket'
p Socket.getaddrinfo(nil, 80, Socket::AF_UNSPEC, Socket::SOCK_STREAM,  
0, Socket::AI_PASSIVE)
[["AF_INET", 80, "0.0.0.0", "0.0.0.0", 2, 1, 6]]

Behavior on other IPv4-only hosts should be identical.

-- 
Eric Hodel - drbrain / segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com