Multicast issue
( Hope this is the right forum to ask this question... if not please direct me to the right place )
The simple multicast program below does not work under Windows ( XP, 2003 ) and it works ok on other operating systems. Under Windows, the bind to the multicast address 224.0.1.75:5060 fails with astrerror(errno)) to be "Results Too large". Is there something I need to configure or 'turn on' in windows for this to work? Any help is much appreciated. Thanks.
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#include <winsock2.h>
#include <WS2tcpip.h>
int
initwinsock ()
{
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
return(err);
}
#else
#define SOCKET int
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
int
main ()
{
SOCKET s;
struct ip_mreq mreq;
struct sockaddr_in bindaddr;
int on = 1;
int v;
#ifdef WIN32
initwinsock();
#endif
s = socket(AF_INET, SOCK_DGRAM, 0);
v = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
printf("setsockopt(SO_REUSEADDR) returned %d\n", v);
memset(&bindaddr, '\0', sizeof(bindaddr));
bindaddr.sin_family = AF_INET;
bindaddr.sin_addr.s_addr = htonl(0xe000014b);
bindaddr.sin_port = htons(5060);
v = bind(s, (const sockaddr *)&bindaddr, sizeof(bindaddr));
printf("bind returned %d\n", v);
memset(&mreq, '\0', sizeof(mreq));
mreq.imr_multiaddr.s_addr = htonl(0xe000014b);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
v = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char *)&mreq, sizeof(mreq));
printf("setsockopt(IP_ADD_MEMBERSHIP) returned %d\n", v);
if ( v == 0 )
{
char buf[1500];
while ( true )
{
int n = recv(s, buf, sizeof(buf), 0);
printf("received %d bytes:\n%.*s\n-\n", n, n, buf);
}
}
return(0);
}

