|
From: | saad saeed |
Subject: | [lwip-users] Multicast: Not receiving multicast messages |
Date: | Mon, 21 Jan 2019 07:05:27 +0000 |
Dear All,
I am trying to receive multicast traffic, I have used the following code.
------------------------------------------------------------------------------------------
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");
}
}
}
---------------------------------------------------------------------------------------------------------------------------------
There is no such error in my code. everything is working fine. But, when I send the multicast message. Nothing is
received. What I am doing wrong?
Kinds Regards,
Saad. |
[Prev in Thread] | Current Thread | [Next in Thread] |