Problem with Linux socket filter
Hi,
I am facing some problem while implementing the filter.
The problem is in want to receive only those packet which matches multicast mac ID or the mac ID of my nic. I am opening the RAW socket and putting it in PACKET_MR_PROMISC mode. I am receiving all the packet. I want to receive only the packerts which are matching the macID.
This is the code snippet
sdRdWr=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
if(sdRdWr<0)
{
perror("socket");
exit(1);
}
memset(&ifr,0,sizeof(ifr));
strncpy(ifr.ifr_name, device,sizeof(ifr.ifr_name));
if(ioctl(sdRdWr, SIOCGIFINDEX, &ifr)<0)
{
close(sdRdWr);
perror("cant get flags");
exit(1);
}
sll.sll_family=AF_PACKET;
sll.sll_ifindex=ifr.ifr_ifindex;
sll.sll_protocol=htons(ETH_P_ALL);
if(bind(sdRdWr,(struct sockaddr*)&sll,sizeof(sll))<0)
{
perror("bind");
exit(1);
}
memset(&mr,0,sizeof(mr));
mr.mr_ifindex=ifr.ifr_ifindex;
mr.mr_type=PACKET_MR_PROMISC;
if(setsockopt(sdRdWr,SOL_PACKET,PACKET_ADD_MEMBERSHIP,&mr,sizeof(mr))<0)
{
.
.
.
.
Thanks in advance
Shree Kant
|