From 64f6eb4ff4e4354d7c52f03db78469b3a6cfdf26 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Tue, 2 Jul 2024 17:23:01 -0400 Subject: [PATCH] Support miniupnp API version 18+ The UPNP_GetValidIGD function has added wanaddr and wanaddr length parameters for API version 18+. --- src/net.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 0f1f87cf0d..f914a69bd7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1155,6 +1155,9 @@ void ThreadMapPort2(void* parg) const char* minissdpdpath = nullptr; struct UPNPDev* devlist = nullptr; char lanaddr[64]; +#if MINIUPNPC_API_VERSION >= 18 + char wanaddr[64]; +#endif int error = 0; #if MINIUPNPC_API_VERSION < 14 @@ -1167,10 +1170,17 @@ void ThreadMapPort2(void* parg) struct IGDdatas data; int r; +#if MINIUPNPC_API_VERSION < 18 r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); +#else + r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr), wanaddr, sizeof(wanaddr)); +#endif if (r == 1) { if (fDiscover) { + // Note that the below is technically duplicative for API version > 18, since the wanaddr is filled out + // by UPNP_GetValidIGD in the internal call to UPNP_GetExternalIPAddress for API version > 18. However, + // it is not harmful to leave the additional separate call here. char externalIPAddress[40]; r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); if(r != UPNPCOMMAND_SUCCESS)