JDK-6393257 : MulticastSocket.setInterface() has no effect on linux when interface is loopback
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2006-03-02
  • Updated: 2011-03-17
  • Resolved: 2007-06-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
When MulticastSocket.setInterface() is called with loopack interface, the address that is set to the outgoing packet is still the default interface. See the following program.

import java.io.*;
import java.net.*;

public class MulticastLoopbackTest {
    public static void main(String[] args) throws Exception {
        MulticastSocket sender = new MulticastSocket();
        MulticastSocket receiver = new MulticastSocket(3000);
        InetAddress multicast = InetAddress.getByName("224.80.80.80");
        SocketAddress sa = new InetSocketAddress(multicast, 0);
        InetAddress localhost = InetAddress.getByName("127.0.0.1");        
        receiver.joinGroup(sa, NetworkInterface.getByInetAddress(localhost));
        byte[] testbytes = {1, 2};
        DatagramPacket packet = new DatagramPacket(testbytes, testbytes.length, multicast, 3000);
        sender.joinGroup(sa, NetworkInterface.getByInetAddress(localhost));
        sender.setInterface(localhost);
        sender.send(packet);        
        byte[] buffer = new byte[10];
        DatagramPacket p = new DatagramPacket(buffer, 10);
        receiver.receive(p);
        System.out.println(p.getAddress());
   }
}

The output from JDK 5.0 on linux is the actual IP address of the host. When the network card is turned off, it prints out the wildcard address 0.0.0.0. The expected output is 127.0.0.1.

Please note that to run the above program on linux, the workaround for 4417033 has to be applied to change the routing table.

The problem is not reproducible on Solaris.

Comments
EVALUATION The problem disappears after applying the fix for 4742177. So it is a duplicate.
28-06-2007

EVALUATION See comments.
10-03-2006