From 4c0a5886ca10f60b0efff843dd10d4b12d4c6de9 Mon Sep 17 00:00:00 2001 From: norman Date: Wed, 11 Apr 2012 08:09:03 +0200 Subject: [PATCH] Make sure multicast tests pass on all os'es --- .../socket/AbstractDatagramMulticastTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramMulticastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramMulticastTest.java index 607f65bdb5..725c5d25c4 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramMulticastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramMulticastTest.java @@ -28,6 +28,7 @@ import io.netty.channel.socket.DatagramChannelFactory; import io.netty.testsuite.util.TestUtils; import io.netty.util.internal.ExecutorUtil; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.NetworkInterface; import java.util.concurrent.CountDownLatch; @@ -72,7 +73,14 @@ public abstract class AbstractDatagramMulticastTest { int port = TestUtils.getFreePort(); - NetworkInterface iface = NetworkInterface.getNetworkInterfaces().nextElement(); + NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); + + // check if the NetworkInterface is null, this is the case on my ubuntu dev machine but not on osx and windows. + // if so fail back the the first interface + if (iface == null) { + // use nextElement() as NetWorkInterface.getByIndex(0) returns null + iface = NetworkInterface.getNetworkInterfaces().nextElement(); + } sb.setOption("networkInterface", iface); sb.setOption("reuseAddress", true);