InetUtils doesn't return IPv6 addresses
Describe the bug
I'm using version 2.1.4. In the function InetUtils.findFirstNonLoopbackAddress, the code only seems to return IPv4 addresses. I believe this code is incorrect, since most systems have multiple IP addresses. In my case, my system has multiple interfaces, each of which has one 1 IPv4 address, and multiple IPv6 addresses. The snippet of interest:
if (!ignoreInterface(ifc.getDisplayName())) {
for (Enumeration<InetAddress> addrs = ifc
.getInetAddresses(); addrs.hasMoreElements();) {
InetAddress address = addrs.nextElement();
if (address instanceof Inet4Address
&& !address.isLoopbackAddress()
&& isPreferredAddress(address)) {
this.log.trace("Found non-loopback interface: " + ifc.getDisplayName());
result = address;
}
}
}
It's probably not as simple as removing the instanceof check, since many programs are not yet ready for IPv6 usage. However, I think making it possible (via configuration perhaps) to return IPv6 addresses would ease the transition from a pure IPv4 only world to a dual stack world.
Longer term, it would be nice to make the HostInfo class, which encapsulates the address, able to express multiple addresses. This would make the code align with realistic networking configuration, where the hosts typically do have multiple addresses.
Host info is used as a means to make a guess at what host name or ip address to use to register in service discovery. Having multiple addresses doesn't make much sense. Supporting ipv6 is certainly a possibility. Let's see what the community thinks.