title: Join multicast group using DatagramChannel without specifying network interface
body: <p>When using java's multicast socket I can join a multicast group without specifying a <code>NetworkInterface</code> using this code:</p>
  
  <pre><code>MulticastSocket sock = new MulticastSocket(PORT);
  sock.joinGroup(ADDR);
  </code></pre>
  
  <p>If I want to use NIO on the other hand I can do: </p>
  
  <pre><code>DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
          .setOption(StandardSocketOptions.SO_REUSEADDR, true)
          .bind(new InetSocketAddress(PORT))
          .setOption(StandardSocketOptions.IP_MULTICAST_IF, IFC);
  
  dc.join(ADDR, IFC);
  </code></pre>
  
  <p>where <code>IFC</code> is the <code>NetworkInterface</code> I am interested on. 
  If I dont know the network interface in advance how can I join a group like with the <code>MulticastSocket?</code></p>
  
  <p>One solution that I found is using this code:</p>
  
  <pre><code>MulticastSocket msock = new MulticastSocket();
  NetworkInterface ifc = msock.getNetworkInterface();
  msock.close();
  DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
          .setOption(StandardSocketOptions.SO_REUSEADDR, true)
          .bind(new InetSocketAddress(PORT))
          .setOption(StandardSocketOptions.IP_MULTICAST_IF, ifc);
  
  dc.join(ADDR, ifc);
  </code></pre>
  
  <p>Surprisingly this code works and performed as expected, when looking on the NetworkInterface returned by the <code>MulticastSocket.getNetworkInterface()</code> method I saw that it returned an interface named "0.0.0.0" which of course does not exists. Moreover there is no way to get this network interface  with any of the <code>NetworkInterface.*</code> factories</p>
  
  <p>Is the solution reliable? can anyone explain why it works and if there is a better way to achieve what I wants?</p>