|
|
@ -19,27 +19,19 @@ |
|
|
|
#include "UPnP.h" |
|
|
|
#include "UPnP.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
#include "RouterInfo.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <miniupnpc/miniupnpc.h> |
|
|
|
#include <miniupnpc/miniupnpc.h> |
|
|
|
#include <miniupnpc/upnpcommands.h> |
|
|
|
#include <miniupnpc/upnpcommands.h> |
|
|
|
|
|
|
|
|
|
|
|
// These are per-process and are safe to reuse for all threads
|
|
|
|
// These are per-process and are safe to reuse for all threads
|
|
|
|
#ifndef UPNPDISCOVER_SUCCESS |
|
|
|
decltype(upnpDiscover) *upnpDiscoverFunc; |
|
|
|
/* miniupnpc 1.5 */ |
|
|
|
decltype(UPNP_AddPortMapping) *UPNP_AddPortMappingFunc; |
|
|
|
UPNPDev* (*upnpDiscoverFunc) (int, const char *, const char *, int); |
|
|
|
decltype(UPNP_GetValidIGD) *UPNP_GetValidIGDFunc; |
|
|
|
int (*UPNP_AddPortMappingFunc) (const char *, const char *, const char *, const char *, |
|
|
|
decltype(UPNP_GetExternalIPAddress) *UPNP_GetExternalIPAddressFunc; |
|
|
|
const char *, const char *, const char *, const char *); |
|
|
|
decltype(UPNP_DeletePortMapping) *UPNP_DeletePortMappingFunc; |
|
|
|
#else |
|
|
|
decltype(freeUPNPDevlist) *freeUPNPDevlistFunc; |
|
|
|
/* miniupnpc 1.6 */ |
|
|
|
decltype(FreeUPNPUrls) *FreeUPNPUrlsFunc; |
|
|
|
UPNPDev* (*upnpDiscoverFunc) (int, const char *, const char *, int, int, int *); |
|
|
|
|
|
|
|
int (*UPNP_AddPortMappingFunc) (const char *, const char *, const char *, const char *, |
|
|
|
|
|
|
|
const char *, const char *, const char *, const char *, const char *); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
int (*UPNP_GetValidIGDFunc) (struct UPNPDev *, struct UPNPUrls *, struct IGDdatas *, char *, int); |
|
|
|
|
|
|
|
int (*UPNP_GetExternalIPAddressFunc) (const char *, const char *, char *); |
|
|
|
|
|
|
|
int (*UPNP_DeletePortMappingFunc) (const char *, const char *, const char *, const char *, const char *); |
|
|
|
|
|
|
|
void (*freeUPNPDevlistFunc) (struct UPNPDev *); |
|
|
|
|
|
|
|
void (*FreeUPNPUrlsFunc) (struct UPNPUrls *); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Nice approach http://stackoverflow.com/a/21517513/673826
|
|
|
|
// Nice approach http://stackoverflow.com/a/21517513/673826
|
|
|
|
template<class M, typename F> |
|
|
|
template<class M, typename F> |
|
|
@ -109,7 +101,8 @@ namespace transport |
|
|
|
|
|
|
|
|
|
|
|
void UPnP::Run () |
|
|
|
void UPnP::Run () |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& address : context.GetRouterInfo ().GetAddresses ()) |
|
|
|
std::vector<data::RouterInfo::Address> a = context.GetRouterInfo().GetAddresses(); |
|
|
|
|
|
|
|
for (auto& address : a) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!address.host.is_v6 ()) |
|
|
|
if (!address.host.is_v6 ()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -134,7 +127,11 @@ namespace transport |
|
|
|
#else |
|
|
|
#else |
|
|
|
/* miniupnpc 1.6 */ |
|
|
|
/* miniupnpc 1.6 */ |
|
|
|
int nerror = 0; |
|
|
|
int nerror = 0; |
|
|
|
m_Devlist = upnpDiscoverFunc (2000, m_MulticastIf, m_Minissdpdpath, 0, 0, &nerror); |
|
|
|
#if MINIUPNPC_API_VERSION >= 15 |
|
|
|
|
|
|
|
m_Devlist = upnpDiscoverFunc(2000, m_MulticastIf, m_Minissdpdpath, 0, 0, 0, &nerror); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
m_Devlist = upnpDiscoverFunc(2000, m_MulticastIf, m_Minissdpdpath, 0, 0, &nerror); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
int r; |
|
|
|
int r; |
|
|
|