Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/MulticastSocket/SetGetNetworkInterfaceTest.java
41149 views
1
/*
2
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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
import java.io.IOException;
25
import java.io.UncheckedIOException;
26
import java.net.MulticastSocket;
27
import java.net.NetworkInterface;
28
29
import jdk.test.lib.NetworkConfiguration;
30
import jdk.test.lib.net.IPSupport;
31
32
/**
33
* @test
34
* @bug 6458027
35
* @summary Disabling IPv6 on a specific network interface causes problems.
36
* @library /test/lib
37
* @build jdk.test.lib.NetworkConfiguration
38
* jdk.test.lib.Platform
39
* @run main SetGetNetworkInterfaceTest
40
* @run main/othervm -Djava.net.preferIPv4Stack=true SetGetNetworkInterfaceTest
41
*/
42
public class SetGetNetworkInterfaceTest {
43
44
public static void main(String[] args) throws Exception {
45
IPSupport.throwSkippedExceptionIfNonOperational();
46
NetworkConfiguration nc = NetworkConfiguration.probe();
47
try (MulticastSocket ms = new MulticastSocket()) {
48
nc.multicastInterfaces(true).forEach(nif -> setGetNetworkInterface(ms, nif));
49
} catch (IOException e) {
50
e.printStackTrace();
51
}
52
System.out.println("Test passed.");
53
}
54
55
static void setGetNetworkInterface(MulticastSocket ms, NetworkInterface nif) {
56
try {
57
System.out.println(NetworkConfiguration.interfaceInformation(nif));
58
ms.setNetworkInterface(nif);
59
NetworkInterface msNetIf = ms.getNetworkInterface();
60
if (nif.equals(msNetIf)) {
61
System.out.println(" OK");
62
} else {
63
System.out.println("FAILED!!!");
64
System.out.println(NetworkConfiguration.interfaceInformation(msNetIf));
65
throw new RuntimeException("Test Fail");
66
}
67
System.out.println("------------------");
68
} catch (IOException e) {
69
throw new UncheckedIOException(e);
70
}
71
}
72
}
73
74