Skip to content

Commit 5589241

Browse files
patrickloddertuaris
andcommitted
net: fix compatibility with miniupnp API version 18
- Fix breaking change on UPNP_GetValidIGD by macro condition on MINIUPNPC_API_VERSION > 18 - Verbosely log what was returned by UPNP_GetValidIGD - because we can detect whether a valid outbound connection was found to and unroutable external IP. This helps troubleshooting situations where for example an ISP uses CGNAT. See miniupnp commit c0a50ce33e3b99ce8a96fd43049bb5b53ffac62f for the full change. Co-authored-by: Daniel Morante <[email protected]>
1 parent 5a1421c commit 5589241

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/net.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,16 @@ void ThreadMapPort()
14881488
struct IGDdatas data;
14891489
int r;
14901490

1491+
// since API version 18 / release 2.2.8
1492+
// both signature and return values of UPNP_GetValidIGD have been changed
1493+
// see miniupnp commit c0a50ce33e3b99ce8a96fd43049bb5b53ffac62f
1494+
#if MINIUPNPC_API_VERSION < 18
14911495
r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
1496+
// r: 1 = success, 2 = not connected, 3 = unrecognized IGD
1497+
#else
1498+
r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr), nullptr, 0);
1499+
// r: 1 = success, 2 = success but not routable (i.e. CGNAT), 3 = not connected, 4 = unrecognized IGD
1500+
#endif // MINIUPNPC_API_VERSION < 18
14921501
if (r == 1)
14931502
{
14941503
if (fDiscover) {
@@ -1543,7 +1552,7 @@ void ThreadMapPort()
15431552
throw;
15441553
}
15451554
} else {
1546-
LogPrintf("No valid UPnP IGDs found\n");
1555+
LogPrintf("No valid UPnP IGDs found: %d\n", r);
15471556
freeUPNPDevlist(devlist); devlist = 0;
15481557
if (r != 0)
15491558
FreeUPNPUrls(&urls);

0 commit comments

Comments
 (0)