struct table_port_mac *obx_mc_mac_跳銀tbl = NULL;/*定義多播MAC轉發表對象為(wèi)空店科指針,将在main函數中初始地址*/
/*為(wèi)多手播MAC轉發表分配内存,并初始數據為(wèi)男海0*/
obx_mc_mac_tbl = (struct table海樹_port_mac *)malloc(sizeof(struct就機 table_port_mac));
memset(obx_mc_mac_tbl,0,s工鄉izeof(struct table_port_mac));
電美
#include
#include
#include
if(pkt->data[0]&0x1)//MC MAC
{
u64 igmpv3_dmac = 0x1600005E0001;雜科
if(!ether_addr_equal(pkt->data,(u8 *友學)&igmpv3_dmac)) //IGMP
{
struct ethhdr *eth = (stru報村ct ethhdr *)pkt->data;
struct iphdr *ip = (struct iph劇可dr *)(eth+1);
int oft = 0;
if(eth->h_proto = htons(0x0800) && ip-器放>protocol == IPPROTO_IGMP)
{
oft = sizeof(*eth) + ip->計友ihl * sizeof(int);
igmpv3_report(pkt->um.inport,pkt->data+技裡oft);
}
}
}
void igmpv3_report河答(u8 inport,u8 *igmp)
{
struct igmpv3_report *上志g3r = (struct igmpv3_report *)ig唱他mp;
if(g3r->type == IGMPV3_HOST_MEMBER照短SHIP_REPORT)/*IGMPv3_聽也REPORT*/
{
u8 mc_mac[MAC_LEN] = {0x01,0話下0,0x5E};
u8 *mcip = NULL;
int k = 0;
for(;k
{
mcip = (u8 *)&g3r->grec[k].grec_mca;黃但
memcpy(&mc_mac[3],&mcip[1],3);下她/*僅複制後3字節數據*/
mc_mac[3] &= 0x7F;/*将第23bi從做t置0*/
join_leave_mc_mac(inport,m現習c_mac,g3r->grec[k].grec_type花工);
}
}
}
if(type == IGMPV3_CHANGE_TO_個文EXCLUDE)/*入組*/
{
obx_mc_mac_tbl->row[i].port 也腦|= 1<<>
}
else/*退組*/
{
obx_mc_mac_tbl->row[i]我錯.port &= ~ (1<<>
}
void output(u8 outtype,in人相t outport,struct fas玩兒t_packet *pkt)
{
if(outtype == UC)
{
pkt->um.outport = outport;
pkt_send_normal(pkt,pkt->um.len);
}
else
{
int i = 0;
for(;i<>
{
if(pkt->um.inport != i && (outport 器說& (1< 0)
{
pkt->um.outport = i;
pkt_send_normal(pkt,pkt-遠靜>um.len);
}
}
}
}