mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-31 01:33:44 -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)
|
net_evhttp_bind(struct evhttp *evhttp, short unsigned port, const char *log_service_name)
|
||||||
{
|
{
|
||||||
const char *bind_address;
|
const char *bind_address;
|
||||||
|
bool v6_enabled;
|
||||||
|
int ret;
|
||||||
|
|
||||||
bind_address = cfg_getstr(cfg_getsec(cfg, "general"), "bind_address");
|
bind_address = cfg_getstr(cfg_getsec(cfg, "general"), "bind_address");
|
||||||
if (!bind_address)
|
if (bind_address)
|
||||||
bind_address = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6") ? "::" : "0.0.0.0";
|
evhttp_bind_socket(evhttp, bind_address, port);
|
||||||
|
|
||||||
return evhttp_bind_socket(evhttp, bind_address, port);
|
// 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
|
||||||
/* TODO check if the below is required for FreeBSD
|
// to do like below.
|
||||||
if (v6enabled)
|
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)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Could not bind to port %d with IPv6, falling back to IPv4\n", httpd_port);
|
DPRINTF(E_LOG, L_MISC, "Could not bind service '%s' to port %d with IPv6, falling back to IPv4\n", log_service_name, port);
|
||||||
v6enabled = 0;
|
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 (ret < 0)
|
||||||
{
|
{
|
||||||
if (!v6enabled)
|
if (!v6_enabled)
|
||||||
{
|
return -1;
|
||||||
DPRINTF(E_FATAL, L_HTTPD, "Could not bind to port %d (server already running?)\n", httpd_port);
|
|
||||||
goto bind_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef __linux__
|
#ifndef __linux__
|
||||||
// Linux will listen on both ipv6 and ipv4, but FreeBSD won't
|
DPRINTF(E_LOG, L_MISC, "Could not bind service '%s' to port %d with IPv4, listening on IPv6 only\n", log_service_name, port);
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Could not bind to port %d with IPv4, listening on IPv6 only\n", httpd_port);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
net_is_http_or_https(const char *url)
|
net_is_http_or_https(const char *url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user