Fix rfc1918 and rfc3927 compliance for ignoring non-internet-routable hosts.
This commit is contained in:
parent
e104c79374
commit
482cb65690
|
@ -88,8 +88,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet)
|
||||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool fRoutable = !(addrConnect.GetByte(3) == 10 || (addrConnect.GetByte(3) == 192 && addrConnect.GetByte(2) == 168));
|
bool fProxy = (fUseProxy && addrConnect.IsRoutable());
|
||||||
bool fProxy = (fUseProxy && fRoutable);
|
|
||||||
struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());
|
struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());
|
||||||
|
|
||||||
if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)
|
if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)
|
||||||
|
|
24
src/net.h
24
src/net.h
|
@ -283,13 +283,29 @@ public:
|
||||||
return (memcmp(pchReserved, pchIPv4, sizeof(pchIPv4)) == 0);
|
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
|
bool IsRoutable() const
|
||||||
{
|
{
|
||||||
return IsValid() &&
|
return IsValid() &&
|
||||||
!(GetByte(3) == 10 ||
|
!(IsRFC1918() || IsRFC3927() || IsLocal());
|
||||||
(GetByte(3) == 192 && GetByte(2) == 168) ||
|
|
||||||
GetByte(3) == 127 ||
|
|
||||||
GetByte(3) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValid() const
|
bool IsValid() const
|
||||||
|
|
Loading…
Reference in New Issue