author | alanb |
Sat, 09 Nov 2019 11:48:37 +0000 | |
changeset 59000 | 612c58965775 |
parent 54811 | 9db7c0f561a6 |
permissions | -rw-r--r-- |
1152 | 1 |
/* |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
2 |
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
1152 | 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 |
* |
|
5506 | 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. |
|
1152 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
25 |
* @bug 4527345 7026376 6633549 8233435 |
1152 | 26 |
* @summary Unit test for DatagramChannel's multicast support |
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
27 |
* @library /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
28 |
* @build jdk.test.lib.NetworkConfiguration |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
29 |
* jdk.test.lib.Platform |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
30 |
* jdk.test.lib.net.IPSupport |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
31 |
* MulticastSendReceiveTests |
3424 | 32 |
* @run main MulticastSendReceiveTests |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
33 |
* @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests |
30046 | 34 |
* @key randomness |
1152 | 35 |
*/ |
36 |
||
37 |
import java.nio.ByteBuffer; |
|
38 |
import java.nio.channels.*; |
|
39 |
import java.net.*; |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
40 |
import static java.net.StandardProtocolFamily.*; |
1152 | 41 |
import java.util.*; |
42 |
import java.io.IOException; |
|
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
43 |
import java.util.stream.Collectors; |
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
44 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
45 |
import jdk.test.lib.Platform; |
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
46 |
import jdk.test.lib.NetworkConfiguration; |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
47216
diff
changeset
|
47 |
import jdk.test.lib.net.IPSupport; |
1152 | 48 |
|
49 |
public class MulticastSendReceiveTests { |
|
50 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
51 |
static final Random rand = new Random(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
52 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
53 |
static final ProtocolFamily UNSPEC = new ProtocolFamily() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
54 |
public String name() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
55 |
return "UNSPEC"; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
56 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
57 |
}; |
1152 | 58 |
|
59 |
/** |
|
60 |
* Send datagram from given local address to given multicast |
|
61 |
* group. |
|
62 |
*/ |
|
63 |
static int sendDatagram(InetAddress local, |
|
64 |
NetworkInterface nif, |
|
65 |
InetAddress group, |
|
66 |
int port) |
|
67 |
throws IOException |
|
68 |
{ |
|
69 |
ProtocolFamily family = (group instanceof Inet6Address) ? |
|
70 |
StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; |
|
71 |
DatagramChannel dc = DatagramChannel.open(family) |
|
72 |
.bind(new InetSocketAddress(local, 0)) |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
73 |
.setOption(StandardSocketOptions.IP_MULTICAST_IF, nif); |
1152 | 74 |
int id = rand.nextInt(); |
75 |
byte[] msg = Integer.toString(id).getBytes("UTF-8"); |
|
76 |
ByteBuffer buf = ByteBuffer.wrap(msg); |
|
77 |
System.out.format("Send message from %s -> group %s (id=0x%x)\n", |
|
78 |
local.getHostAddress(), group.getHostAddress(), id); |
|
79 |
dc.send(buf, new InetSocketAddress(group, port)); |
|
80 |
dc.close(); |
|
81 |
return id; |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Wait (with timeout) for datagram. |
|
86 |
* |
|
87 |
* @param expectedSender - expected sender address, or |
|
88 |
* null if no datagram expected |
|
89 |
* @param id - expected id of datagram |
|
90 |
*/ |
|
91 |
static void receiveDatagram(DatagramChannel dc, |
|
92 |
InetAddress expectedSender, |
|
93 |
int id) |
|
94 |
throws IOException |
|
95 |
{ |
|
96 |
Selector sel = Selector.open(); |
|
97 |
dc.configureBlocking(false); |
|
98 |
dc.register(sel, SelectionKey.OP_READ); |
|
99 |
ByteBuffer buf = ByteBuffer.allocateDirect(100); |
|
100 |
||
101 |
try { |
|
102 |
for (;;) { |
|
103 |
System.out.println("Waiting to receive message"); |
|
104 |
sel.select(5*1000); |
|
105 |
SocketAddress sa = dc.receive(buf); |
|
106 |
||
107 |
// no datagram received |
|
108 |
if (sa == null) { |
|
109 |
if (expectedSender != null) { |
|
29746
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
110 |
throw new RuntimeException("Expected message not received"); |
1152 | 111 |
} |
112 |
System.out.println("No message received (correct)"); |
|
113 |
return; |
|
114 |
} |
|
115 |
||
116 |
// datagram received |
|
117 |
||
118 |
InetAddress sender = ((InetSocketAddress)sa).getAddress(); |
|
119 |
buf.flip(); |
|
120 |
byte[] bytes = new byte[buf.remaining()]; |
|
121 |
buf.get(bytes); |
|
29746
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
122 |
String s = new String(bytes, "UTF-8"); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
123 |
int receivedId = -1; |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
124 |
try { |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
125 |
receivedId = Integer.parseInt(s); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
126 |
System.out.format("Received message from %s (id=0x%x)\n", |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
127 |
sender, receivedId); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
128 |
} catch (NumberFormatException x) { |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
129 |
System.out.format("Received message from %s (msg=%s)\n", sender, s); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
130 |
} |
1152 | 131 |
|
132 |
if (expectedSender == null) { |
|
133 |
if (receivedId == id) |
|
134 |
throw new RuntimeException("Message not expected"); |
|
135 |
System.out.println("Message ignored (has wrong id)"); |
|
136 |
} else { |
|
137 |
if (sender.equals(expectedSender)) { |
|
138 |
System.out.println("Message expected"); |
|
139 |
return; |
|
140 |
} |
|
141 |
System.out.println("Message ignored (wrong sender)"); |
|
142 |
} |
|
143 |
||
144 |
sel.selectedKeys().clear(); |
|
145 |
buf.rewind(); |
|
146 |
} |
|
147 |
} finally { |
|
148 |
sel.close(); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
||
153 |
/** |
|
154 |
* Exercise multicast send/receive on given group/interface |
|
155 |
*/ |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
156 |
static void test(ProtocolFamily family, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
157 |
NetworkInterface nif, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
158 |
InetAddress group, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
159 |
InetAddress source) |
1152 | 160 |
throws IOException |
161 |
{ |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
162 |
System.out.format("\nTest DatagramChannel to %s socket\n", family.name()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
163 |
try (DatagramChannel dc = (family == UNSPEC) ? |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
164 |
DatagramChannel.open() : DatagramChannel.open(family)) { |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
165 |
dc.setOption(StandardSocketOptions.SO_REUSEADDR, true) |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
166 |
.bind(new InetSocketAddress(0)); |
1152 | 167 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
168 |
// join group |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
169 |
System.out.format("join %s @ %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
170 |
nif.getName()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
171 |
MembershipKey key; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
172 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
173 |
key = dc.join(group, nif); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
174 |
} catch (IllegalArgumentException iae) { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
175 |
if (family == UNSPEC) { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
176 |
System.out.println("Not supported"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
177 |
return; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
178 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
179 |
throw iae; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
180 |
} |
1152 | 181 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
182 |
// send message to group |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
183 |
int port = ((InetSocketAddress)dc.getLocalAddress()).getPort(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
184 |
int id = sendDatagram(source, nif, group, port); |
1152 | 185 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
186 |
// receive message and check id matches |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
187 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
188 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
189 |
// exclude-mode filtering |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
190 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
191 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
192 |
System.out.format("block %s\n", source.getHostAddress()); |
1152 | 193 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
194 |
// may throw UOE |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
195 |
key.block(source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
196 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
197 |
receiveDatagram(dc, null, id); |
1152 | 198 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
199 |
// unblock source, send message, message should be received |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
200 |
System.out.format("unblock %s\n", source.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
201 |
key.unblock(source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
202 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
203 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
204 |
} catch (UnsupportedOperationException x) { |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
205 |
String os = System.getProperty("os.name"); |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
206 |
// Exclude-mode filtering supported on these platforms so UOE should never be thrown |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
207 |
if (os.equals("SunOS") || os.equals("Linux")) |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
208 |
throw x; |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
209 |
System.out.println("Exclude-mode filtering not supported!"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
210 |
} |
1152 | 211 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
212 |
key.drop(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
213 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
214 |
// include-mode filtering |
1152 | 215 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
216 |
InetAddress bogus = (group instanceof Inet6Address) ? |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
217 |
InetAddress.getByName("fe80::1234") : |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
218 |
InetAddress.getByName("1.2.3.4"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
219 |
System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
220 |
nif.getName(), bogus.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
221 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
222 |
// may throw UOE |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
223 |
key = dc.join(group, nif, bogus); |
1152 | 224 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
225 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
226 |
receiveDatagram(dc, null, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
227 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
228 |
System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
229 |
nif.getName(), source.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
230 |
key = dc.join(group, nif, source); |
1152 | 231 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
232 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
233 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
234 |
} catch (UnsupportedOperationException x) { |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
235 |
String os = System.getProperty("os.name"); |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
236 |
// Include-mode filtering supported on these platforms so UOE should never be thrown |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
237 |
if (os.equals("SunOS") || os.equals("Linux")) |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
238 |
throw x; |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
239 |
System.out.println("Include-mode filtering not supported!"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
240 |
} |
1152 | 241 |
} |
242 |
} |
|
243 |
||
244 |
public static void main(String[] args) throws IOException { |
|
54811
9db7c0f561a6
8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents:
54770
diff
changeset
|
245 |
IPSupport.throwSkippedExceptionIfNonOperational(); |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
47216
diff
changeset
|
246 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
247 |
// IPv4 and IPv6 interfaces that support multicasting |
1152 | 248 |
NetworkConfiguration config = NetworkConfiguration.probe(); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
249 |
List<NetworkInterface> ip4MulticastInterfaces = config.ip4MulticastInterfaces() |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
250 |
.collect(Collectors.toList()); |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
251 |
List<NetworkInterface> ip6MulticastInterfaces = config.ip6MulticastInterfaces() |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
252 |
.collect(Collectors.toList()); |
1152 | 253 |
|
254 |
// multicast groups used for the test |
|
255 |
InetAddress ip4Group = InetAddress.getByName("225.4.5.6"); |
|
256 |
InetAddress ip6Group = InetAddress.getByName("ff02::a"); |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
257 |
|
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
258 |
// Platforms that allow dual sockets join IPv4 multicast groups |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
259 |
boolean canIPv6JoinIPv4Group = |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
260 |
Platform.isLinux() || |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
261 |
Platform.isOSX() || |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
262 |
Platform.isSolaris() || |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
263 |
Platform.isWindows(); |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
264 |
|
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
265 |
for (NetworkInterface nif : ip4MulticastInterfaces) { |
1152 | 266 |
InetAddress source = config.ip4Addresses(nif).iterator().next(); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
267 |
test(UNSPEC, nif, ip4Group, source); |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
268 |
test(INET, nif, ip4Group, source); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
269 |
if (IPSupport.hasIPv6() && canIPv6JoinIPv4Group) { |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
270 |
test(INET6, nif, ip4Group, source); |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
271 |
} |
1152 | 272 |
} |
273 |
||
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
274 |
for (NetworkInterface nif : ip6MulticastInterfaces) { |
1152 | 275 |
InetAddress source = config.ip6Addresses(nif).iterator().next(); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
54811
diff
changeset
|
276 |
test(UNSPEC, nif, ip6Group, source); |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
277 |
test(INET6, nif, ip6Group, source); |
1152 | 278 |
} |
279 |
} |
|
280 |
} |