title: How to use multicast on a multi-homed system (Java, Linux)
body: <p>This is in Java, but I can always revert to C via JNI if needed.</p>
  
  <p>I have a system with two NICs, each connected to a distinct subnet. I want to use multicast (in particular, SDP) to discover other hosts on both networks.</p>
  
  <p>One network is easy: create a MulticastSocket on the specified port, joinGroup it, and I get packets. Simplicity.</p>
  
  <p>Two networks: so far impossible. I've tried:</p>
  
  <p>1) creating two sockets, binding to the same port and using setInterface() or setNetworkInterface() to "connect" to the right interface. No luck, even after various permutations of setReuseAddress().</p>
  
  <p>2) create a single socket, and then attempt to join twice, with two calls to joinGroup(SocketAddress mcastaddr, NetworkInterface netIf). The second join call fails.</p>
  
  <p>Solutions outside of Java would be great. In particular, if I could set up multicast routes that would effectively 'combine' the two interfaces (I could then look at each packet to determine which network) that would be fine. As I mentioned before, any amount of native code is usable in this environment (Linux, with the Apache "luni" java infrastructure).</p>
  
  <p>Thanks!</p>