test/jdk/java/net/MulticastSocket/Promiscuous.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 55475 6ca3526c4e25
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     1
/*
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     4
 *
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     8
 *
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    13
 * accompanied this code).
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    14
 *
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    18
 *
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    21
 * questions.
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    22
 *
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    23
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    24
/* @test
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    25
 * @bug 8014499 8219804
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    26
 * @library /test/lib
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    27
 * @summary Test for interference when two sockets are bound to the same
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    28
 *          port but joined to different multicast groups
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    29
 * @run main Promiscuous
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    30
 * @run main/othervm -Djava.net.preferIPv4Stack=true Promiscuous
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    31
 */
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    32
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    33
import java.io.IOException;
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    34
import static java.lang.System.out;
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    35
import java.net.*;
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 47216
diff changeset
    36
import jdk.test.lib.net.IPSupport;
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    37
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    38
public class Promiscuous {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    39
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    40
    static final int TIMEOUT =  5 * 1000; // 5 secs
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    41
    static int id = 1000;
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    42
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    43
    static void receive(MulticastSocket mc, boolean datagramExpected, int id)
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    44
        throws IOException
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    45
    {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    46
        byte[] ba = new byte[100];
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    47
        DatagramPacket p;
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    48
        try {
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    49
            String data = null;
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    50
            while (true) {
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    51
                p = new DatagramPacket(ba, ba.length);
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    52
                mc.receive(p);
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    53
                data = new String(p.getData(), 0, p.getLength(), "UTF-8");
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    54
                if (data.length() > UUID.length() && data.startsWith(UUID)) {
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    55
                    data = data.substring(UUID.length());
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    56
                    break;
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    57
                }
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    58
                logUnexpected(p);
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    59
            }
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    60
            int recvId = Integer.parseInt(data);
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    61
            if (datagramExpected) {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    62
                if (recvId != id)
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    63
                    throw new RuntimeException("Unexpected id, got " + recvId
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    64
                                               + ", expected: " + id);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    65
                out.printf("Received message as expected, %s\n", p.getAddress());
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    66
            } else {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    67
                throw new RuntimeException("Unexpected message received, "
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    68
                                           + p.getAddress());
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    69
            }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    70
        } catch (SocketTimeoutException e) {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    71
            if (datagramExpected)
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    72
                throw new RuntimeException("Expected message not received, "
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    73
                                            + e.getMessage());
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    74
            else
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    75
                out.printf("Message not received, as expected\n");
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    76
        }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    77
    }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    78
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    79
    static void logUnexpected(DatagramPacket p) {
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    80
        byte[] ba = p.getData();
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    81
        System.out.printf("Unexpected packet: length: %d. First three bytes: %d, %d, %d\n",
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    82
                          p.getLength(), ba[0], ba[1], ba[2]);
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    83
    }
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    84
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    85
    static final String UUID; // process-id : currentTimeMillis
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    86
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    87
    static {
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    88
        String s1 = Long.toString(ProcessHandle.current().pid());
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    89
        String s2 = Long.toString(System.currentTimeMillis());
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    90
        UUID = "<" + s1 + s2 + ">";
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    91
    }
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
    92
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    93
    static void test(InetAddress group1, InetAddress group2)
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    94
        throws IOException
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    95
    {
55475
6ca3526c4e25 8226683: Remove review suggestion from fix to 8219804
michaelm
parents: 55474
diff changeset
    96
        try (MulticastSocket mc1 = new MulticastSocket();
6ca3526c4e25 8226683: Remove review suggestion from fix to 8219804
michaelm
parents: 55474
diff changeset
    97
             MulticastSocket mc2 = new MulticastSocket(mc1.getLocalPort());
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    98
             DatagramSocket ds = new DatagramSocket()) {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
    99
            final int port = mc1.getLocalPort();
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   100
            out.printf("Using port: %d\n", port);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   101
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   102
            mc1.setSoTimeout(TIMEOUT);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   103
            mc2.setSoTimeout(TIMEOUT);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   104
            int nextId = id;
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
   105
            byte[] msg = (UUID + Integer.toString(nextId)).getBytes("UTF-8");
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   106
            DatagramPacket p = new DatagramPacket(msg, msg.length);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   107
            p.setAddress(group1);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   108
            p.setPort(port);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   109
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   110
            mc1.joinGroup(group1);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   111
            out.printf("mc1 joined the MC group: %s\n", group1);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   112
            mc2.joinGroup(group2);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   113
            out.printf("mc2 joined the MC group: %s\n", group2);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   114
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   115
            out.printf("Sending datagram to: %s/%d\n", group1, port);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   116
            ds.send(p);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   117
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   118
            // the packet should be received by mc1 only
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   119
            receive(mc1, true, nextId);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   120
            receive(mc2, false, 0);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   121
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   122
            nextId = ++id;
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
   123
            msg = (UUID + Integer.toString(nextId)).getBytes("UTF-8");
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   124
            p = new DatagramPacket(msg, msg.length);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   125
            p.setAddress(group2);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   126
            p.setPort(port);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   127
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   128
            out.printf("Sending datagram to: %s/%d\n", group2, port);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   129
            ds.send(p);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   130
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   131
            // the packet should be received by mc2 only
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   132
            receive(mc2, true, nextId);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   133
            receive(mc1, false, 0);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   134
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   135
            mc1.leaveGroup(group1);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   136
            mc2.leaveGroup(group2);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   137
        }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   138
    }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   139
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   140
    public static void main(String args[]) throws IOException {
54811
9db7c0f561a6 8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents: 54770
diff changeset
   141
        IPSupport.throwSkippedExceptionIfNonOperational();
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   142
        String os = System.getProperty("os.name");
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   143
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   144
        // Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   145
        // on older kernels. Note that we skip on <= version 3 to keep the
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   146
        // parsing simple
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   147
        if (os.equals("Linux")) {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   148
            String osversion = System.getProperty("os.version");
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   149
            String[] vers = osversion.split("\\.", 0);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   150
            int major = Integer.parseInt(vers[0]);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   151
            if (major < 3) {
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   152
                System.out.format("Kernel version is %s, test skipped%n", osversion);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   153
                return;
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   154
            }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   155
        }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   156
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   157
        // multicast groups used for the test
55474
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
   158
        InetAddress ip4Group1 = InetAddress.getByName("224.0.0.120");
73250862f818 8219804: java/net/MulticastSocket/Promiscuous.java fails intermittently due to NumberFormatException
michaelm
parents: 54811
diff changeset
   159
        InetAddress ip4Group2 = InetAddress.getByName("224.0.0.121");
18534
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   160
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   161
        test(ip4Group1, ip4Group2);
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   162
    }
2d131cf5db63 8014499: MulticastSocket should enable IP_MULTICAST_ALL (lnx)
chegar
parents:
diff changeset
   163
}