简体   繁体   中英

Multicast UDP not working on my board

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;

}

Do you configure the Ethernet controller of your board to accept multicast packets? lwIP has a function netif_set_igmp_mac_filter() that you can use to register a callback that will be called every time you join or leave a multicast group. In the implementation of your callback you may need to configure your Ethernet controller to accept the multicast MAC address for the group that you are joining.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM