title: How to receive multicast data on a multihomed server's non-default interface
body: <p>I have a linux server with two NICs (eth0 and eth1), and have set eth0 as default in "ip route."  Now I would like to receive multicast packets on eth1.  I have added "224.0.20.0/24 dev eth1  proto static scope link" to the routing table, and I connect as follows:</p>
  
  <pre><code>sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
  
  // port 12345, adress INADDR_ANY
  bind(sock, &amp;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, &amp;imreq, sizeof(imreq));
  </code></pre>
  
  <p>According to <code>ip maddr</code> it connects to that group on the right interface, and <code>tshark -i eth1</code> shows that I am actually getting multicast packets.</p>
  
  <p>However, I don't get any packets when calling <code>recvfrom(sock)</code>.  If I set "ip route default" to eth1 (instead of eth0), I do get packets via recvfrom.  Is this an issue with my code or with my network setup, and what is the correct way of doing this?</p>
  
  <p>(update) <strong>solution:</strong> caf hinted that <a href="https://stackoverflow.com/questions/5483779/receiving-multicast-on-a-server-with-multiple-interfaces-linux">this</a> might be the same problem; indeed: after doing <code>echo 0 &gt; /proc/sys/net/ipv4/conf/eth1/rp_filter</code> I can now receive multicast packets!</p>