United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6393257 MulticastSocket.setInterface() has no effect on linux when interface is loopback
6393257 : MulticastSocket.setInterface() has no effect on linux when interface is loopback

Details
Type:
Bug
Submit Date:
2006-03-02
Status:
Closed
Updated Date:
2011-03-17
Project Name:
JDK
Resolved Date:
2007-06-28
Component:
core-libs
OS:
solaris_9
Sub-Component:
java.net
CPU:
sparc
Priority:
P4
Resolution:
Duplicate
Affected Versions:
5.0
Fixed Versions:
7

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

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.
                                     
2007-06-28
EVALUATION

See comments.
                                     
2006-03-10



Hardware and Software, Engineered to Work Together