I am transmitting data through multicast through my network.
I am sending the data to a PC and my board which runs freeRTOS and Lwip.The data gets received right on the PC but not on my board.
The code in the board is an exact relevant copy of the code in the PC.
I have tried various solutions which involved setting the NETIF_FLAG_IGMP flag,using netconn_join_leave_group instead of igmp_leave or igmp_join but both have them dont seem to work.
The above two solutions were my best bets but they have failed me.
I am trying to figure out a way around this for three days but to no avail.
int recieve_udp(char *ip, int sock, int port)
{
int datalen;
char databuf[25];
struct ip_mreq group;/*Multicast address group structure*/
struct sockaddr_in localSock;
{
int reuse=1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&reuse, sizeof(reuse)) < 0)
{
wmprintf("setting SO_REUSEADDR");
net_close(sock);
return -1;
}
}
memset((char *) &localSock, 0, sizeof(localSock));
localSock.sin_family = AF_INET;
localSock.sin_port = htons(EXAMPLE_PORT);
localSock.sin_addr.s_addr = htonl(INADDR_ANY);
if (net_bind(sock, (struct sockaddr*)&localSock, sizeof(localSock)))
{
wmprintf("\r\nbinding datagram socket");
net_close(sock);
return 2;
}
group.imr_multiaddr.s_addr = inet_addr(SRV_IP);
//group.imr_interface.s_addr = inet_addr("192.168.0.116");
group.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&group, sizeof(group)) < 0)
{
wmprintf("\r\nadding multicast group");
net_close(sock);
return -3;
}
datalen = sizeof(databuf);
while(1){
if (read(sock, databuf, datalen) < 0)
{
wmprintf("\r\nreading datagram message");
net_close(sock);
return -4;
}
else
wmprintf("The data recieved is %s\r\n",databuf);
}
return 0;
}