Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/net/MulticastSocket/SetOutgoingIf.java
          +++ new/test/java/net/MulticastSocket/SetOutgoingIf.java
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   * or visit www.oracle.com if you need additional information or have any
  21   21   * questions.
  22   22   */
  23   23  
  24   24  /*
  25   25   * @test
  26   26   * @bug 4742177
  27   27   * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
  28   28   */
  29   29  import java.net.*;
  30      -import java.util.concurrent.*;
  31   30  import java.util.*;
  32   31  
  33   32  
  34   33  public class SetOutgoingIf {
  35   34      private static int PORT = 9001;
  36   35      private static String osname;
  37   36  
  38   37      static boolean isWindows() {
  39   38          if (osname == null)
  40   39              osname = System.getProperty("os.name");
↓ open down ↓ 22 lines elided ↑ open up ↑
  63   62  
  64   63          if (!hasIPv6()) {
  65   64              System.out.println("No IPv6 available. Bye.");
  66   65              return;
  67   66          }
  68   67  
  69   68          // We need 2 or more network interfaces to run the test
  70   69          //
  71   70          List<NetworkInterface> nics = new ArrayList<NetworkInterface>();
  72   71          for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
  73      -            if (!nic.isLoopback())
       72 +            // we should use only network interfaces with multicast support which are in "up" state
       73 +            if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp())
  74   74                  nics.add(nic);
  75   75          }
  76   76          if (nics.size() <= 1) {
  77   77              System.out.println("Need 2 or more network interfaces to run. Bye.");
  78   78              return;
  79   79          }
  80   80  
  81   81          // We will send packets to one ipv4, one ipv4-mapped, and one ipv6
  82   82          // multicast group using each network interface :-
  83   83          //      224.1.1.1        --|
↓ open down ↓ 81 lines elided ↑ open up ↑
 165  165              DatagramPacket packet2 = new DatagramPacket(buf, buf.length,
 166  166                                          new InetSocketAddress(group2, port));
 167  167              DatagramPacket packet3 = new DatagramPacket(buf, buf.length,
 168  168                                          new InetSocketAddress(group3, port));
 169  169  
 170  170              for (;;) {
 171  171                  mcastsock.send(packet1);
 172  172                  mcastsock.send(packet2);
 173  173                  mcastsock.send(packet3);
 174  174  
 175      -                Thread.currentThread().sleep(1000);   // sleep 1 second
      175 +                Thread.sleep(1000);   // sleep 1 second
 176  176              }
 177  177          } catch (Exception e) {
 178  178              throw new RuntimeException(e);
 179  179          }
 180  180      }
 181  181  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX