IPv4 binding failure is fatal in all cases

IPv4 and IPv6 are bound separately; IPv6 may fail if unsupported, IPv4
must always succeed.
This commit is contained in:
Julien BLACHE 2010-05-14 17:36:58 +02:00
parent ed38ce7dd1
commit 588b328b45

View File

@ -1201,7 +1201,6 @@ int
httpd_init(void)
{
unsigned short port;
int bindv6;
int ret;
httpd_exit = 0;
@ -1278,20 +1277,20 @@ httpd_init(void)
port = cfg_getint(cfg_getsec(cfg, "library"), "port");
/* evhttp doesn't support IPv6 yet, so this is expected to fail */
bindv6 = evhttp_bind_socket(evhttpd, "::", port);
if (bindv6 < 0)
DPRINTF(E_INFO, L_HTTPD, "Could not bind IN6ADDR_ANY:%d (that's OK)\n", port);
/* We are binding v6 and v4 separately, and we allow v6 to fail
* as IPv6 might not be supported on the system.
* We still warn about the failure, in case there's another issue.
*/
ret = evhttp_bind_socket(evhttpd, "::", port);
if (ret < 0)
DPRINTF(E_WARN, L_HTTPD, "Could not bind IN6ADDR_ANY:%d (that's OK)\n", port);
ret = evhttp_bind_socket(evhttpd, "0.0.0.0", port);
if (ret < 0)
{
if (bindv6 < 0)
{
DPRINTF(E_FATAL, L_HTTPD, "Could not bind INADDR_ANY:%d\n", port);
DPRINTF(E_FATAL, L_HTTPD, "Could not bind INADDR_ANY:%d\n", port);
goto bind_fail;
}
goto bind_fail;
}
evhttp_set_gencb(evhttpd, httpd_gen_cb, NULL);