zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.53k stars 2.34k forks source link

Dish socket should bind on multicast group IP instead of INADDR_ANY #4582

Open NoAnyLove opened 11 months ago

NoAnyLove commented 11 months ago

Issue description

For dish socket with UDP multicast, if it binds on INADDR_ANY (see code here), it will receive messages from other multicast IPs on the same port.

Given an example, we have 4 apps,

Note: D1 and D2 are on the same box

We expect D1 only receives messages from R1, and D2 only from R2. But in fact, D1 will receive messages from both R1 and R2, so does D2.

This prevents us to segregate the traffic with the same port, as mentioned in issue lcm-proj/lcm#186.

Can we change the bind to the multicast IP, which prevents us from receiving messages from other multicast addresses?

Quote from UNIX Network Programming, Volume 1,

Recall that we could just bind the wildcard IP address and port 8888, but binding the multicast address prevents the socket from receiving any other datagrams that might arrive destined for port 8888.

I'm more than happy to submit a PR if you agree with this change.

Reference:

Environment

Minimal test code / Steps to reproduce the issue

N/A