title: Multicast Problems with Java and Zeroconf (avahi) on Linux
body: <p>I am trying to develop a Java-based solution for VM's that start without knowing what static IP address they should self-select from a list.  My idea for the solution was:</p>
  
  <ol>
  <li>Use Zeroconf/avahi to select an IP address for the VM</li>
  <li>VM's broadcast their MAC addresses using multicast.  Each VM would know the expected number of peer MAC addresses.</li>
  <li>Once all VM's had received all other MAC addresses they would sort them alphabetically and select an IP based on the position of their MAC address in the list - IP.1, IP.2, etc.</li>
  </ol>
  
  <p><em><strong>Please note DHCP is not available in this environment under any circumstances and I am trying to find a workaround to this problem</em></strong></p>
  
  <p><strong>I would like help resolving this exception.  Please let me know if you can help.  Thanks!!</strong></p>
  
  <pre><code>java.net.SocketException: No such device
      at java.net.PlainDatagramSocketImpl.join(Native Method)
      at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)
      at java.net.MulticastSocket.joinGroup(MulticastSocket.java:319)
  </code></pre>
  
  <p>Here is the Java code I am using:</p>
  
  <pre><code>InetAddress address = InetAddress.getByName(mIPAddress);
  SocketAddress addr = new InetSocketAddress(address, mPort);
  MulticastSocket multiSocket = new MulticastSocket(addr);
  multiSocket.joinGroup(address);
  </code></pre>
  
  <p>Here is the output of /sbin/ifconfig:</p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr 08:00:27:1D:BB:21  
        inet6 addr: fe80::a00:27ff:fe1d:bb21/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:152 errors:0 dropped:0 overruns:0 frame:0
        TX packets:182 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000 
        RX bytes:35179 (34.3 KiB)  TX bytes:36383 (35.5 KiB)
  
  eth0:avahi Link encap:Ethernet  HWaddr 08:00:27:1D:BB:21  
        inet addr:169.254.4.55  Bcast:169.254.255.255  Mask:255.255.0.0
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  
  lo        Link encap:Local Loopback  
        inet addr:127.0.0.1  Mask:255.0.0.0
        inet6 addr: ::1/128 Scope:Host
        UP LOOPBACK RUNNING  MTU:16436  Metric:1
        RX packets:2957 errors:0 dropped:0 overruns:0 frame:0
        TX packets:2957 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0 
        RX bytes:4448536 (4.2 MiB)  TX bytes:4448536 (4.2 MiB)
  </code></pre>
  
  <p><strong>EDIT</strong>: Added Routing Table: </p>
  
  <pre><code>Kernel IP routing table
  Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
  </code></pre>