[ISSUE #5512] Skip the unnecessary network interfaces. (#5513)

This commit is contained in:
echooymxq
2022-11-13 18:02:32 +08:00
committed by GitHub
parent 48ed898071
commit 407d2738f2
2 changed files with 6 additions and 4 deletions
@@ -95,12 +95,12 @@ public class NetworkUtil {
ArrayList<String> ipv4Result = new ArrayList<>();
ArrayList<String> ipv6Result = new ArrayList<>();
while (enumeration.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration.nextElement();
if (isBridge(networkInterface)) {
final NetworkInterface nif = enumeration.nextElement();
if (isBridge(nif) || nif.isVirtual() || nif.isPointToPoint() || !nif.isUp()) {
continue;
}
final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
final Enumeration<InetAddress> en = nif.getInetAddresses();
while (en.hasMoreElements()) {
final InetAddress address = en.nextElement();
if (!address.isLoopbackAddress()) {
@@ -16,6 +16,7 @@
*/
package org.apache.rocketmq.common;
import java.net.InetAddress;
import org.apache.rocketmq.common.utils.NetworkUtil;
import org.junit.Test;
@@ -23,10 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
public class NetworkUtilTest {
@Test
public void testGetLocalAddress() throws Exception {
public void testGetLocalAddress() {
String localAddress = NetworkUtil.getLocalAddress();
assertThat(localAddress).isNotNull();
assertThat(localAddress.length()).isGreaterThan(0);
assertThat(localAddress).isNotEqualTo(InetAddress.getLoopbackAddress().getHostAddress());
}
@Test