p2p, refactor: return std::optional<CNetAddr> in LookupHost

This commit is contained in:
brunoerg
2022-10-11 13:37:45 -03:00
parent 34bcdfc6a6
commit 5c832c3820
12 changed files with 61 additions and 83 deletions

View File

@@ -24,9 +24,7 @@ BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup)
static CNetAddr ResolveIP(const std::string& ip)
{
CNetAddr addr;
LookupHost(ip, addr, false);
return addr;
return LookupHost(ip, false).value_or(CNetAddr{});
}
static CSubNet ResolveSubNet(const std::string& subnet)
@@ -477,11 +475,10 @@ BOOST_AUTO_TEST_CASE(netpermissions_test)
BOOST_AUTO_TEST_CASE(netbase_dont_resolve_strings_with_embedded_nul_characters)
{
CNetAddr addr;
BOOST_CHECK(LookupHost("127.0.0.1"s, addr, false));
BOOST_CHECK(!LookupHost("127.0.0.1\0"s, addr, false));
BOOST_CHECK(!LookupHost("127.0.0.1\0example.com"s, addr, false));
BOOST_CHECK(!LookupHost("127.0.0.1\0example.com\0"s, addr, false));
BOOST_CHECK(LookupHost("127.0.0.1"s, false).has_value());
BOOST_CHECK(!LookupHost("127.0.0.1\0"s, false).has_value());
BOOST_CHECK(!LookupHost("127.0.0.1\0example.com"s, false).has_value());
BOOST_CHECK(!LookupHost("127.0.0.1\0example.com\0"s, false).has_value());
CSubNet ret;
BOOST_CHECK(LookupSubNet("1.2.3.0/24"s, ret));
BOOST_CHECK(!LookupSubNet("1.2.3.0/24\0"s, ret));