tools: net: support IPv4 and IPv6 addresses
Switch from IPv4-only to an unspecified address family, which will allow
either IPv4 or IPv6 addresses to be used.
Signed-off-by: Benjamin Fair <benjaminfair@google.com>
Change-Id: I6f4d3e71e2a310fc158ec90793f5c7479e060f02
diff --git a/tools/net.cpp b/tools/net.cpp
index 9027862..c971cb8 100644
--- a/tools/net.cpp
+++ b/tools/net.cpp
@@ -81,7 +81,7 @@
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
- hints.ai_family = AF_INET;
+ hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo *addrs, *addr;
diff --git a/tools/test/tools_net_unittest.cpp b/tools/test/tools_net_unittest.cpp
index 51556ff..faf68d0 100644
--- a/tools/test/tools_net_unittest.cpp
+++ b/tools/test/tools_net_unittest.cpp
@@ -64,7 +64,7 @@
sysMock,
getaddrinfo(StrEq(host), StrEq(port),
AllOf(Field(&addrinfo::ai_flags, AI_NUMERICHOST),
- Field(&addrinfo::ai_family, AF_INET),
+ Field(&addrinfo::ai_family, AF_UNSPEC),
Field(&addrinfo::ai_socktype, SOCK_STREAM)),
NotNull()))
.WillOnce(DoAll(SetArgPointee<3>(&addr), Return(0)));
@@ -127,7 +127,7 @@
EXPECT_CALL(sysMock,
getaddrinfo(StrEq(host), StrEq(port),
AllOf(Field(&addrinfo::ai_flags, AI_NUMERICHOST),
- Field(&addrinfo::ai_family, AF_INET),
+ Field(&addrinfo::ai_family, AF_UNSPEC),
Field(&addrinfo::ai_socktype, SOCK_STREAM)),
NotNull()))
.WillOnce(Return(EAI_ADDRFAMILY));