xbmc/xbmc — pull request #2668 by simonvetter (2013-04-29 08:14:14+00:00)
Title: JSONRPCServer, AirPlayServer, WebServer: listen on ipv6 if available, else fall back to ipv4

This PR makes JSONRPCServer, AirPlayServer and WebServer available over ipv6.

If the platform we are running on doesn't support ipv6 (i.e. the ipv6 module is not inserted), trying to create an ipv6 socket will fail. In this case, we safely fall back to ipv4.

JSONRPCServer, AirPlayServer:
The code attempts to make ipv6 sockets dual stack by setting setsockopt(IPV6_V6ONLY) to false. This means that both ipv4 and ipv6 connections will be handled by the same socket.

Binding to localhost works for both address families.

WebServer:
By design, MHD tries to bind to only one address family, so in case ipv6 is available, the best solution seems to start two instances of the server.

On some systems (OSX at least), MHD seems to use dual stack sockets. In this case, the ipv6 instance will serve both ipv6 and ipv4 clients and the ipv4 instance will fail to start (port already in use). The code handles both situations.

Tested OK on Linux (raspberry pi) and MacOSX (macbook air).