Hi

On which hardware? You may have to enable reception of multicast frames in your ethernet controller

BR /Jens

On 2018-07-11 02:12, Amr Elsayed wrote:
Dear LWIP users and team,
I am trying to send and receive IGMP multicast messages using RAW API's , I can only send but can not receive back the messages by a board running the same code (without sending packets).On wireshark I can  see the "IGMP Membership report Group " packets for both devices  and I can also see the UDP messages I send periodically to the multicast IP, but on receiver board having the same code that I also share below I can not receive back the Multicast messages and the udp_recv set callback function is never called. also i tried to put a breakpoint in ip4_input inside the if condition of the multicast packets but the breakpoint is never getting fired.
  if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
              // ...
  }
so this may do means that the sent UDP message have something wrong despite that I can see the packet on wireshark ? I have netif->flags|= NETIF_FLAG_IGMP; and i am sure igmp_start() is called. to summarize the problem I do have I can join IGMP group and send UDP messages to the multicast IP as on wireshark but I can not receive that message on another board running the same code.

code:
#define MULTICAST_PORT9533
static char multicast_ip[] = "238.0.0.8";

static char dummyData[] = "Hello from board";
#define UDP_APP_INTERVAL 5000
static struct udp_pcb *multiAppPcb;
static ip_addr_t multicastIp;
static uint32_t multiAppTime = 0 ;
// prototypes
void multicast_init(void);
int multicast_send_data(const char* buff,uint16_t len );.
static void multicast_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
               const ip_addr_t *addr, u16_t port);

void main( void ){
 // .. initializations
  LWIP_Init();
  multicast_init();
  while(1)
  {
       MX_LWIP_Process(hal_time);
       // only on sender board..
if(time - multiAppTime > UDP_APP_INTERVAL)
{
multiAppTime = time ;
uint16_t totLen = strlen(dummyData);
multicast_send_data(dummyData,totLen);
}
  }

void
multicast_init(void)
{
      multicastIp.addr= ipaddr_addr(multicast_ip);
multiAppPcb = udp_new_ip_type(IPADDR_TYPE_ANY);
if (multiAppPcb != NULL) {

    err_t err;

    err = udp_bind(multiAppPcb, IP_ADDR_ANY, MULTICAST_PORT);
    if (err == ERR_OK) {
#if LWIP_IGMP
err_t iret =
igmp_joingroup(IP_ADDR_ANY,(const struct ip4_addr *)(&multicastIp));
if(iret){
initErr = 1 ;
return ;
}
#endif // LWIP_IGMP
udp_set_multicast_netif_addr(multiAppPcb,(const struct ip4_addr *)(&multicastIp));
udp_set_multicast_ttl(multiAppPcb,5);

udp_recv(multiAppPcb, multicast_recv, multiAppPcb);

    } else {
      /* abort? output diagnostic? */
initErr = 1;
    }
  } else {
    /* abort? output diagnostic? */
initErr = 1;
  }
}
int multicast_send_data(const char* buff,uint16_t len )
{
err_t err;
  if (initErr == 1)
return 1 ;
struct pbuf *p = pbuf_alloc(PBUF_RAW,len,PBUF_RAM);
int ret  = 0 ;
if(p == NULL)
return 1 ;
if(pbuf_take(p,buff,len) != ERR_OK)
{
ret = 1 ;
goto udp_app_send_end;
}
err = udp_sendto(multiAppPcb, p, &multicastIp, MULTICAST_PORT) ;
if(err != ERR_OK)
ret = 1 ;
udp_app_send_end:
pbuf_free(p);
return ret ;
}
static void
multicast_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
                 const ip_addr_t *addr, u16_t port)
{
  LWIP_UNUSED_ARG(arg);
  if (p != NULL) {
    /* send received packet back to sender */
//udp_sendto(upcb, p, addr, port);
  char* recv_buff = (char*) mem_malloc(p->tot_len);
  if(recv_buff){
extract_payload(p,recv_buff);
multicast_recv_callback(recv_buff,p->tot_len);
  }else{

multicast_recv_callback(NULL,p->tot_len);
  }

    /* free the pbuf */
    pbuf_free(p);
  }
}
void  extract_payload(struct pbuf *p,char *payload)
{
struct pbuf *q = p ;
while(q)
{
for(int i = 0  ; i < q->len ; i++ )
{
payload[i] =((char*)(q->payload))[i];
}
q = p->next;
}
}
void multicast_recv_callback(char* buff, int len )
{
if(buff != NULL){


}else{
// invalid
}


}

-----------------------------------------------------------------------------------------------------------
Best Regards,
Amr Elsayed.
RA @ E-JUST <http://ejust.edu.eg/>.
Founder & Engineer @ DIY-Life <http://www.the-diy-life.co/>.
eng.amralsa...@gmail.com <mailto:eng.amralsa...@gmail.com>
+201223240852.


Mailtrack <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&;> Sender notified by Mailtrack <https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&;> 07/11/18, 1:58:47 AM



_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to