From 6032e4f4e7c1892a4e3f0a1a2007e4cd0fe99937 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 2 Oct 2012 21:36:39 +0200 Subject: get rid of strlcpy.h Don't use hand-rolled string manipulation routine with a fixed buffer in the bitcoin core, instead make use of c++ strings and boost. --- src/netbase.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/netbase.cpp') diff --git a/src/netbase.cpp b/src/netbase.cpp index daa8a8d07..05ae056ef 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -10,8 +10,8 @@ #include #endif -#include "strlcpy.h" #include // for to_lower() +#include // for startswith() and endswith() using namespace std; @@ -118,18 +118,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) -- cgit v1.2.3