Multicasting in C++ : Error "An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call"
<p>I have developed one server pgm for multicasting in C++, when i register the address and after that when i set the socket option using setsockopt it returns me -1</p>

<p>If this option is not supported in setsockopt then how i can go for multicasting in C++</p>

<p>My code is below :</p>

<pre><code>#include"winsock.h"
#include&lt;iostream&gt;
#include&lt;conio.h&gt;

using namespace std;

#define MYPORT 9009 // the port users will be connecting to






#define MAXBUFSIZE 65536 // Max UDP Packet size is 64 Kbyte

int main()
{


    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2), &amp;wsaData);

   int sock, status, socklen;
   char buffer[MAXBUFSIZE];
   struct sockaddr_in saddr;
   struct ip_mreq imreq;

   // set content of struct saddr and imreq to zero
   memset(&amp;saddr, 0, sizeof(sockaddr_in));
   memset(&amp;imreq, 0, sizeof(ip_mreq));

   // open a UDP socket
   sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
   if ( sock &lt; 0 )
     perror("Error creating socket"), exit(0);

   saddr.sin_family = PF_INET;
   saddr.sin_port = htons(4849); // listen on port 4096
   saddr.sin_addr.s_addr = htonl(INADDR_ANY); // bind socket to any interface
   status = bind(sock, (sockaddr *)&amp;saddr, sizeof(sockaddr_in));

   if ( status &lt; 0 )
     perror("Error binding socket to interface"), exit(0);

   imreq.imr_multiaddr.s_addr = inet_addr("226.0.0.1");
   imreq.imr_interface.s_addr = htonl(INADDR_ANY); // use DEFAULT interface

   // JOIN multicast group on default interface
   **status = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
              (const char *)&amp;imreq, sizeof(ip_mreq));** // This line return -1



   socklen = sizeof(struct sockaddr_in);

   // receive packet from socket
   status = recvfrom(sock, buffer, MAXBUFSIZE, 0, 
                     (struct sockaddr *)&amp;saddr, &amp;socklen);


   if(status &lt; 0)

   {
      printf("Received failed");
   }
   else

   {
       printf("received buffer : %s",buffer);
   }

   // shutdown socket
   shutdown(sock, 2);
   // close socket
   closesocket(sock);

   return 0;
}
</code></pre>

<p>// I think it sis not able to register the interface address.
Any body has idea on this ?
Thanks in advance</p>
