I have a linux server with two network adapters (eth0 and eth1) and set eth0 to "ip route" by default. Now I would like to receive multicast packets on eth1. I added "224.0.20.0/24 dev eth1 proto static scope link" to the routing table, and I connect as follows:
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); // port 12345, adress INADDR_ANY bind(sock, &bind_addr, sizeof(bind_addr)); // multicast address 224.0.20.100, interface address 10.13.0.7 (=eth1) setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imreq, sizeof(imreq));
According to ip maddr it connects to this group on the right interface, and tshark -i eth1 indicates that I am actually receiving multicast packets.
However, when I call recvfrom(sock) I do not receive any packets. If I set "ip route default" to eth1 (instead of eth0), I get packets through recvfrom. Is this a problem with my code or my network setup, and what is the correct way to do this?
(update) solution: caf hinted that this might be the same problem; really: after doing echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter now I can receive multicast packets!
hrr
source share