Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/MulticastSocket/TestInterfaces.java
41149 views
1
/*
2
* Copyright (c) 2001, 2017, 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
* @library /test/lib
30
* @build jdk.test.lib.NetworkConfiguration
31
* jdk.test.lib.Platform
32
* @run main TestInterfaces
33
*/
34
import jdk.test.lib.NetworkConfiguration;
35
36
import java.net.*;
37
import java.util.Arrays;
38
import java.util.Collections;
39
import java.util.Enumeration;
40
import java.io.IOException;
41
42
public class TestInterfaces {
43
44
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
45
46
public static void main(String args[]) throws Exception {
47
int failures = 0;
48
49
MulticastSocket soc = new MulticastSocket();
50
51
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
52
while (nifs.hasMoreElements()) {
53
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
54
55
// JDK-8022963, Skip (Windows) Teredo Tunneling Pseudo-Interface
56
String dName = ni.getDisplayName();
57
if (isWindows && dName != null && dName.contains("Teredo"))
58
continue;
59
60
// Skip those interfaces not up or not support multicast
61
if (!ni.isUp() || !ni.supportsMulticast())
62
continue;
63
64
/*
65
* Test MulticastSocket.getInterface
66
*/
67
System.out.println("Testing network interface " + ni);
68
Enumeration addrs = ni.getInetAddresses();
69
while (addrs.hasMoreElements()) {
70
InetAddress ia = (InetAddress)addrs.nextElement();
71
72
System.out.println("********************************");
73
System.out.println("MulticastSocket.setInterface(" + ia + ")");
74
75
try {
76
soc.setInterface(ia);
77
} catch (IOException ioe) {
78
System.err.println("Can't set interface to: " + ia
79
+ " " + ioe.getMessage());
80
continue;
81
}
82
83
InetAddress curr = soc.getInterface();
84
if (!curr.equals(ia)) {
85
System.err.println("NetworkInterface under test " + ni);
86
displayInterfaceInformation(ni);
87
System.err.println("MulticastSocket.getInterface returned: " + curr);
88
System.err.println("Failed! Expected: " + ia);
89
failures++;
90
} else {
91
System.out.println("Passed.");
92
}
93
}
94
95
/*
96
* Test MulticastSocket.getNetworkInterface
97
*/
98
System.out.println("********************************");
99
System.out.println("MulticastSocket.setNetworkInterface(" +
100
ni.getName() + ")");
101
102
try {
103
soc.setNetworkInterface(ni);
104
} catch (IOException ioe) {
105
System.err.println("Can't set interface to: " + ni.getName()
106
+ " " + ioe.getMessage());
107
continue;
108
}
109
110
111
NetworkInterface curr = soc.getNetworkInterface();
112
if (!curr.equals(ni)) {
113
System.err.println("MulticastSocket.getNetworkInterface returned: " + curr);
114
System.err.println("Failed! Expected: " + ni);
115
System.err.println("NetworkInterface details for curr variable ");
116
displayInterfaceInformation(curr);
117
System.err.println("NetworkInterface details for ni variable ");
118
displayInterfaceInformation(ni) ;
119
failures++;
120
} else {
121
System.out.println("Passed.");
122
}
123
124
}
125
126
if (failures > 0) {
127
System.err.println("********************************");
128
NetworkConfiguration.printSystemConfiguration(System.err);
129
System.out.println("********************************");
130
throw new Exception(failures + " test(s) failed!!!");
131
}
132
133
}
134
135
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
136
System.err.println("Display name: " + netint.getDisplayName());
137
System.err.println("Name: " + netint.getName());
138
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
139
140
for (InetAddress inetAddress : Collections.list(inetAddresses))
141
System.err.println("InetAddress: " + inetAddress);
142
143
System.err.println("Up? " + netint.isUp());
144
System.err.println("Loopback? " + netint.isLoopback());
145
System.err.println("PointToPoint? " + netint.isPointToPoint());
146
System.err.println("Supports multicast? " + netint.supportsMulticast());
147
System.err.println("Virtual? " + netint.isVirtual());
148
System.err.println("Hardware address: " +
149
Arrays.toString(netint.getHardwareAddress()));
150
System.err.println("MTU: " + netint.getMTU());
151
System.err.println("Index: " + netint.getIndex());
152
System.err.println();
153
}
154
}
155
156