test/jdk/java/net/MulticastSocket/SetLoopbackOption.java
author dfuchs
Fri, 22 Nov 2019 11:52:48 +0000
changeset 59224 55fdee124e89
permissions -rw-r--r--
8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP Summary: MulticastSocket.getOption(StandardSocketOption.IP_MULTICAST_LOOP) now returns true if loopback mode is enabled, and MulticastSocket.setOption(StandardSocketOption.IP_MULTICAST_LOOP, true) enables loopback mode. No other behavioral changes. Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59224
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     1
/*
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     4
 *
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     8
 *
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    14
 *
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    18
 *
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    21
 * questions.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    22
 */
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    23
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    24
/*
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    25
 * @test
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    26
 * @bug 8233296
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    27
 * @summary Check that MulticastSocket::setOption and MulticastSocket::getOption
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    28
 *          return the correct result for StandardSocketOptions.IP_MULTICAST_LOOP.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    29
 *          The test sets a DatagramSocketImplFactory and needs to run in /othervm
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    30
 *          mode.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    31
 * @run testng/othervm SetLoopbackOption
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    32
 * @run testng/othervm -Djava.net.preferIPv4Stack=true SetLoopbackOption
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    33
 * @run testng/othervm -Djava.net.preferIPv6Addresses=true SetLoopbackOption
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    34
 */
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    35
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    36
import java.io.FileDescriptor;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    37
import java.io.IOException;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    38
import java.net.DatagramPacket;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    39
import java.net.DatagramSocket;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    40
import java.net.DatagramSocketImpl;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    41
import java.net.DatagramSocketImplFactory;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    42
import java.net.InetAddress;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    43
import java.net.InetSocketAddress;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    44
import java.net.MulticastSocket;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    45
import java.net.NetworkInterface;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    46
import java.net.SocketAddress;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    47
import java.net.SocketException;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    48
import java.net.SocketOption;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    49
import java.net.SocketOptions;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    50
import java.net.StandardSocketOptions;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    51
import java.util.HashMap;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    52
import java.util.Map;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    53
import java.util.Set;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    54
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    55
import org.testng.annotations.Test;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    56
import static org.testng.Assert.*;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    57
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    58
import static java.lang.System.out;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    59
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    60
public class SetLoopbackOption {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    61
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    62
    final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    63
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    64
    @Test
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    65
    public void run() throws Exception {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    66
        var bindAddress = new InetSocketAddress(loopbackAddress, 0);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    67
        try (MulticastSocket sock = new MulticastSocket(null)) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    68
            out.println("Testing unbound socket");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    69
            test(sock, null);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    70
            out.printf("\nBinding socket to %s and testing again%n", bindAddress);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    71
            sock.bind(bindAddress);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    72
            test(sock, null);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    73
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    74
        TestDatagramSocketImplFactory factory = new TestDatagramSocketImplFactory();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    75
        DatagramSocket.setDatagramSocketImplFactory(factory);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    76
        try (MulticastSocket sock = new MulticastSocket(null)) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    77
            out.println("\nTesting unbound socket with custom impl");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    78
            TestDatagramSocketImpl impl = factory.last;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    79
            test(sock, impl);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    80
            out.printf("\nBinding socket to %s and testing again%n", bindAddress);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    81
            sock.bind(new InetSocketAddress(loopbackAddress, 0));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    82
            test(sock, impl);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    83
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    84
    }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    85
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    86
    private void test(MulticastSocket sock, TestDatagramSocketImpl impl) throws Exception {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    87
        out.println("Testing with " + sock.getClass() + (impl == null ? "" : ", " + impl.getClass()));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    88
        var op = StandardSocketOptions.IP_MULTICAST_LOOP;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    89
        var opId = SocketOptions.IP_MULTICAST_LOOP;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    90
        boolean enable = sock.getOption(op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    91
        assertTrue(enable, "Initial Value for " + op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    92
        boolean disable = sock.getLoopbackMode();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    93
        assertFalse(disable, "Initial Value for getLoopbackMode()");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    94
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    95
            assertFalse((Boolean)impl.getOption(opId));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    96
            assertTrue((Boolean)impl.getOption(op));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    97
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    98
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
    99
        out.println("Setting " + op + " to " + false);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   100
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   101
            // allows setOption(SocketOption, Object) to be called
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   102
            impl.allowAllSetOptions(true);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   103
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   104
        sock.setOption(op, false);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   105
        enable = sock.getOption(op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   106
        assertFalse(enable, "Value for " + op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   107
        disable = sock.getLoopbackMode();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   108
        assertTrue(disable, "Value for getLoopbackMode()");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   109
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   110
            assertTrue((Boolean)impl.getOption(opId));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   111
            assertFalse((Boolean)impl.getOption(op));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   112
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   113
        out.println("Setting " + op + " to " + true);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   114
        sock.setOption(op, true);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   115
        enable = sock.getOption(op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   116
        assertTrue(enable, "Value for " + op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   117
        disable = sock.getLoopbackMode();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   118
        assertFalse(disable, "Value for getLoopbackMode()");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   119
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   120
            assertFalse((Boolean)impl.getOption(opId));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   121
            assertTrue((Boolean)impl.getOption(op));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   122
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   123
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   124
        out.println("Calling setLoopbackMode(true)");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   125
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   126
            // for backward compatibility reason, setLoopbackMode
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   127
            // should call setOption(int, Object), not setOption(SocketOption, Object)
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   128
            // Make sure that an exception is thrown if the latter is ever called.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   129
            impl.allowAllSetOptions(false);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   130
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   131
        sock.setLoopbackMode(true);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   132
        enable = sock.getOption(op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   133
        assertFalse(enable, "Value for " + op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   134
        disable = sock.getLoopbackMode();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   135
        assertTrue(disable, "Value for getLoopbackMode()");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   136
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   137
            assertTrue((Boolean)impl.getOption(opId));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   138
            assertFalse((Boolean)impl.getOption(op));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   139
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   140
        out.println("Calling setLoopbackMode(false)");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   141
        sock.setLoopbackMode(false);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   142
        enable = sock.getOption(op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   143
        assertTrue(enable, "Value for " + op);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   144
        disable = sock.getLoopbackMode();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   145
        assertFalse(disable, "Value for getLoopbackMode()");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   146
        if (impl != null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   147
            assertFalse((Boolean)impl.getOption(opId));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   148
            assertTrue((Boolean)impl.getOption(op));
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   149
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   150
    }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   151
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   152
    // Used to attempt to control what is called/passed to the impl.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   153
    static class TestDatagramSocketImplFactory implements DatagramSocketImplFactory {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   154
        TestDatagramSocketImpl last;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   155
        public synchronized DatagramSocketImpl createDatagramSocketImpl() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   156
            TestDatagramSocketImpl last = this.last;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   157
            if (last == null) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   158
                return (last = this.last = new TestDatagramSocketImpl());
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   159
            } else {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   160
                throw new AssertionError("Only one instance should be created");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   161
            }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   162
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   163
    }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   164
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   165
    // Used to attempt to control what is called/passed to the impl.
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   166
    static class TestDatagramSocketImpl extends DatagramSocketImpl {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   167
        InetAddress address;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   168
        private boolean allowAllSetOptions;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   169
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   170
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   171
        protected void create() throws SocketException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   172
            legacyOptions.put(SocketOptions.IP_MULTICAST_LOOP, false);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   173
            options.put(StandardSocketOptions.IP_MULTICAST_LOOP, true);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   174
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   175
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   176
        final Map<Integer, Object> legacyOptions = new HashMap<>();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   177
        final Map<SocketOption<?>, Object> options = new HashMap<>();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   178
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   179
        static <T> T shouldNotComeHere() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   180
            throw new AssertionError("should not come here");
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   181
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   182
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   183
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   184
        protected void bind(int lport, InetAddress laddr) throws SocketException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   185
            this.localPort = (lport == 0 ? 6789 : lport);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   186
            this.address = laddr;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   187
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   188
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   189
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   190
        protected void send(DatagramPacket p) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   191
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   192
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   193
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   194
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   195
        protected int peek(InetAddress i) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   196
            return shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   197
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   198
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   199
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   200
        protected int peekData(DatagramPacket p) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   201
            return shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   202
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   203
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   204
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   205
        protected void receive(DatagramPacket p) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   206
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   207
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   208
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   209
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   210
        protected void setTTL(byte ttl) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   211
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   212
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   213
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   214
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   215
        protected byte getTTL() throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   216
            return shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   217
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   218
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   219
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   220
        protected void setTimeToLive(int ttl) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   221
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   222
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   223
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   224
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   225
        protected int getTimeToLive() throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   226
            return shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   227
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   228
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   229
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   230
        protected void join(InetAddress inetaddr) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   231
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   232
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   233
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   234
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   235
        protected void leave(InetAddress inetaddr) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   236
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   237
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   238
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   239
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   240
        protected void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   241
                throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   242
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   243
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   244
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   245
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   246
        protected void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   247
                throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   248
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   249
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   250
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   251
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   252
        protected void close() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   253
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   254
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   255
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   256
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   257
        public void setOption(int optID, Object value) throws SocketException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   258
            legacyOptions.put(optID, value);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   259
            if (optID == SocketOptions.IP_MULTICAST_LOOP) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   260
                boolean disable = (Boolean) value;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   261
                options.put(StandardSocketOptions.IP_MULTICAST_LOOP, !disable);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   262
            }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   263
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   264
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   265
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   266
        public Object getOption(int optID) throws SocketException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   267
            return legacyOptions.get(optID);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   268
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   269
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   270
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   271
        protected Set<SocketOption<?>> supportedOptions() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   272
            return Set.of(StandardSocketOptions.IP_MULTICAST_LOOP);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   273
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   274
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   275
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   276
        protected void connect(InetAddress address, int port) throws SocketException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   277
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   278
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   279
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   280
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   281
        protected void disconnect() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   282
            shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   283
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   284
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   285
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   286
        protected FileDescriptor getFileDescriptor() {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   287
            return super.getFileDescriptor();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   288
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   289
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   290
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   291
        protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   292
            if (!allowAllSetOptions) shouldNotComeHere();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   293
            options.put(name, value);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   294
            if (name.equals(StandardSocketOptions.IP_MULTICAST_LOOP)) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   295
                boolean enable = (Boolean)value;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   296
                legacyOptions.put(SocketOptions.IP_MULTICAST_LOOP, !enable);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   297
            }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   298
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   299
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   300
        @Override
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   301
        protected <T> T getOption(SocketOption<T> name) throws IOException {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   302
            return (T) options.get(name);
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   303
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   304
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   305
        public void allowAllSetOptions(boolean allow) {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   306
            this.allowAllSetOptions = allow;
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   307
        }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   308
    }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   309
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   310
    public static void main (String args[]) throws Exception {
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   311
        new SetLoopbackOption().run();
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   312
    }
55fdee124e89 8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP
dfuchs
parents:
diff changeset
   313
}