diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-10-11 00:39:51 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-10-11 00:39:51 -0700 |
commit | ac0ad5dc63f89dfc64f869f0babc1899e01ac867 (patch) | |
tree | ab0e41516319862f5c6b41484bc5cd0338e7bd33 /src/netbase.cpp | |
parent | eb49457ff279721cc3cef10fe68fd75b4aa71833 (diff) | |
parent | 6032e4f4e7c1892a4e3f0a1a2007e4cd0fe99937 (diff) |
Merge pull request #1901 from laanwj/2012_10_remove_strlcpy
get rid of strlcpy.h
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r-- | src/netbase.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp index 95d64939ba..dbf79ab3e0 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -11,8 +11,8 @@ #include <sys/fcntl.h> #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; @@ -119,18 +119,16 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign 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) |