Fall back to IPv4 in case initializing IPv6 socket fails
authorJuho Vähä-Herttua <juhovh@iki.fi>
Sat, 12 May 2012 15:04:09 +0000 (18:04 +0300)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:33:32 +0000 (00:33 +0300)
src/lib/httpd.c

index 9c17e3694668a0d1ddc6c349dc94dfae9d0989a6..971a5bf3e99e0717a3b2feddfd6248a4d5b893bd 100644 (file)
@@ -315,6 +315,11 @@ httpd_start(httpd_t *httpd, unsigned short *port)
        }
 
        httpd->server_fd = netutils_init_socket(port, 1, 0);
+       if (httpd->server_fd == -1) {
+               logger_log(httpd->logger, LOGGER_INFO, "Error initialising IPv6 socket %d", SOCKET_GET_ERROR());
+               logger_log(httpd->logger, LOGGER_INFO, "Attempting to fall back to IPv4");
+               httpd->server_fd = netutils_init_socket(port, 0, 0);
+       }
        if (httpd->server_fd == -1) {
                logger_log(httpd->logger, LOGGER_INFO, "Error initialising socket %d", SOCKET_GET_ERROR());
                MUTEX_UNLOCK(httpd->run_mutex);