-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Incoming interface would be useful for multicast UDP #29
Comments
Is there perhaps a missing function to bind for this library? Or could you narrow it down a bit what needs to happen in this library? |
recvfrom() doesn't provide the incoming interface for a packet. code that runs on multiple interfaces (like mDNS) needs the incoming interface (usually an index). |
This is important for multicast UDP because the destination address is always the multicast IP address and the source address can't be trusted because it's UDP and no 3-way handshake occurs to ensure return reachability. So the incoming interface is necessary to prevent spoofing. |
@pusateri er right yeah makes sense, but I'm curious what API needs to be added to this library to expose the incoming interface? Or put another way, what would a PR to solve this look like? |
Sorry, I misunderstood the question. Similar to the existing recv_from:
but with the new if_index. Maybe something like:
But any function name is fine if you prefer something like recv_from_if() or recv_if() |
Hm the implementation here is basically switching to |
Sure. I can try documenting a Rust version of recvmsg(). It does a lot more than incoming interface which others will probably appreciate. |
FWIW I think it'd be fine to basically add that API to this crate at any time, and we could probably just use the same raw pointers as the underlying C APIs and just push the safety to users, making it convenient to at least call the C API |
It looks like nix has already done this. |
nix-rust/nix#990 includes support for incoming interface index. |
In C, you use recvmsg() to get the incoming interface. It's a bit complicated for differences between unix and linux. Not sure about Windows. Sample C code is in this gist:
https://gist.github.com/pusateri/58d4ea943cfbfb7e2b3af955293227fe
recvfrom() won't give you the incoming interface, just the source address.
The text was updated successfully, but these errors were encountered: