--- namecoin-nc0.3.75/src/net.cpp +++ namecoin-nc0.3.75/src/net.cpp.new @@ -19,10 +19,10 @@ #endif #ifdef USE_UPNP -#include -#include -#include -#include +#include +#include +#include +#include #endif using namespace std; @@ -1088,8 +1088,7 @@ { printf("ThreadMapPort started\n"); - char port[6]; - sprintf(port, "%d", GetListenPort()); + std::string port = strprintf("%u", GetListenPort()); const char * rootdescurl = 0; const char * multicastif = 0; @@ -1113,25 +1112,26 @@ r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); if (r == 1) { - char intClient[16]; - char intPort[6]; + string strDesc = "Namecoin " + FormatFullVersion(); -#if !defined(__WXMSW__) && !defined(MAC_OSX) +#ifndef UPNPDISCOVER_SUCCESS + /* miniupnpc 1.5 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, 0, "TCP", 0); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0); #else + /* miniupnpc 1.6 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, 0, "TCP", 0, "0"); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0"); #endif if(r!=UPNPCOMMAND_SUCCESS) printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", - port, port, lanaddr, r, strupnperror(r)); + port.c_str(), port.c_str(), lanaddr, r, strupnperror(r)); else printf("UPnP Port Mapping successful.\n"); loop { if (fShutdown || !fUseUPnP) { - r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port, "TCP", 0); + r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); printf("UPNP_DeletePortMapping() returned : %d\n", r); freeUPNPDevlist(devlist); devlist = 0; FreeUPNPUrls(&urls);