Skip to content

Commit 4c6b210

Browse files
committed
Fix netbase tests
* Do not rely on "a.b.c" being interpreted as "a.0.b.c" * Parse numeric addresses for address families for which no device is configured
1 parent c5532e1 commit 4c6b210

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/netbase.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
6565
#ifdef WIN32
6666
# ifdef USE_IPV6
6767
aiHint.ai_family = AF_UNSPEC;
68-
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
6968
# else
7069
aiHint.ai_family = AF_INET;
71-
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
7270
# endif
71+
aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
7372
#else
7473
# ifdef USE_IPV6
7574
aiHint.ai_family = AF_UNSPEC;
76-
aiHint.ai_flags = AI_ADDRCONFIG | (fAllowLookup ? 0 : AI_NUMERICHOST);
7775
# else
7876
aiHint.ai_family = AF_INET;
79-
aiHint.ai_flags = AI_ADDRCONFIG | (fAllowLookup ? 0 : AI_NUMERICHOST);
8077
# endif
78+
aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
8179
#endif
8280
struct addrinfo *aiRes = NULL;
8381
int nErr = getaddrinfo(pszName, NULL, &aiHint, &aiRes);

src/test/netbase_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ BOOST_AUTO_TEST_CASE(netbase_lookupnumeric)
8686
BOOST_CHECK(TestParse("[::]:8333", "[::]:8333"));
8787
BOOST_CHECK(TestParse("[127.0.0.1]", "127.0.0.1:65535"));
8888
BOOST_CHECK(TestParse(":::", ""));
89-
BOOST_CHECK(TestParse("128.5.1", "128.5.0.1:65535"));
9089
}
9190

9291
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)