Skip to content

Commit

Permalink
Support miniupnp API version 18+
Browse files Browse the repository at this point in the history
The UPNP_GetValidIGD function has added wanaddr and wanaddr length
parameters for API version 18+.
  • Loading branch information
jamescowens committed Jul 2, 2024
1 parent 95b4c2e commit 64f6eb4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 64f6eb4

Please sign in to comment.