title: Receiving UDP multicast on macOS Big Sur
body: <p>I know this might be the 10.000th question on receiving UDP multicast messages. However, I already got it working half a year ago. The following snippet I got from <a href="http://www.cs.tau.ac.il/%7Eeddiea/samples/Multicast/multicast-listen.c.html" rel="nofollow noreferrer">http://www.cs.tau.ac.il/~eddiea/samples/Multicast/multicast-listen.c.html</a> (with minor changes: The bind-ip was changed to <code>IPADDR_ANY</code>) worked as expected before I upgraded to macOS Big Sur.</p>
  <pre class="lang-c prettyprint-override"><code>/**************************************************************/
  /* Multicast listener (server)                                */
  /*                                                            */
  /* Activation using: {program name} {Multicast IP} {port}     */
  /*   {program name} - This program name                       */
  /*   {Multicast IP} - The IP address to listen to (Class D)   */
  /*   {port} - The port hnumber to listen on                   */
  /*                                                            */
  /* This is free software released under the GPL license.      */
  /* See the GNU GPL for details.                               */
  /*                                                            */
  /* (c) Juan-Mariano de Goyeneche. 1998, 1999.                 */
  /**************************************************************/
  
  
  #include &lt;stdio.h&gt;          /* printf(), snprintf() */
  #include &lt;stdlib.h&gt;         /* strtol(), exit() */
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;     /* socket(), setsockopt(), bind(), recvfrom(), sendto() */
  #include &lt;errno.h&gt;          /* perror() */
  #include &lt;netinet/in.h&gt;     /* IPPROTO_IP, sockaddr_in, htons(), htonl() */
  #include &lt;arpa/inet.h&gt;      /* inet_addr() */
  #include &lt;unistd.h&gt;         /* fork(), sleep() */
  #include &lt;sys/utsname.h&gt;    /* uname() */
  #include &lt;string.h&gt;         /* memset() */
  
  #define MAXLEN 1024
  
  
  int main(int argc, char* argv[])
  {
    u_char no = 0;
    u_int yes = 1;      /* Used with SO_REUSEADDR.
                               In Linux both u_int */
    /* and u_char are valid. */
    int send_s, recv_s;     /* Sockets for sending and receiving. */
    u_char ttl;
    struct sockaddr_in mcast_group;
    struct ip_mreq mreq;
    struct utsname name;
    int n;
    socklen_t socklen;
    struct sockaddr_in from;
    char message [MAXLEN+1];
  
    if (argc != 3) {
      fprintf(stderr, &quot;Usage: %s mcast_group port\n&quot;, argv[0]);
      exit(1);
    }
  
    memset(&amp;mcast_group, 0, sizeof(mcast_group));
    mcast_group.sin_family = AF_INET;
    mcast_group.sin_port = htons((unsigned short int)strtol(argv[2], NULL, 0));
    mcast_group.sin_addr.s_addr = htonl(INADDR_ANY);
  
    if ( (recv_s=socket(AF_INET, SOCK_DGRAM, 0)) &lt; 0) {
      perror (&quot;recv socket&quot;);
      exit(1);
    }
  
    if (setsockopt(recv_s, SOL_SOCKET, SO_REUSEADDR, &amp;yes, sizeof(yes)) &lt; 0) {
      perror(&quot;reuseaddr setsockopt&quot;);
      exit(1);
    }
  
    if (bind(recv_s, (struct sockaddr*)&amp;mcast_group, sizeof(mcast_group)) &lt; 0) {
      perror (&quot;bind&quot;);
      exit(1);
    }
  
    struct in_addr sin;
    inet_pton(AF_INET, argv[1], &amp;sin);
    /* Preparatios for using Multicast */
    mreq.imr_multiaddr = sin;
    mreq.imr_interface.s_addr = 0;
  
    /* Tell the kernel we want to join that multicast group. */
    if (setsockopt(recv_s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &amp;mreq, sizeof(mreq)) &lt; 0) {
      perror (&quot;add_membership setsockopt&quot;);
      exit(1);
    }
  
    for (;;) {
      socklen=sizeof(from);
      if ( (n=recvfrom(recv_s, message, MAXLEN, 0,
                       (struct sockaddr*)&amp;from, &amp;socklen)) &lt; 0) {
        perror (&quot;recv&quot;);
        exit(1);
      }
      message[n] = '\0'; /* null-terminate string */
      printf(&quot;%s: Received message from %s, size=%d !!\n&quot;,
             name.nodename,
             inet_ntoa(from.sin_addr), n);
      printf(&quot;\t%s \n&quot;, message);
    }
  }
  </code></pre>
  <p>Now I try to get it running again and I can not find any reason why this does not work anymore.
  Did some policies change in Big Sur and this is some permission error? I already run the Application as root with <code>sudo ./multicast-listen 239.255.255.250 1900</code> but this did not work either. I'm trying to receive SSDP packages.</p>