Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.