Closed keepsimple1 closed 8 months ago
The test failure on Ubuntu Linux is:
thread 'service_daemon::tests::service_with_temporarily_invalidated_ptr' panicked at 'called
Result::unwrap()on an
Errvalue: Msg("socket bind to [ff02::fb]:5353 failed: Invalid argument (os error 22)")', src/service_daemon.rs:2496:47
The IPv6 addr ff02::fb
is a link-local multicast address (according to chatGPT). Binding to it works fine on macOS but for some reason it failed on Linux.
This is to experiment some ideas in issue #65 . It does not fully address the issue (details below) but showing it's possible to bind to multicast address and use separate unicast sockets. (only tested on macOS at the moment).
In theory, it is mainly based on two statements in the book "Unix network programming" by W. Richard Stevens:
... Nothing special is required to send a multicast datagram: the application does not have to join the multicast group.
hence, in this patch, we use
uni_sock
in thefn send_packet
even for sending multicast packets... Some applications also bind the multicast address to the socket, in addition to the port. This prevents any other datagrams that might be received for that port from being delivered to the socket.
Hence, in this patch, we bind the multicast socket to
GROUP_ADDR_V4/6
, instead ofINADDR_ANY
, to prevent this socket from receiving unicast packets.However, there is a problem: even with dedicated unicast sockets, we don't know the source IP of unicast packets received. This is because we are using
.read()
, not.recv_from()
. This is an old problem because insocket2
.recv_from()
became unsafe to use since 0.4.0.In my understanding, a prime use case of issue #65 is that:
QU
flag in its question.QU
flag, the responder sends back responses in unicast back to the querier.Although this patch can support receiving the unicast responses, the responder cannot do step 3 as they don't know the unicast IP of the querier.
A more rare use case is that the querier directly sends questions in unicast, which could be supported by this patch.