Skip to content

Incoming interface would be useful for multicast UDP #29

Closed

Description

@pusateri

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.

Activity

  1. alexcrichton commented on Oct 1, 2018

    @alexcrichton
    Member

    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?

  2. pusateri commented on Oct 1, 2018

    @pusateri
    Author

    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).

  3. pusateri commented on Oct 1, 2018

    @pusateri
    Author

    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.

  4. alexcrichton commented on Oct 8, 2018

    @alexcrichton
    Member

    @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?

  5. pusateri commented on Oct 9, 2018

    @pusateri
    Author

    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()

  6. alexcrichton commented on Oct 11, 2018

    @alexcrichton
    Member

    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)

  7. pusateri commented on Oct 11, 2018

    @pusateri
    Author

    Sure. I can try documenting a Rust version of recvmsg(). It does a lot more than incoming interface which others will probably appreciate.

  8. alexcrichton commented on Oct 11, 2018

    @alexcrichton
    Member

    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

  9. pusateri commented on Dec 10, 2018

    @pusateri
    Author

    nix-rust/nix#990 includes support for incoming interface index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions