lwip multicast question on rt1176

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lwip multicast question on rt1176

149 Views
llf
Contributor I

I use CreateSockets() to create  the first three multicast communication sockets successfully ,but fail to create the fourth one and after, fail at "ret=setsockopt(*socket,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq));"

i think i should change  some parameters in lwipopts.h,which limited the number of multicast communications 

can anyone help me? thanks

 

int CreateSockets(int* socket,char* remoteip, unsigned int remoteport,char* localip)
{
PRINTF("CreateSockets rmip:%s,port:%d,localip:%s\r\n",remoteip,remoteport,localip);

*socket = SocketEX();
if(*socket<0)
{
PRINTF("socket failed!\r\n");
return 1;
}

/*int opt = 1;
PRINTF("1.1\r\n");
if(setsockopt(*socket, SOL_SOCKET,SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))==-1)
{
PRINTF("setsockopt SO_REUSEADDR failed\r\n");
return 4;
}*/

PRINTF("2\r\n");
int ret = 0;
struct sockaddr_in local_addr;
memset(&local_addr,0,sizeof(local_addr));
PRINTF("3\r\n");
local_addr.sin_family=AF_INET;
local_addr.sin_addr.s_addr=htonl(INADDR_ANY);//localip
//inet_pton(AF_INET, localip, local_addr.sin_addr);
local_addr.sin_port=htons(remoteport);
PRINTF("4\r\n");
ret=bind(*socket,(struct sockaddr*)&local_addr,sizeof(local_addr));
if(ret<0)
{
PRINTF("bind failed !");
return 2;
}
PRINTF("5\r\n");
struct timeval timeout;
timeout.tv_sec = 0;//秒
timeout.tv_usec = 1000*1000;//微秒
if (setsockopt(*socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
PRINTF("setsockopt failed:\r\n");
return 3;
}
PRINTF("6\r\n");

struct ip_mreq mreq; // 多播地址结构体
mreq.imr_multiaddr.s_addr=inet_addr(remoteip);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
ret=setsockopt(*socket,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq));
if(ret<0)
{
PRINTF("setsockopt failed ! ret:%d\r\n",ret);
perror("socket");
return 5;
}
else
{
PRINTF("setsockopt success\r\n");
return 0;
}
PRINTF("8\r\n");

}

0 Kudos
2 Replies

128 Views
MultipleMonomials
Contributor III

Hmm perhaps the MEMP_NUM_IGMP_GROUP option needs to be increased?

0 Kudos

97 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

MEMP_NUM_IGMP_GROUP  might work but we need to consider that it is set to 8 by default.
Instead, I suggest you modify: MEMP_NUM_TCP_PCB, MEMP_NUM_NETBUF, MEMP_NUM_NETCONN

It is also important that there is enough memory available.

Best regards,
Omar

0 Kudos