aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Corallo <matt@bluematt.me>2012-02-09 22:41:42 -0500
committerLuke Dashjr <luke-jr+git@utopios.org>2012-02-11 21:25:35 -0500
commit888ac4e7a326986945ca91668c47a3d8fa981d49 (patch)
tree7c1797cd38da7969bb8d8b7a09f598bbb09a6013 /src
parent76e707a44e280e2b0e6df776d16a86df1002ff3b (diff)
Get ext. IP from UPnP, make sure addrMe IsRoutable() in version.
This fixes a potential bug where some NATs may replace the node's interal IP with its external IP in version messages, causing incorrect checksums when version messages begin being checksummed on February 14, 2012.
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp20
-rw-r--r--src/net.h2
2 files changed, 21 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 764246520b..83e7f28c6b 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1103,6 +1103,26 @@ void ThreadMapPort2(void* parg)
r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
if (r == 1)
{
+ if (!addrLocalHost.IsRoutable())
+ {
+ char externalIPAddress[40];
+ r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
+ if(r != UPNPCOMMAND_SUCCESS)
+ printf("UPnP: GetExternalIPAddress() returned %d\n", r);
+ else
+ {
+ if(externalIPAddress[0])
+ {
+ printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
+ CAddress addrExternalFromUPnP(externalIPAddress, 0, false, nLocalServices);
+ if (addrExternalFromUPnP.IsRoutable())
+ addrLocalHost = addrExternalFromUPnP;
+ }
+ else
+ printf("UPnP: GetExternalIPAddress failed.\n");
+ }
+ }
+
string strDesc = "Bitcoin " + FormatFullVersion();
#ifndef UPNPDISCOVER_SUCCESS
/* miniupnpc 1.5 */
diff --git a/src/net.h b/src/net.h
index 52df06f1be..d8b9022276 100644
--- a/src/net.h
+++ b/src/net.h
@@ -355,7 +355,7 @@ public:
/// when NTP implemented, change to just nTime = GetAdjustedTime()
int64 nTime = (fInbound ? GetAdjustedTime() : GetTime());
CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr);
- CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost);
+ CAddress addrMe = (fUseProxy || !addrLocalHost.IsRoutable() ? CAddress("0.0.0.0") : addrLocalHost);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, std::string(pszSubVer), nBestHeight);