- 参数设置ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Enable;
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_NONE;
2.opt.h中 #define LWIP_IGMP 1
3.ethernetif.c文件中,low_level_init函数,使能IGMP标志
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP |NETIF_FLAG_IGMP;//添加IGMP
4.在函数lwip_periodic_handle函数点C文件中添加
#ifdef LWIP_IGMP
u32 IGMPTimer=0;
#endif
#if LWIP_IGMP
if(localtime-IGMPTimer>=IGMP_TMR_INTERVAL)
{
IGMPTimer=localtime;
igmp_tmr();
}
#endif
5.def.h中定义
#define LWIP_RAND rand //添加
6.加入组播
struct ip_addr ipgroup_recv,ipgroup_send, local_ip;
IP4_ADDR(&local_ip, 192,168,4,141);
IP4_ADDR(&ipgroup_recv, 230,1,1,11);//用于接收组播的地址
IP4_ADDR(&ipgroup_send, 230,12,2,22);//用于发送组播的地址
err=igmp_joingroup(&local_ip,(struct ip_addr *)(&ipgroup_rev));//只需要将接收地址放入igmp组,发送的不需要
7.发送组播数据
udp_sendto(udp_server_multi_pcb, p,(struct ip_addr *) (&ipgroup_send),UDP_MULTICASE_SEND_PORT);