X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fnetbase.cpp;h=98cdc2702c39f6062e0391b46d63aa52e6740168;hb=a767cdb1f8901b4b3042a6745dc65912b7cc0ebd;hp=3c83b19daa2b9b50c03c9a12e28d927b68d62f5d;hpb=3f2487993dadc31d1512c9598c85581759768568;p=novacoin.git diff --git a/src/netbase.cpp b/src/netbase.cpp index 3c83b19..98cdc27 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -21,8 +21,8 @@ typedef SSIZE_T ssize_t; #endif -#include "strlcpy.h" #include // for to_lower() +#include // for startswith() and endswith() using namespace std; @@ -130,18 +130,16 @@ bool static LookupIntern(const char *pszName, std::vector& vIP, unsign bool LookupHost(const char *pszName, std::vector& 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& vIP, unsigned int nMaxSolutions) @@ -559,7 +557,7 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest void CNetAddr::Init() { - memset(ip, 0, 16); + memset(ip, 0, sizeof(ip)); } void CNetAddr::SetIP(const CNetAddr& ipIn) @@ -906,7 +904,7 @@ std::vector CNetAddr::GetGroup() const 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