title: IP_ADD_MEMBERSHIP on a socket, will the socket listen to unicast also?
body: <p>Considering the code below,</p>
  
  <p>I'm trying to bind a UDP socket for multicast.<br>
  I've bound it to a specific port, and set <code>IP_ADD_MEMBERSHIP</code> for the address to listen to.</p>
  
  <p>My question: will the socket receive unicast UDP packets bound for that port? If so, how can I prevent it? I wish to only receive multicast.</p>
  
  <pre><code>int fd;
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) &lt; 0)
  {
      perror("socket");
      exit(1);
  }
  
  u_int yes = 1;
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &amp;yes, sizeof(yes)) &lt; 0)
  {
      perror("Reusing ADDR failed");
      exit(1);
  }
  
  struct sockaddr_in addr;
  memset(&amp;addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = (source_iface.empty()
                            ? htonl(INADDR_ANY)
                            : inet_addr(source_iface.c_str()));
  
  if (bind(fd,(struct sockaddr *)&amp;addr, sizeof(addr)) &lt; 0)
  {
      perror("bind");
      exit(1);
  }
  
  struct ip_mreq mreq;
  mreq.imr_multiaddr.s_addr = inet_addr(group.c_str());
  mreq.imr_interface.s_addr = (source_iface.empty()
                                 ? htonl(INADDR_ANY)
                                 : inet_addr(source_iface.c_str()));
  
  if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &amp;mreq, sizeof(mreq)) &lt; 0)
  {
      perror("setsockopt");
      exit(1);
  }
  </code></pre>