Comments (10)
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?
from socket2.
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).
from socket2.
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.
from socket2.
@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?
from socket2.
Sorry, I misunderstood the question. Similar to the existing recv_from:
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
but with the new if_index. Maybe something like:
pub fn recv_from_intf(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr, usize)>
But any function name is fine if you prefer something like recv_from_if() or recv_if()
from socket2.
Hm the implementation here is basically switching to recvmsg
, right? If that's the case then I think we'd probably want to expose the lowest level API, and leave all the various parsing of the result to calling code (although we could also add conveniences as well)
from socket2.
Sure. I can try documenting a Rust version of recvmsg(). It does a lot more than incoming interface which others will probably appreciate.
from socket2.
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
from socket2.
It looks like nix has already done this.
https://github.com/nix-rust/nix/blob/master/src/sys/socket/mod.rs
Test here:
https://github.com/nix-rust/nix/blob/master/test/sys/test_socket.rs (test_scm_rights)
from socket2.
nix-rust/nix#990 includes support for incoming interface index.
from socket2.
Related Issues (20)
- Question: Possible to support architectures that only provide the `std::net` interface (and only TCP)? HOT 4
- Windows: `sa_family_t` should use `ADDRESS_FAMILY` from `windows-sys` HOT 5
- nonblocking connect HOT 6
- Set `ss_len` when creating `SockAddr` from std HOT 1
- Why cannot find WASStartup and WSACleanup in source code? HOT 7
- bind_device succeeds, but subsequent sends fail with no such device or address. HOT 5
- QUESTION: How to special `laddr` when dialing connection? HOT 3
- Android support HOT 3
- don'tassign8080 port
- Currently socket2 has no way to set the DF bit on packets. The attached patch adds it. HOT 3
- Error: BoxSend(Os { code: 98, kind: AddrInUse, message: "Address already in use" }) HOT 2
- How to read EventExtra from the event? HOT 2
- socket() always fails on WSL1 due to unsupported SOCK_CLOEXEC flag HOT 5
- Support for {recv,send}mmsg HOT 2
- New release HOT 1
- socket error HOT 1
- Provide `bind_device_by_index_v{4|6}` methods for linux. HOT 7
- Shouldn't socket recv() promise in its doc allows a nicer API HOT 7
- ESP-IDF compiation error HOT 4
- Possible to publish a new patch release? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket2.