Open Zoxc opened 3 months ago
Well that's a fairly advanced use that needs cmsg kung-fu to set the source address for each packet. I think only nix supports this right now: https://docs.rs/nix/0.29.0/nix/sys/socket/enum.ControlMessage.html
You might have a point if std
didn't support wildcard UDP sockets, however documentation for UdpSocket::send
explicitly mentions them. Yet basic functionally like replying to packets is not possible. If you're not paying attention, you might assume (like me) that send
and recv
work for these. tokio
even has an incorrect UDP echo server example in their UdpSocket
documentation.
Windows does have APIs for these operations. It's pretty much required for any operation system which support wildcard bindings.
UdpSocket
allows binding to wildcard IPs likeIpAddr::V6(Ipv6Addr::UNSPECIFIED)
which means it can accept packets targeted to multiple IPs. However thesend
method does not allow specifying the source IP which means any reply packets may be send from the wrong interface. Therecv
method also doesn't allow getting the target IP which would need to be passed tosend
.This is a bit of a trap which isn't warned against in the documentation either.
Similar issue for
tokio
which mirrors the APIs: https://github.com/tokio-rs/tokio/issues/6737