aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorMatt Corallo <matt@bluematt.me>2012-02-09 22:41:42 -0500
committerMatt Corallo <matt@bluematt.me>2012-02-10 00:54:11 -0500
commitbaba6e7de28940a8f4cc907d57d2ea5b780d39ea (patch)
tree04bce51d6b43395f40c54bc918156652f7e38dea /src/net.cpp
parent328b26d40b2ea046144a487a6b4927a630e91fb9 (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/net.cpp')
-rw-r--r--src/net.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index f0ea5506e2..63829d0e0a 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -530,7 +530,7 @@ void CNode::PushVersion()
/// when NTP implemented, change to just nTime = GetAdjustedTime()
int64 nTime = (fInbound ? GetAdjustedTime() : GetTime());
CAddress addrYou = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addr);
- CAddress addrMe = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addrLocalHost);
+ CAddress addrMe = (fUseProxy || !addrLocalHost.IsRoutable() ? CAddress(CService("0.0.0.0",0)) : addrLocalHost);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight);
@@ -965,6 +965,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(CService(externalIPAddress, 0), nLocalServices);
+ if (addrExternalFromUPnP.IsRoutable())
+ addrLocalHost = addrExternalFromUPnP;
+ }
+ else
+ printf("UPnP: GetExternalIPAddress failed.\n");
+ }
+ }
+
string strDesc = "Bitcoin " + FormatFullVersion();
#ifndef UPNPDISCOVER_SUCCESS
/* miniupnpc 1.5 */