mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-28 00:10:59 -04:00
[misc] Fix for evhttp_bind_socket not supporting dual stack ipv4/6 on BSD
This commit is contained in:
parent
c1db4d914f
commit
5128d9478a
37
src/misc.c
37
src/misc.c
@ -329,39 +329,40 @@ int
|
||||
net_evhttp_bind(struct evhttp *evhttp, short unsigned port, const char *log_service_name)
|
||||
{
|
||||
const char *bind_address;
|
||||
bool v6_enabled;
|
||||
int ret;
|
||||
|
||||
bind_address = cfg_getstr(cfg_getsec(cfg, "general"), "bind_address");
|
||||
if (!bind_address)
|
||||
bind_address = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6") ? "::" : "0.0.0.0";
|
||||
if (bind_address)
|
||||
evhttp_bind_socket(evhttp, bind_address, port);
|
||||
|
||||
return evhttp_bind_socket(evhttp, bind_address, port);
|
||||
}
|
||||
/* TODO check if the below is required for FreeBSD
|
||||
if (v6enabled)
|
||||
// For Linux, we could just do evhttp_bind_socket() for "::", and both the
|
||||
// ipv4 and v6 port would be bound. However, for bsd it seems it is necessary
|
||||
// to do like below.
|
||||
v6_enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");
|
||||
if (v6_enabled)
|
||||
{
|
||||
ret = evhttp_bind_socket(evhttpd, "::", httpd_port);
|
||||
ret = evhttp_bind_socket(evhttp, "::", port);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_HTTPD, "Could not bind to port %d with IPv6, falling back to IPv4\n", httpd_port);
|
||||
v6enabled = 0;
|
||||
DPRINTF(E_LOG, L_MISC, "Could not bind service '%s' to port %d with IPv6, falling back to IPv4\n", log_service_name, port);
|
||||
v6_enabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ret = evhttp_bind_socket(evhttpd, "0.0.0.0", httpd_port);
|
||||
ret = evhttp_bind_socket(evhttp, "0.0.0.0", port);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (!v6enabled)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_HTTPD, "Could not bind to port %d (server already running?)\n", httpd_port);
|
||||
goto bind_fail;
|
||||
}
|
||||
if (!v6_enabled)
|
||||
return -1;
|
||||
|
||||
#ifndef __linux__
|
||||
// Linux will listen on both ipv6 and ipv4, but FreeBSD won't
|
||||
DPRINTF(E_LOG, L_HTTPD, "Could not bind to port %d with IPv4, listening on IPv6 only\n", httpd_port);
|
||||
DPRINTF(E_LOG, L_MISC, "Could not bind service '%s' to port %d with IPv4, listening on IPv6 only\n", log_service_name, port);
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
net_is_http_or_https(const char *url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user