Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6393257

MulticastSocket.setInterface() has no effect on linux when interface is loopback

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7
    • 5.0
    • core-libs
    • None
    • sparc
    • solaris_9

      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.

            yuwangsunw Yujiang Wang (Inactive)
            xwangsunw Xiaozhong Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: