title: setsockopt returning error 10014
body: <p>I'm trying to write a simple UDP server that advertises its service port on a multicast group but I'm having trouble getting the multicast to work. I tried looking around on the Microsoft documentation and copy/pasted some of their code but it's not working. Here is the problematic code:</p>
  
  <pre><code>    this-&gt;port = srvc_port; //11129 in my example
      this-&gt;mcast_port = mcast_port; //11130 in my example
      this-&gt;mcast_ip = mcast_ip; //230.0.0.30 in my example
  
      int iResult = WSAStartup(MAKEWORD(2,2), &amp;service_wsaData);
      if (iResult != NO_ERROR)
      {
          cout &lt;&lt; "WSAstartup failed" &lt;&lt; endl;
          return -1;
      }
  
      service_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if (service_sock == INVALID_SOCKET) {
          closesocket(service_sock);
          WSACleanup();
          cout &lt;&lt; "Error at socket" &lt;&lt; endl;
          return -1;
      }
  
      mcast_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if(mcast_sock == INVALID_SOCKET) {
          closesocket(mcast_sock);
          WSACleanup();
          cout &lt;&lt; "Error at socket" &lt;&lt; endl;
          return -1;
      }
  
      multicast.sin_family = AF_INET; // multicast is a sockaddr_in struct
      multicast.sin_addr.s_addr = INADDR_ANY;
      multicast.sin_port = htons(mcast_port);
  
      service.sin_family = AF_INET; //same for service
      service.sin_addr.s_addr = INADDR_ANY;
      service.sin_port = htons(port);
  
      if(::bind( service_sock, (sockaddr *)&amp;service, sizeof(service) ) == SOCKET_ERROR) {
          closesocket(mcast_sock);
          closesocket(service_sock);
          WSACleanup();
          cout &lt;&lt; "Error binding service socket" &lt;&lt; endl;
          return -1;
      };
  
      if(::bind( mcast_sock, (sockaddr *)&amp;multicast, sizeof(multicast) ) == SOCKET_ERROR) {
          closesocket(mcast_sock);
          closesocket(service_sock);
          WSACleanup();
          cout &lt;&lt; "Error binding multicast socket" &lt;&lt; endl;
          return -1;
      };
  
      mreq.imr_multiaddr.s_addr = inet_addr(mcast_ip.c_str()); //mreq is declared like so "struct ip_mreq mreq;" in the class
      mreq.imr_interface.s_addr = htonl(INADDR_ANY);
  
      if(setsockopt(mcast_sock,IPPROTO_IP,IP_ADD_SOURCE_MEMBERSHIP,(char *) &amp;mreq, sizeof(mreq)) == SOCKET_ERROR)
      {
              //I get error 10014 here
          cout &lt;&lt; "Error: " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
          return -1;
      }
  </code></pre>
  
  <p>Any help would be appreciated.</p>