fix: fix NetworkInterfaceTests using IPv6 address error.
package com.alibaba.cloud.nacos.registry;
import java.net.Inet4Address;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
@@ -102,7 +103,7 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
Enumeration<InetAddress> inetAddress = netInterface.getInetAddresses();
while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement();
- if (currentAddress instanceof Inet4Address
+ if (currentAddress instanceof Inet4Address || currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress()) {
return currentAddress.getHostAddress();
}
@@ -135,7 +136,7 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
.getInetAddresses();
while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement();
- if (currentAddress instanceof Inet4Address
+ if (currentAddress instanceof Inet4Address || currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress()) {
hasValidNetworkInterface = true;
netWorkInterfaceName = networkInterface.getName();
