PACKET_MR_MULTICAST causes broadcast pkt to be rcvd - Linux

This is a discussion on PACKET_MR_MULTICAST causes broadcast pkt to be rcvd - Linux ; Hi All, Sorry for restarting the old topic.. http://groups.google.co.in/group/com...828417467fa6e6 But I am facing the same problem.. I went through the mails.. But I was not able able to find any solution.. I am trying to receive multicast pkts with a ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: PACKET_MR_MULTICAST causes broadcast pkt to be rcvd

  1. PACKET_MR_MULTICAST causes broadcast pkt to be rcvd

    Hi All,
    Sorry for restarting the old topic..
    http://groups.google.co.in/group/com...828417467fa6e6
    But I am facing the same problem.. I went through the mails..
    But I was not able able to find any solution..
    I am trying to receive multicast pkts with a specific mac address. But
    the kernel is passing me other multicast packets as well.
    Is there any way through which I can receive only the packets meant for
    me.(i.e having the same multicast mac and protocol type)
    The Code Snippet is given below..

    strcpy(device,"eth0");
    memset(&sll,'\0',sizeof(struct sockaddr_ll));
    sdRdWr=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_2));
    if(sdRdWr<0)
    {
    perror("socket");
    exit(1);
    }
    memset(&ifr,0,sizeof(ifr));
    memset(&toAddr, 0, sizeof(toAddr));
    toAddr.sa_family = AF_PACKET;
    strncpy(toAddr.sa_data, device, sizeof(toAddr.sa_data));
    toLen = sizeof(toAddr);

    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_802_2);
    sll.sll_pkttype = PACKET_MULTICAST;
    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_MULTICAST;;
    mr.mr_alen = 6;
    bzero((char *)&mr.mr_address, 6);
    mr.mr_address = //multicast mac address
    // memcpy(mr.mr_address,eaddr.ether_addr_octet,6);

    if(setsockopt(sdRdWr,SOL_PACKET,PACKET_ADD_MEMBERS HIP,&mr,sizeof(mr))<0)
    {
    perror("setsockopt error");
    exit(1);
    }
    length = sizeof(struct sockaddr);
    while (1)
    {

    x=recvfrom(sdRdWr, outpack, 23,0,(struct sockaddr *)&toAddr,
    &length);
    if (x>1)
    {
    printf("Data read is ");
    for(i = 0;i < x; i++)
    {
    printf("%2.2x ",outpack[i]);
    }
    printf("\n");
    }

    }
    }

    Thanks in advance
    Shree Kant


  2. Re: PACKET_MR_MULTICAST causes broadcast pkt to be rcvd


    tinku wrote:
    > Hi All,
    > Sorry for restarting the old topic..
    > http://groups.google.co.in/group/com...828417467fa6e6
    > But I am facing the same problem.. I went through the mails..
    > But I was not able able to find any solution..
    > I am trying to receive multicast pkts with a specific mac address. But
    > the kernel is passing me other multicast packets as well.
    > Is there any way through which I can receive only the packets meant for
    > me.(i.e having the same multicast mac and protocol type)

    You could specify which multicast group you want to receive by calling
    setsockopt().


    > The Code Snippet is given below..
    >
    > strcpy(device,"eth0");
    > memset(&sll,'\0',sizeof(struct sockaddr_ll));
    > sdRdWr=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_2));
    > if(sdRdWr<0)
    > {
    > perror("socket");
    > exit(1);
    > }
    > memset(&ifr,0,sizeof(ifr));
    > memset(&toAddr, 0, sizeof(toAddr));
    > toAddr.sa_family = AF_PACKET;
    > strncpy(toAddr.sa_data, device, sizeof(toAddr.sa_data));
    > toLen = sizeof(toAddr);
    >
    > 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_802_2);
    > sll.sll_pkttype = PACKET_MULTICAST;
    > 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_MULTICAST;;
    > mr.mr_alen = 6;
    > bzero((char *)&mr.mr_address, 6);
    > mr.mr_address = //multicast mac address
    > // memcpy(mr.mr_address,eaddr.ether_addr_octet,6);
    >
    > if(setsockopt(sdRdWr,SOL_PACKET,PACKET_ADD_MEMBERS HIP,&mr,sizeof(mr))<0)


    Is the option should be IP_ADD_MEMBERSHIP? it expects also "struct
    ip_mreq"
    > {
    > perror("setsockopt error");
    > exit(1);
    > }
    > length = sizeof(struct sockaddr);
    > while (1)
    > {
    >
    > x=recvfrom(sdRdWr, outpack, 23,0,(struct sockaddr *)&toAddr,
    > &length);
    > if (x>1)
    > {
    > printf("Data read is ");
    > for(i = 0;i < x; i++)
    > {
    > printf("%2.2x ",outpack[i]);
    > }
    > printf("\n");
    > }
    >
    > }
    > }
    >
    > Thanks in advance
    > Shree Kant



+ Reply to Thread