summaryrefslogtreecommitdiff
path: root/modules/upnp/upnp.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-03-15 14:38:13 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-03-15 17:33:26 +0100
commit163fc125cda09289feb6342215440358ed2163b6 (patch)
tree4dbd44f65a0892f6108832abe1074d5033050fd7 /modules/upnp/upnp.cpp
parent6eef187a81cbdd3cd314776de372e753f79f9831 (diff)
[Net] Fix miniupnpc when no interface is specified
This is a tricky one, it used to work, but it was wrong, because in such a scenario instead of passing NULL as required by the API, it would pass a buffer containing the `\0` terminator. This stopped working on a specific miniupnpc version, when they fixed some network endianess issue on Windows, to which we made a workaround, which in turn would probably result in failures when the interface is specified. This commit address the issue properly, by checking the specified interface string size, and correctly passing NULL instead of the empty string when necessary. Also reverts the commit that introduced the bogus workaround: e85330231c729a88d5a478de2bbe4a61e5edeae3 One of those PR when the explaination is much longer then code changes :).
Diffstat (limited to 'modules/upnp/upnp.cpp')
-rw-r--r--modules/upnp/upnp.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/upnp/upnp.cpp b/modules/upnp/upnp.cpp
index cff13251ce..8e4e833d45 100644
--- a/modules/upnp/upnp.cpp
+++ b/modules/upnp/upnp.cpp
@@ -52,10 +52,12 @@ int UPNP::discover(int timeout, int ttl, const String &device_filter) {
int error = 0;
struct UPNPDev *devlist;
+ CharString cs = discover_multicast_if.utf8();
+ const char *m_if = cs.length() ? cs.get_data() : nullptr;
if (is_common_device(device_filter)) {
- devlist = upnpDiscover(timeout, discover_multicast_if.utf8().get_data(), nullptr, discover_local_port, discover_ipv6, ttl, &error);
+ devlist = upnpDiscover(timeout, m_if, nullptr, discover_local_port, discover_ipv6, ttl, &error);
} else {
- devlist = upnpDiscoverAll(timeout, discover_multicast_if.utf8().get_data(), nullptr, discover_local_port, discover_ipv6, ttl, &error);
+ devlist = upnpDiscoverAll(timeout, m_if, nullptr, discover_local_port, discover_ipv6, ttl, &error);
}
if (error != UPNPDISCOVER_SUCCESS) {