aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2011-06-05 07:30:05 -0700
committerJeff Garzik <jgarzik@exmulti.com>2011-06-05 07:30:05 -0700
commit39105dac1b2880970cab3d8f1af969a4b803df01 (patch)
tree51ea99402d8a958551c3ac7cbcb8726a40466e61
parente104c7937455bf2c9b535ec14ea710a97b66750b (diff)
parent482cb6569058423ca952076459f1539a88d70074 (diff)
downloadbitcoin-39105dac1b2880970cab3d8f1af969a4b803df01.tar.xz
Merge pull request #290 from jrmithdobbs/ip-filter-rfc1918-rfc3927
Fix rfc1918 and rfc3927 compliance for ignoring non-internet-routable hosts
-rw-r--r--src/net.cpp3
-rw-r--r--src/net.h24
2 files changed, 21 insertions, 6 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 654fe0cad5..39360a334c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -88,8 +88,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet)
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
#endif
- bool fRoutable = !(addrConnect.GetByte(3) == 10 || (addrConnect.GetByte(3) == 192 && addrConnect.GetByte(2) == 168));
- bool fProxy = (fUseProxy && fRoutable);
+ bool fProxy = (fUseProxy && addrConnect.IsRoutable());
struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());
if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)
diff --git a/src/net.h b/src/net.h
index 6bbcd64e42..d1ded87232 100644
--- a/src/net.h
+++ b/src/net.h
@@ -283,13 +283,29 @@ public:
return (memcmp(pchReserved, pchIPv4, sizeof(pchIPv4)) == 0);
}
+ bool IsRFC1918() const
+ {
+ return IsIPv4() && (GetByte(3) == 10 ||
+ (GetByte(3) == 192 && GetByte(2) == 168) ||
+ (GetByte(3) == 172 &&
+ (GetByte(2) >= 16 && GetByte(2) <= 31)));
+ }
+
+ bool IsRFC3927() const
+ {
+ return IsIPv4() && (GetByte(3) == 169 && GetByte(2) == 254);
+ }
+
+ bool IsLocal() const
+ {
+ return IsIPv4() && (GetByte(3) == 127 ||
+ GetByte(3) == 0);
+ }
+
bool IsRoutable() const
{
return IsValid() &&
- !(GetByte(3) == 10 ||
- (GetByte(3) == 192 && GetByte(2) == 168) ||
- GetByte(3) == 127 ||
- GetByte(3) == 0);
+ !(IsRFC1918() || IsRFC3927() || IsLocal());
}
bool IsValid() const