title: multicast bind - Address already in use
body: <p>I try to do bind a multicast port in my app. Previously the code always worked, but on this server it (often, but not always) fails...</p>
  
  <p>The error message is <code>Address already in use</code>, which I don't quite understand, as it's possible to bind the same address from multiple applications (and even from the same application)...</p>
  
  <p>What could cause this? I know someone would ask for it, so here is the code:</p>
  
  <pre><code>int fd = socket(PF_INET, SOCK_DGRAM, 0);
  /* yes, that's a valid socket, verified.... */
  
  u_int val = 1;
  if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &amp;val, sizeof(val)) &lt; 0) {
      perror("Reusing ADDR failed");
      exit(1);
  }
  
  struct sockaddr_in saddr;
  saddr.sin_family = PF_INET;
  saddr.sin_addr.s_addr = inet_addr(multicast_group_ip);
  saddr.sin_port = htons(port);
  /* yes, valid multicast ip address and port, verified */
  
  if(bind(fd, (struct sockaddr *) &amp;saddr, sizeof(struct sockaddr_in)) == -1)
      //FAILS....
  </code></pre>