Question

I need to receive a multicast stream but filter incoming packets by source MAC address on CentOS 5.5. I'm planning to use libpcap library. Is it possible to join/leave multicast group using libpcap? If yes, how to do that?

Thanks

Was it helpful?

Solution

Sure, just construct and send the appropriate IGMP packets.

OTHER TIPS

1.Create dummy socket: sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

2.Bind it: rc = bind(sd, (sockaddr*) &addr, sizeof(sockaddr_in));

3.Join multicast group:

ip_mreq mreq;
mreq.imr_interface.s_addr = htonl(InterfaceIp);
mreq.imr_multiaddr.s_addr = htonl(DestIp);
if (setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
  close(sd);
  // Error handle...
}

Don't send or receive packets using dummy socket

4.open pcap using pcap_open_live()

The general idea is use regular socket in order to "tell" kernel to send IGMP join packet, and after use pcap in order to capture packets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top