lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2011/3/22 Diego Nehab <>:
> Hi,
> How about I make the automatic name resolution in LuaSocket to follow the
> principled approach of trying addresses in the order returned by getaddrinfo?
> Users could invoke the name resolution function themselves, and filter
> out the resolved addresses based on their own family requirements?
> In other words, socket.connect("", 80) would try whatever
> the resolve returns: perhaps IPv6 first then if that fails IPv4, or perhaps the
> only address returned is IPv4 so that's what connect tries. On the other hand,
> socket.connect("", 80) would obviously try to connect only through
> IPv4 and fail through to the user if that doesn't work, whereas
> socket.connect("2001:db8::1", 80) would try only IPv6. Since the user can
> perform his/her own name resolution, this would be the method to control
> specific behavior without weighting the API down with options.
> Wouldn't that be both simple and general enough to satisfy everyone?

Actually that's exactly the kind of solution I was about to suggest.

> Maybe the connect() call could accept a table of IP addresses to try
> in sequence, so that socket.connect("", 80) is equivalent to
> socket.connect(socket.toip(""), 80), assuming socket.toip()
> simply returns the list of resolved addresses in the order provided by
> getaddrinfo...

That on the other hand seems to be a bit overkill, the user could do
the iteration itself. Maybe instead you could provide facilities to
determine what IP version each address returned by toip belongs to, or
maybe add a parameter second parameter in toip to filter on the
protocol version.