Name: dfR10049 Date: 10/06/2000
MulticastSocket works wrong on Solaris 2.8 if "localhost" interface set.
MulticastSocket allows set interface to "localhost", join to
desired group, send packet, but it cannot receive sent packet.
This bug is reproduced only on Solaris 2.8.
This is the test demonstrated the bug:
-------------------------------------
import java.net.*;
public class Test {
public static void main(String args[]) {
boolean passed = true;
try {
InetAddress in1 = InetAddress.getByName("localhost");
InetAddress m_addr = InetAddress.getByName("224.80.80.80");
MulticastSocket soc = new MulticastSocket(0);;
soc.setInterface(in1);
System.out.println("interface: " + in1);
soc.joinGroup(m_addr);
System.out.println("joined to: " + m_addr);
byte[] data = {100, 101};
int port = soc.getLocalPort();
DatagramPacket pac =
new DatagramPacket(data, data.length, m_addr, port);
soc.setSoTimeout(10000);
soc.send(pac);
System.out.println("sent to: " + m_addr);
soc.receive(pac);
soc.leaveGroup(m_addr);
InetAddress from = pac.getAddress();
System.out.println("received from: " + from);
if (!in1.equals(from)) {
passed = false;
}
soc.close();
} catch (Exception e) {
passed = false;
e.printStackTrace(System.out);
}
if (passed)
System.out.println("test passed");
else
System.out.println("test failed");
}
}
-------- output from the text on Solaris 2.7 ----------------
#> uname -a
SunOS falcon 5.7 Generic_106541-12 sun4u sparc SUNW,Ultra-5_10
#> java Test
interface: localhost/127.0.0.1
joined to: /224.80.80.80
sent to: /224.80.80.80
received from: /127.0.0.1
test passed
-------- output from the text on Solaris 2.8 ----------------
#> uname -a
SunOS stardust 5.8 s28_34 sun4u sparc SUNW,Ultra-1
#> java Test
interface: localhost/127.0.0.1
joined to: /224.80.80.80
sent to: /224.80.80.80
java.io.InterruptedIOException: Receive timed out
at java.net.PlainDatagramSocketImpl.receive(Native Method)
at java.net.DatagramSocket.receive(DatagramSocket.java:392)
at Test.main(Test.java:25)
test failed
----------------------------------------------
======================================================================