My understanding is this, if a socket does not bind local address(or binds to
INADDR_ANY), and does not call
connect() to set remote address/port, then there is no way to prevent unicast packets to be delivered to a multicast listening socket, or vice versa, since the only check remaining when a packet reaches the UDP layer is port number match (again, since the other criteria such as remote/local addresses are both zero). The hypothetical scenario I can think of is like this:
- on a machine with one interface, primary IP address is IP_ADDR
- socket A listens to UDP multicast address MULTICAST_IP_A with port number PORT_A
- socket B listens to UDP unicast, on PORT_B
Then are any of the following statements true?
- multicast packet sent to group address MULTICAST_IP_A with port number PORT_B will be delivered to socket B
- unicast packet sent to IP_ADDR:PORT_A will be delivered to socket A
I looked into the Linux IPv4 source code and so far it seems that the above two will happen, for example,
__udp_is_mcast_sock() would return
true even if
inet->mc_list is empty, because
1. But I'm no expert, would like to hear someone validate/invalidate the claims and maybe give some pointers to the code. thanks!