AnsweredAssumed Answered

LWIP 2.0.3 MULTICAST

Question asked by saad saeed on Jan 21, 2019
Latest reply on Mar 1, 2019 by Daniel Chen

Hello,

I am using MCUXpresso 10.0.3with SDK 2.5.0. I am using the udp_echo_freertos demo example, in which I have changed the code like this.

"

int s;
struct sockaddr_in addr;
struct sockaddr_in from;
char buff[80];
s=lwip_socket(AF_INET,SOCK_DGRAM,0u);
if(s==-1)
{
PRINTF("Socket not created.\r\n");
}
else
{
PRINTF("Socket created.\r \n");
addr.sin_family=AF_INET;
addr.sin_port=htons(7);
addr.sin_addr.s_addr=inet_addr("192.168.1.105");
if(lwip_bind(s,(struct sockaddr*)&addr,sizeof(addr)) < 0)
{

PRINTF("Binding error. \r\n");
}
else
{
PRINTF("Binding recieve.\r \n");
// use setsockopt() to request that the kernel join a multicast group
struct ip_mreq mreq;
memset(&mreq, 0, sizeof(mreq));
mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
mreq.imr_interface.s_addr = inet_addr("192.168.1.105");
if (lwip_setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &mreq, sizeof(mreq)) < 0)
{
PRINTF("Membership unsuccessfull \r\n");
}
else
{
PRINTF("Membership successfull \r\n");


}
socklen_t size =sizeof(from);
if(lwip_recvfrom(s,&buff,80,0,(struct sockaddr*)&from,&size) < 0)
{
PRINTF("Failed to recieve a message. \r\n");

}
else
{
PRINTF("Recieved a message. \r\n");

}

}
}

"

I am getting no error but when I try to receive multicast message. I am receiving nothing. I have also checked my udp socket. Its working fine. What I am doing wrong? 

Outcomes