Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/MulticastSocket/TestInterfaces.java
38811 views
1
/*
2
* Copyright (c) 2001, 2013, 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
/*
25
* @test
26
* @bug 4422122
27
* @summary Test that MulticastSocket.getInterface returns the
28
* same InetAddress set by MulticastSocket.setInterface
29
*/
30
import java.net.*;
31
import java.util.Enumeration;
32
import java.io.IOException;
33
34
public class TestInterfaces {
35
36
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
37
38
public static void main(String args[]) throws Exception {
39
int failures = 0;
40
41
MulticastSocket soc = new MulticastSocket();
42
43
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
44
while (nifs.hasMoreElements()) {
45
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
46
47
/*
48
* Test MulticastSocket.getInterface
49
*/
50
Enumeration addrs = ni.getInetAddresses();
51
while (addrs.hasMoreElements()) {
52
InetAddress ia = (InetAddress)addrs.nextElement();
53
54
System.out.println("********************************");
55
System.out.println("MulticastSocket.setInterface(" + ia + ")");
56
57
try {
58
soc.setInterface(ia);
59
} catch (IOException ioe) {
60
System.err.println("Can't set interface to: " + ia
61
+ " " + ioe.getMessage());
62
continue;
63
}
64
65
InetAddress curr = soc.getInterface();
66
if (!curr.equals(ia)) {
67
System.err.println("MulticastSocket.getInterface returned: " + curr);
68
System.err.println("Failed! Expected: " + ia);
69
failures++;
70
} else {
71
System.out.println("Passed.");
72
}
73
}
74
75
/*
76
* Test MulticastSocket.getNetworkInterface
77
*/
78
System.out.println("********************************");
79
System.out.println("MulticastSocket.setNetworkInterface(" +
80
ni.getName() + ")");
81
82
try {
83
soc.setNetworkInterface(ni);
84
} catch (IOException ioe) {
85
System.err.println("Can't set interface to: " + ni.getName()
86
+ " " + ioe.getMessage());
87
continue;
88
}
89
90
// JDK-8022963, Skip (Windows) Teredo Tunneling Pseudo-Interface
91
String dName = ni.getDisplayName();
92
if (isWindows && dName != null && dName.contains("Teredo"))
93
continue;
94
95
NetworkInterface curr = soc.getNetworkInterface();
96
if (!curr.equals(ni)) {
97
System.err.println("MulticastSocket.getNetworkInterface returned: " + curr);
98
System.err.println("Failed! Expected: " + ni);
99
failures++;
100
} else {
101
System.out.println("Passed.");
102
}
103
104
}
105
106
if (failures > 0) {
107
System.out.println("********************************");
108
throw new Exception(failures + " test(s) failed!!!");
109
}
110
111
}
112
113
}
114
115