Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/MulticastSocket/MulticastAddresses.java
41149 views
1
/*
2
* Copyright (c) 2001, 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
/*
25
* @test
26
* @bug 4488458
27
* @library /test/lib
28
* @summary Test that MutlicastSocket.joinGroup is working for
29
* various multicast and non-multicast addresses.
30
* @run main MulticastAddresses
31
* @run main/othervm -Djdk.net.usePlainDatagramSocketImpl MulticastAddresses
32
*/
33
34
import jdk.test.lib.NetworkConfiguration;
35
36
import java.net.*;
37
import java.io.IOException;
38
import java.util.stream.Collectors;
39
40
public class MulticastAddresses {
41
public static void runTest(NetworkInterface ni,
42
String[] multicasts,
43
String[] nonMulticasts) throws Exception {
44
int failures = 0;
45
46
MulticastSocket s = new MulticastSocket();
47
48
/* test valid multicast addresses */
49
for (int i = 0; i < multicasts.length; i++) {
50
InetAddress ia = InetAddress.getByName(multicasts[i]);
51
52
System.out.println("Test: " + ia + " " + " ni: " + ni);
53
try {
54
55
System.out.print(" joinGroup(InetAddress) ");
56
s.joinGroup(ia);
57
s.leaveGroup(ia);
58
System.out.println(" Passed.");
59
60
System.out.print(" joinGroup(InetAddress,NetworkInterface) ");
61
s.joinGroup(new InetSocketAddress(ia, 0), ni);
62
s.leaveGroup(new InetSocketAddress(ia, 0), ni);
63
System.out.println(" Passed.");
64
} catch (IOException e) {
65
failures++;
66
System.out.println("Failed: " + e.getMessage());
67
}
68
69
}
70
71
/* test non-multicast addresses */
72
for (int i = 0; i < nonMulticasts.length; i++) {
73
InetAddress ia = InetAddress.getByName(nonMulticasts[i]);
74
boolean failed = false;
75
76
System.out.println("Test: " + ia + " ");
77
try {
78
System.out.println(" joinGroup(InetAddress) ");
79
s.joinGroup(ia);
80
81
System.out.println("Failed!! -- incorrectly joined group");
82
failed = true;
83
} catch (IOException e) {
84
System.out.println(" Passed: " + e.getMessage());
85
}
86
if (failed) {
87
s.leaveGroup(ia);
88
failures++;
89
}
90
}
91
s.close();
92
if (failures > 0) {
93
throw new Exception(failures + " test(s) failed - see log file.");
94
}
95
}
96
97
98
public static void main(String args[]) throws Exception {
99
100
String[] multicastIPv4 = {
101
"224.80.80.80",
102
};
103
String[] multicastIPv6 = {
104
"ff01::1",
105
"ff02::1234",
106
"ff05::a",
107
"ff0e::1234:a"};
108
109
String[] nonMulticastIPv4 = {
110
"129.1.1.1"
111
};
112
113
String[] nonMulticastIPv6 = {
114
"::1",
115
"::129.1.1.1",
116
"fe80::a00:20ff:fee5:bc02"};
117
118
/*
119
* Examine the network interfaces and determine :-
120
*
121
* 1. If host has IPv6 support
122
* 2. Get reference to a non-loopback interface
123
*/
124
NetworkConfiguration nc = NetworkConfiguration.probe();
125
var ipv6List = nc.ip6MulticastInterfaces(false)
126
.collect(Collectors.toList());
127
128
var ipv4List = nc.ip4MulticastInterfaces(false)
129
.collect(Collectors.toList());
130
131
if (ipv6List.retainAll(ipv4List)) {
132
runTest(ipv6List.get(0), multicastIPv4, nonMulticastIPv4);
133
runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
134
} else {
135
if (!ipv4List.isEmpty())
136
runTest(ipv4List.get(0), multicastIPv4, nonMulticastIPv4);
137
if (!ipv6List.isEmpty())
138
runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
139
}
140
}
141
}
142
143