#include "hash.h"
#ifndef WIN32
+#ifdef ANDROID
+#include <fcntl.h>
+#else
#include <sys/fcntl.h>
#endif
+#endif
+
+#ifdef _MSC_VER
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
-#include "strlcpy.h"
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
+#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
using namespace std;
struct addrinfo *aiTrav = aiRes;
while (aiTrav != NULL && (nMaxSolutions == 0 || vIP.size() < nMaxSolutions))
{
- if (aiTrav->ai_family == AF_INET)
+ switch (aiTrav->ai_family)
{
- assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in));
- vIP.push_back(CNetAddr(((struct sockaddr_in*)(aiTrav->ai_addr))->sin_addr));
- }
+ case (AF_INET):
+ assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in));
+ vIP.push_back(CNetAddr(((struct sockaddr_in*)(aiTrav->ai_addr))->sin_addr));
+ break;
#ifdef USE_IPV6
- if (aiTrav->ai_family == AF_INET6)
- {
- assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
- vIP.push_back(CNetAddr(((struct sockaddr_in6*)(aiTrav->ai_addr))->sin6_addr));
- }
+ case (AF_INET6):
+ assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
+ vIP.push_back(CNetAddr(((struct sockaddr_in6*)(aiTrav->ai_addr))->sin6_addr));
+ break;
#endif
+ }
aiTrav = aiTrav->ai_next;
}
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
{
- if (pszName[0] == 0)
+ std::string str(pszName);
+ std::string strHost = str;
+ if (str.empty())
return false;
- char psz[256];
- char *pszHost = psz;
- strlcpy(psz, pszName, sizeof(psz));
- if (psz[0] == '[' && psz[strlen(psz)-1] == ']')
+ if (boost::algorithm::starts_with(str, "[") && boost::algorithm::ends_with(str, "]"))
{
- pszHost = psz+1;
- psz[strlen(psz)-1] = 0;
+ strHost = str.substr(1, str.size() - 2);
}
- return LookupIntern(pszHost, vIP, nMaxSolutions, fAllowLookup);
+ return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup);
}
bool LookupHostNumeric(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions)
void CNetAddr::Init()
{
- memset(ip, 0, 16);
+ memset(ip, 0, sizeof(ip));
}
void CNetAddr::SetIP(const CNetAddr& ipIn)
nBits = 4;
}
// for he.net, use /36 groups
- else if (GetByte(15) == 0x20 && GetByte(14) == 0x11 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
+ else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
nBits = 36;
// for the rest of the IPv6 network, use /32 groups
else
return vchRet;
}
-uint64 CNetAddr::GetHash() const
+uint64_t CNetAddr::GetHash() const
{
uint256 hash = Hash(&ip[0], &ip[16]);
- uint64 nRet;
+ uint64_t nRet;
memcpy(&nRet, &hash, sizeof(nRet));
return nRet;
}