-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicast Send/Receive Support #65
Comments
Thanks for stepping up and take the initiative! Here is a list of tasks on my mind:
We probably are okay, because:
another option is to use a different server port (i.e. not 5353) just for unicast. But it's tricky to pick a port number. It will be worth to check out what existing unicast DNS-SD software do.
The above is the main points I can think of for now. There are muddy areas in unicast DNS-SD I don't know enough about. Hope we can figure everything out along the way. |
Thanks for the information, I'll make a start and submit a draft PR for review when ready. |
Unfortunately, according to RFC 6702 5.5, this is required. The library should respond to any queries sent to the server's unicast address with unicast responses. Therefore the library needs to determine the destination address of the incoming packets. I did some research and there's not currently an easy way to get this information in a cross-platform way in Rust. The best example I've found so far is the multicast socket crate. So a potential way forward could be to base the implementation on this, although it would require separate implementations for windows and unix sockets, and would also require some unsafe code. Thoughts? |
I think it looks like a good way to go. Particularly we can use And instead of adding it directly into Then |
What prevents us from using the |
In this crate, we moved away from For the separate small crate I was suggesting above, yes we could use |
I think looking at the destination address could tell if it's unicast or multicast. The multicast packets be sent to the multicast address, but unicast to the host address. Unless unicast is also sent to the multicast address? |
Yes looking at the destination address can tell if it's unicast or multicast. The problem is that it's not easy to determine the destination address (AFAIK). We know which interface (and its local address) received the packet, but the local address is not necessarily same as the dest. address. As in earlier comments, one possibility is to use socket option I'm open to use other approaches or other crate if can solve the problem and not too big dependencies. |
So, have finally had some available time to complete phase one, I've just published a crate (https://crates.io/crates/socket-pktinfo) which provides a cross-platform way to consume the IP_PKTINFO. I will now work on a PR to integrate this into mdns-sd. |
It's awesome you created the Recently after discussing issue #179 and got inspired by it, I've been thinking a different approach to solve this issue:
I haven't get around to implement / verify this idea yet, but conceptually it might just work (I think). If that could work, it would relatively small change and no new dependency. If it doesn't work, I think we should use your crate. Let me know what you think, especially if any obvious errors in my thinking. Cheers! |
I know you can have several processes listening on the same multicast address:port. |
AFAIK binding to a multicast socket address directly is unsupported on Windows. I tested the following code: let multicast_socket_addr: SockAddr = SocketAddr::new(Ipv4Addr::new(238, 10, 20, 31).into(), 8000).into();
let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?;
socket.bind(&multicast_socket_addr)?; This is successful on Linux but on Windows returns Even if it were possible to do this on Windows, the other issue I see with this approach is that it delegates the selection of network interface to the operating system. IMO This isn't a desirable outcome as it prevents consumers of the library from selecting the network interface. |
I had a similar problem in Linux years ago. I added the multicast subnet to the interface to get around it. (I guess I should have been using INADDR_ANY) Might be worth trying, but then it would require users to do that. And it might not even be possible with some windows versions (Home vs Pro or whatever, I'm not a windows guy) |
OK, actually looking at the |
I cannot find my logs but my memory is that I tried and it didn't work. The current implementation is the best method I could find actually working (except for unicast). That said, I opened a PR #187 to try out unicast sockets. And checkout what I mentioned in the later part of the PR, i.e. a major problem is that we don't know the source IP of the packets. (Currently it's ok as we don't need to unicast the host). This problem persists regardless how we bind the sockets. (Is that correct understanding about your use case?) Without using |
yes we're using this option (when supported, otherwise SO_REUSEADDR). |
@pixsperdavid I think my experiment PR #187 showed the same thing as you mentioned in your earlier comment, i.e. binding multicast address does not always work. Plus I think we also have a problem of finding the source IP to support unicast use cases. So I think our best option is to use your crate |
I guess if rust-lang/socket2#313 gets eventually solved things might get simpler. (adding this issue to the list so we might get notified once there is progress in that regard) |
See #190 for draft |
I need unicast send/receive support for my current project so willing to work on adding this feature. Similar to #61, could you give an overview of tasks that are involved in implementing this?
The text was updated successfully, but these errors were encountered: