Getaddrinfo ::?

I’m tinkering around with Borges on my XP box and one of the first
things it tries to do out of the chute is:

server = WEBrick::HTTPServer.new(options)
server.listen('::', 7000)

The listen method inside WEBrick is:

def listen(address, port)
  res = Socket::getaddrinfo(address, port,
                            Socket::AF_UNSPEC,   # address family
                            Socket::SOCK_STREAM, # socket type
                            0,                   # protocol
                            Socket::AI_PASSIVE)  # flag

I assume ‘::’ is shorthand for something, localhost if I had to guess
… but Googling for :: doesn’t work so I’ve no idea where to start
looking. This is raised as an error:

c:/ruby/lib/ruby/1.8/webrick/server.rb:77:in getaddrinfo': getaddrinfo: no addr ess associated with hostname. (SocketError) from c:/ruby/lib/ruby/1.8/webrick/server.rb:77:inlisten’
from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:67:in create' from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:77:instart’
from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:88

Can anyone help me here?

···


Chris
http://clabs.org/blogki

Chris Morris wrote:

I assume ‘::’ is shorthand for something, localhost if I had to guess …

I replaced the Borges/WEBrick.rb code with localhost and it gets past
getaddrinfo, but then fails on the TCPServer.new line:

def listen(address, port)
  res = Socket::getaddrinfo(address, port,
                            Socket::AF_UNSPEC,   # address family
                            Socket::SOCK_STREAM, # socket type
                            0,                   # protocol
                            Socket::AI_PASSIVE)  # flag
  last_error = nil
  sockets = []
  res.each{|ai|
    begin
      @logger.debug("TCPServer.new(#{ai[3]}, #{ai[1]})")
      sock = TCPServer.new(ai[3], ai[1])
      Utils::set_close_on_exec(sock)
      sockets << sock
    rescue => ex
      @logger.warn("TCPServer Error: #{ex}")
      last_error  = ex
    end
  }
  raise last_error if sockets.empty?
  return sockets
end

with the following:

c:/ruby/lib/ruby/1.8/webrick/server.rb:91:in listen': Unknown Error - bind(2) ( Errno::E048) from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:67:in create’
from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:77:in `start’
from C:/ruby/lib/ruby/site_ruby/1.8/Borges/WEBrick.rb:88

···


Chris
http://clabs.org/blogki

Chris Morris wrote:

I replaced the Borges/WEBrick.rb code with localhost and it gets past
getaddrinfo, but then fails on the TCPServer.new line:

I’m guessing this is older Borges code with newer WEBrick code. This is
the failing Borges code:

server = WEBrick::HTTPServer.new(options)
server.listen('127.0.0.1', 7000) 
server.mount("/borges", self, options)

The HTTPServer.new call itself sets up shop on TCP port 7000, so the
following listen call is failing because the port is already in use.
Remmed out the .listen line and now we’re rolling.

···


Chris
http://clabs.org/blogki

See alpha3, which does this the right way:
http://segment7.net/ruby-code/borges/Borges-1.0.0-alpha3.tar.gz

For reference, the correct way to set up a v4/v6 WEBrick server that
works out of the box on v4-only hosts is this:

def create(options)
options[:BindAddress] ||= nil
options[:Port] ||= 7000

server = WEBrick::HTTPServer.new(options)

return server
end

When the :BindAddress option is set to nil, getaddrinfo will
return both :: and 0.0.0.0 on an IPv6 system, and the server will bind
to both.

:: is kinda but not really an IPv6 equivalent to 0.0.0.0 (there are
several broadcast addresses for IPv6, depending upon who you want
to talk to).

···

Chris Morris (chrismo@clabs.org) wrote:

Chris Morris wrote:

I replaced the Borges/WEBrick.rb code with localhost and it gets past
getaddrinfo, but then fails on the TCPServer.new line:

I’m guessing this is older Borges code with newer WEBrick code. This is
the failing Borges code:

server = WEBrick::HTTPServer.new(options)
server.listen(‘127.0.0.1’, 7000)
server.mount(“/borges”, self, options)

The HTTPServer.new call itself sets up shop on TCP port 7000, so the
following listen call is failing because the port is already in use.
Remmed out the .listen line and now we’re rolling.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Oh, ha! I lied, I fixed this after alpha3 (about 5 minutes after) :frowning:

Here’s the patch:

CS file: /home/cvs/ruby/seaside2/Borges/lib/Borges/WEBrick.rb,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -p -F [1]*(class|module|def) -r1.9 -r1.10
— ruby/seaside2/Borges/lib/Borges/WEBrick.rb 2003/12/21 02:53:52 1.9
+++ ruby/seaside2/Borges/lib/Borges/WEBrick.rb 2003/12/22 04:05:49 1.10
@@ -60,11 +60,10 @@ def do_GET(req, res)

and mounts the Borges::WEBrickServlet on /borges.

def self.create(options)

  • options[:BindAddress] ||= ‘0.0.0.0’
  • options[:BindAddress] ||= nil
    options[:Port] ||= 7000

    server = WEBrick::HTTPServer.new(options)

  • server.listen(‘::’, 7000)
    server.mount(“/borges”, self, options)

    return server

···

Eric Hodel (drbrain@segment7.net) wrote:

See alpha3, which does this the right way:
http://segment7.net/ruby-code/borges/Borges-1.0.0-alpha3.tar.gz


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


  1. ↩︎