Commit 4ed60a57 authored by Max Audron's avatar Max Audron

upnp: expose interface configuration on UpnpInit2()

Adds the Interface Name as an argument to the *Init functions to make it possible to select which interface is used by upnp to detect servers. Currently "nullptr" is passed in to let the upnp library select an interface, as before.
parent c93195c9
...@@ -155,7 +155,7 @@ UpnpDatabase::Create(EventLoop &, EventLoop &io_event_loop, ...@@ -155,7 +155,7 @@ UpnpDatabase::Create(EventLoop &, EventLoop &io_event_loop,
void void
UpnpDatabase::Open() UpnpDatabase::Open()
{ {
handle = UpnpClientGlobalInit(); handle = UpnpClientGlobalInit(nullptr);
discovery = new UPnPDeviceDirectory(event_loop, handle); discovery = new UPnPDeviceDirectory(event_loop, handle);
try { try {
......
...@@ -57,9 +57,9 @@ DoInit() ...@@ -57,9 +57,9 @@ DoInit()
} }
UpnpClient_Handle UpnpClient_Handle
UpnpClientGlobalInit() UpnpClientGlobalInit(const char* iface)
{ {
UpnpGlobalInit(); UpnpGlobalInit(iface);
try { try {
const std::lock_guard<Mutex> protect(upnp_client_init_mutex); const std::lock_guard<Mutex> protect(upnp_client_init_mutex);
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "Compat.hxx" #include "Compat.hxx"
UpnpClient_Handle UpnpClient_Handle
UpnpClientGlobalInit(); UpnpClientGlobalInit(const char* iface);
void void
UpnpClientGlobalFinish() noexcept; UpnpClientGlobalFinish() noexcept;
......
...@@ -33,12 +33,13 @@ static Mutex upnp_init_mutex; ...@@ -33,12 +33,13 @@ static Mutex upnp_init_mutex;
static unsigned upnp_ref; static unsigned upnp_ref;
static void static void
DoInit() DoInit(const char* iface)
{ {
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
auto code = UpnpInit2(nullptr, 0); auto code = UpnpInit2(iface, 0);
#else #else
auto code = UpnpInit(nullptr, 0); auto code = UpnpInit(iface, 0);
#endif #endif
if (code != UPNP_E_SUCCESS) if (code != UPNP_E_SUCCESS)
throw FormatRuntimeError("UpnpInit() failed: %s", throw FormatRuntimeError("UpnpInit() failed: %s",
...@@ -53,12 +54,12 @@ DoInit() ...@@ -53,12 +54,12 @@ DoInit()
} }
void void
UpnpGlobalInit() UpnpGlobalInit(const char* iface)
{ {
const std::lock_guard<Mutex> protect(upnp_init_mutex); const std::lock_guard<Mutex> protect(upnp_init_mutex);
if (upnp_ref == 0) if (upnp_ref == 0)
DoInit(); DoInit(iface);
++upnp_ref; ++upnp_ref;
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define MPD_UPNP_INIT_HXX #define MPD_UPNP_INIT_HXX
void void
UpnpGlobalInit(); UpnpGlobalInit(const char* iface);
void void
UpnpGlobalFinish() noexcept; UpnpGlobalFinish() noexcept;
......
...@@ -74,7 +74,7 @@ private: ...@@ -74,7 +74,7 @@ private:
void void
UpnpNeighborExplorer::Open() UpnpNeighborExplorer::Open()
{ {
auto handle = UpnpClientGlobalInit(); auto handle = UpnpClientGlobalInit(nullptr);
discovery = new UPnPDeviceDirectory(event_loop, handle, this); discovery = new UPnPDeviceDirectory(event_loop, handle, this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment