// Test for method void
// java.net.MulticastSocket.setInterface(java.net.InetAddress)
// Note that the machine is not multi-homed
try {
mss = new MulticastSocket();
mss.setInterface(InetAddress.getLocalHost());
ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_MULTICAST_INTERFACE);
} catch (Exception e) {
handleException(e, SO_MULTICAST_INTERFACE);
return;
}
try {
InetAddress theInterface = mss.getInterface();
// under IPV6 we are not guarrenteed to get the same address back as
// the address, all we should be guaranteed is that we get an
// address on the same interface
if (theInterface instanceof Inet6Address) {
assertTrue(
"Failed to return correct interface IPV6",
NetworkInterface
.getByInetAddress(mss.getInterface())
.equals(
NetworkInterface
.getByInetAddress(theInterface)));
} else {
assertTrue("Failed to return correct interface IPV4 got:"
+ mss.getInterface() + " excpeted: "
+ InetAddress.getLocalHost(), mss.getInterface()
.equals(InetAddress.getLocalHost()));
}
ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_MULTICAST);
} catch (SocketException e) {
handleException(e, SO_MULTICAST);
} catch (UnknownHostException e) {
fail("Exception during setInterface test: " + e.toString());
}
// Regression test for Harmony-2410
try {
mss = new MulticastSocket();
mss.setInterface(InetAddress.getByName("224.0.0.5"));
} catch (UnknownHostException uhe) {
fail("Unable to get InetAddress by name from '224.0.0.5' addr: " + uhe.toString());
} catch (SocketException se) {
// expected