187 receiveDatagram(dc, source, id);
188
189 // exclude-mode filtering
190
191 try {
192 System.out.format("block %s\n", source.getHostAddress());
193
194 // may throw UOE
195 key.block(source);
196 id = sendDatagram(source, nif, group, port);
197 receiveDatagram(dc, null, id);
198
199 // unblock source, send message, message should be received
200 System.out.format("unblock %s\n", source.getHostAddress());
201 key.unblock(source);
202 id = sendDatagram(source, nif, group, port);
203 receiveDatagram(dc, source, id);
204 } catch (UnsupportedOperationException x) {
205 String os = System.getProperty("os.name");
206 // Exclude-mode filtering supported on these platforms so UOE should never be thrown
207 if (os.equals("SunOS") || os.equals("Linux"))
208 throw x;
209 System.out.println("Exclude-mode filtering not supported!");
210 }
211
212 key.drop();
213
214 // include-mode filtering
215
216 InetAddress bogus = (group instanceof Inet6Address) ?
217 InetAddress.getByName("fe80::1234") :
218 InetAddress.getByName("1.2.3.4");
219 System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(),
220 nif.getName(), bogus.getHostAddress());
221 try {
222 // may throw UOE
223 key = dc.join(group, nif, bogus);
224
225 id = sendDatagram(source, nif, group, port);
226 receiveDatagram(dc, null, id);
227
228 System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(),
229 nif.getName(), source.getHostAddress());
230 key = dc.join(group, nif, source);
231
232 id = sendDatagram(source, nif, group, port);
233 receiveDatagram(dc, source, id);
234 } catch (UnsupportedOperationException x) {
235 String os = System.getProperty("os.name");
236 // Include-mode filtering supported on these platforms so UOE should never be thrown
237 if (os.equals("SunOS") || os.equals("Linux"))
238 throw x;
239 System.out.println("Include-mode filtering not supported!");
240 }
241 }
242 }
243
244 public static void main(String[] args) throws IOException {
245 IPSupport.throwSkippedExceptionIfNonOperational();
246
247 // IPv4 and IPv6 interfaces that support multicasting
248 NetworkConfiguration config = NetworkConfiguration.probe();
249 List<NetworkInterface> ip4MulticastInterfaces = config.ip4MulticastInterfaces()
250 .collect(Collectors.toList());
251 List<NetworkInterface> ip6MulticastInterfaces = config.ip6MulticastInterfaces()
252 .collect(Collectors.toList());
253
254 // multicast groups used for the test
255 InetAddress ip4Group = InetAddress.getByName("225.4.5.6");
256 InetAddress ip6Group = InetAddress.getByName("ff02::a");
257
258 // Platforms that allow dual sockets join IPv4 multicast groups
259 boolean canIPv6JoinIPv4Group =
260 Platform.isLinux() ||
261 Platform.isOSX() ||
262 Platform.isSolaris() ||
263 Platform.isWindows();
264
265 for (NetworkInterface nif : ip4MulticastInterfaces) {
266 InetAddress source = config.ip4Addresses(nif).iterator().next();
267 test(UNSPEC, nif, ip4Group, source);
268 test(INET, nif, ip4Group, source);
269 if (IPSupport.hasIPv6() && canIPv6JoinIPv4Group) {
270 test(INET6, nif, ip4Group, source);
271 }
272 }
273
274 for (NetworkInterface nif : ip6MulticastInterfaces) {
275 InetAddress source = config.ip6Addresses(nif).iterator().next();
276 test(UNSPEC, nif, ip6Group, source);
277 test(INET6, nif, ip6Group, source);
278 }
279 }
280 }
|
187 receiveDatagram(dc, source, id);
188
189 // exclude-mode filtering
190
191 try {
192 System.out.format("block %s\n", source.getHostAddress());
193
194 // may throw UOE
195 key.block(source);
196 id = sendDatagram(source, nif, group, port);
197 receiveDatagram(dc, null, id);
198
199 // unblock source, send message, message should be received
200 System.out.format("unblock %s\n", source.getHostAddress());
201 key.unblock(source);
202 id = sendDatagram(source, nif, group, port);
203 receiveDatagram(dc, source, id);
204 } catch (UnsupportedOperationException x) {
205 String os = System.getProperty("os.name");
206 // Exclude-mode filtering supported on these platforms so UOE should never be thrown
207 if (os.equals("Linux"))
208 throw x;
209 System.out.println("Exclude-mode filtering not supported!");
210 }
211
212 key.drop();
213
214 // include-mode filtering
215
216 InetAddress bogus = (group instanceof Inet6Address) ?
217 InetAddress.getByName("fe80::1234") :
218 InetAddress.getByName("1.2.3.4");
219 System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(),
220 nif.getName(), bogus.getHostAddress());
221 try {
222 // may throw UOE
223 key = dc.join(group, nif, bogus);
224
225 id = sendDatagram(source, nif, group, port);
226 receiveDatagram(dc, null, id);
227
228 System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(),
229 nif.getName(), source.getHostAddress());
230 key = dc.join(group, nif, source);
231
232 id = sendDatagram(source, nif, group, port);
233 receiveDatagram(dc, source, id);
234 } catch (UnsupportedOperationException x) {
235 String os = System.getProperty("os.name");
236 // Include-mode filtering supported on these platforms so UOE should never be thrown
237 if (os.equals("Linux"))
238 throw x;
239 System.out.println("Include-mode filtering not supported!");
240 }
241 }
242 }
243
244 public static void main(String[] args) throws IOException {
245 IPSupport.throwSkippedExceptionIfNonOperational();
246
247 // IPv4 and IPv6 interfaces that support multicasting
248 NetworkConfiguration config = NetworkConfiguration.probe();
249 List<NetworkInterface> ip4MulticastInterfaces = config.ip4MulticastInterfaces()
250 .collect(Collectors.toList());
251 List<NetworkInterface> ip6MulticastInterfaces = config.ip6MulticastInterfaces()
252 .collect(Collectors.toList());
253
254 // multicast groups used for the test
255 InetAddress ip4Group = InetAddress.getByName("225.4.5.6");
256 InetAddress ip6Group = InetAddress.getByName("ff02::a");
257
258 // Platforms that allow dual sockets join IPv4 multicast groups
259 boolean canIPv6JoinIPv4Group =
260 Platform.isLinux() ||
261 Platform.isOSX() ||
262 Platform.isWindows();
263
264 for (NetworkInterface nif : ip4MulticastInterfaces) {
265 InetAddress source = config.ip4Addresses(nif).iterator().next();
266 test(UNSPEC, nif, ip4Group, source);
267 test(INET, nif, ip4Group, source);
268 if (IPSupport.hasIPv6() && canIPv6JoinIPv4Group) {
269 test(INET6, nif, ip4Group, source);
270 }
271 }
272
273 for (NetworkInterface nif : ip6MulticastInterfaces) {
274 InetAddress source = config.ip6Addresses(nif).iterator().next();
275 test(UNSPEC, nif, ip6Group, source);
276 test(INET6, nif, ip6Group, source);
277 }
278 }
279 }
|