diff options
-rw-r--r-- | NorthstarDedicatedTest/NetAdr2.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/NorthstarDedicatedTest/NetAdr2.cpp b/NorthstarDedicatedTest/NetAdr2.cpp index edf2d180..1a44390b 100644 --- a/NorthstarDedicatedTest/NetAdr2.cpp +++ b/NorthstarDedicatedTest/NetAdr2.cpp @@ -224,12 +224,18 @@ bool CNetAdr2::SetFromSockadr(sockaddr_storage* s) //----------------------------------------------------------------------------- std::string CNetAdr2::GetBase(void) const { - std::string svIpAdr = m_svip; - static std::regex rx("\\].*"); - svIpAdr.erase(0, 1); - svIpAdr = std::regex_replace(svIpAdr, rx, ""); + static std::regex rx("[^\\[]*.(.*)(\\]).*"); + std::smatch smRegexMatches; + std::regex_search(m_svip, smRegexMatches, rx); - return svIpAdr; + if (smRegexMatches.size() > 0) + { + return smRegexMatches[1].str(); + } + else + { + return "127.0.0.1"; + } } //----------------------------------------------------------------------------- @@ -238,11 +244,18 @@ std::string CNetAdr2::GetBase(void) const //----------------------------------------------------------------------------- std::string CNetAdr2::GetBase(std::string svInAdr) const { - static std::regex rx("\\].*"); - svInAdr.erase(0, 1); - svInAdr = std::regex_replace(svInAdr, rx, ""); + static std::regex rx("[^\\[]*.(.*)(\\]).*"); + std::smatch smRegexMatches; + std::regex_search(svInAdr, smRegexMatches, rx); - return svInAdr; + if (smRegexMatches.size() > 0) + { + return smRegexMatches[1].str(); + } + else + { + return "127.0.0.1"; + } } //----------------------------------------------------------------------------- |