< prev index next >

test/jdk/java/net/MulticastSocket/NoLoopbackPackets.java

Print this page
rev 55983 : 8229706: java/net/MulticastSocket/NoLoopbackPackets.java fails on some AIX machines


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4742177
  27  * @library /test/lib
  28  * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
  29  */
  30 import java.util.*;
  31 import java.net.*;

  32 import jdk.test.lib.net.IPSupport;
  33 
  34 public class NoLoopbackPackets {
  35     private static String osname;
  36 
  37     static boolean isWindows() {
  38         if (osname == null)
  39             osname = System.getProperty("os.name");
  40         return osname.contains("Windows");
  41     }
  42 
  43     private static final String MESSAGE = "hello world (" + System.nanoTime() + ")";
  44     public static void main(String[] args) throws Exception {
  45         if (isWindows()) {
  46             System.out.println("The test only run on non-Windows OS. Bye.");
  47             return;
  48         }
  49 
  50         MulticastSocket msock = null;
  51         List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
  52         Sender sender = null;
  53         Thread senderThread = null;
  54         try {
  55             msock = new MulticastSocket();
  56             int port = msock.getLocalPort();
  57 
  58             // we will send packets to three multicast groups :-
  59             // 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
  60             //
  61             List<SocketAddress> groups = new ArrayList<SocketAddress>();
  62             if (IPSupport.hasIPv4()) {
  63                 groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), port));
  64             }
  65             if (IPSupport.hasIPv6()) {



  66                 groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
  67                 groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
  68             }
  69             if (groups.isEmpty()) {
  70                 System.err.println("Nothing to test: there are no network interfaces");
  71             }
  72 
  73             sender = new Sender(groups);
  74             senderThread = new Thread(sender);
  75             senderThread.start();
  76 
  77             // Now try to receive multicast packets. we should not see any of them
  78             // since we disable loopback mode.
  79             //
  80             msock.setSoTimeout(5000);       // 5 seconds
  81 
  82             byte[] buf = new byte[1024];
  83             for (int i = 0; i < buf.length; i++) {
  84                 buf[i] = (byte) 'z';
  85             }




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4742177
  27  * @library /test/lib
  28  * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
  29  */
  30 import java.util.*;
  31 import java.net.*;
  32 import jdk.test.lib.NetworkConfiguration;
  33 import jdk.test.lib.net.IPSupport;
  34 
  35 public class NoLoopbackPackets {
  36     private static String osname;
  37 
  38     static boolean isWindows() {
  39         if (osname == null)
  40             osname = System.getProperty("os.name");
  41         return osname.contains("Windows");
  42     }
  43 
  44     private static final String MESSAGE = "hello world (" + System.nanoTime() + ")";
  45     public static void main(String[] args) throws Exception {
  46         if (isWindows()) {
  47             System.out.println("The test only run on non-Windows OS. Bye.");
  48             return;
  49         }
  50 
  51         MulticastSocket msock = null;
  52         List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
  53         Sender sender = null;
  54         Thread senderThread = null;
  55         try {
  56             msock = new MulticastSocket();
  57             int port = msock.getLocalPort();
  58 
  59             // we will send packets to three multicast groups :-
  60             // 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
  61             //
  62             List<SocketAddress> groups = new ArrayList<SocketAddress>();
  63             if (IPSupport.hasIPv4()) {
  64                 groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), port));
  65             }
  66 
  67             // see also JDK-8207404 where similar checks were added
  68             NetworkConfiguration nc = NetworkConfiguration.probe();
  69             if (IPSupport.hasIPv6() && nc.hasTestableIPv6Address()) {
  70                 groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
  71                 groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
  72             }
  73             if (groups.isEmpty()) {
  74                 System.err.println("Nothing to test: there are no network interfaces");
  75             }
  76 
  77             sender = new Sender(groups);
  78             senderThread = new Thread(sender);
  79             senderThread.start();
  80 
  81             // Now try to receive multicast packets. we should not see any of them
  82             // since we disable loopback mode.
  83             //
  84             msock.setSoTimeout(5000);       // 5 seconds
  85 
  86             byte[] buf = new byte[1024];
  87             for (int i = 0; i < buf.length; i++) {
  88                 buf[i] = (byte) 'z';
  89             }


< prev index next >