Skip to content
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

Expose address from SockAddr for unix domains #332

Open
sullivan-sean opened this issue Aug 19, 2022 · 12 comments
Open

Expose address from SockAddr for unix domains #332

sullivan-sean opened this issue Aug 19, 2022 · 12 comments

Comments

@sullivan-sean
Copy link

It would be nice to be able to access the path of a unix socket from SockAddr similar to vsock_address

socket2 is being considered as a backend for UDS on windows in mio/tokio (tokio-rs/mio#1610 (comment)) and, if used, would need to expose the address of unix sockets from SocketAddr to mirror the implementation of SocketAddr in mio for unix

@sullivan-sean sullivan-sean changed the title Expose Unix path from SocketAddr Expose Unix path from SockAddr Aug 19, 2022
@sullivan-sean sullivan-sean changed the title Expose Unix path from SockAddr Expose address from SockAddr for unix sockets Aug 19, 2022
@sullivan-sean sullivan-sean changed the title Expose address from SockAddr for unix sockets Expose address from SockAddr for unix domain Aug 19, 2022
@sullivan-sean sullivan-sean changed the title Expose address from SockAddr for unix domain Expose address from SockAddr for unix domains Aug 19, 2022
@Thomasdezeeuw
Copy link
Collaborator

It would be nice to be able to access the path of a unix socket from SockAddr similar to vsock_address

Do you mean https://docs.rs/socket2/latest/socket2/struct.SockAddr.html#method.unix? I think we simply forgot to expose it in #249.

socket2 is being considered as a backend for UDS on windows in mio/tokio (tokio-rs/mio#1610 (comment)) and, if used, would need to expose the address of unix sockets from SocketAddr to mirror the implementation of SocketAddr in mio for unix

It's not ;)

@sullivan-sean
Copy link
Author

I meant more going the other way from SockAddr -> Path. Right now the SockAddr struct has private fields and there are no methods for Unix sockets exposing the Path which means once you have a SockAddr object (e.g. as returned from accept) you cannot get the corresponding Path back out, or tell whether a SockAddr is an unnamed or abstract Unix socket (i.e. the SockAddr here can't provide this functionality https://github.com/tokio-rs/mio/blob/master/src/sys/unix/uds/socketaddr.rs#L76-L96)

@Thomasdezeeuw
Copy link
Collaborator

We could add SocketAddr::as_pathname() -> Option<Path>.

@sullivan-sean
Copy link
Author

What is the desired behavior for abstract unix sockets where there is a name associated with the SockAddr struct but this name has no connection with filesystem pathnames? (https://manpages.ubuntu.com/manpages/trusty/man7/unix.7.html)

Unnamed unix sockets would presumably return None from as_pathname, and normal sockets would return a Path as expected.

@Thomasdezeeuw
Copy link
Collaborator

I think we can match the std::os::unix::net::SocketAddr type and match the is_unnamed, as_pathname and as_abstract_namespace functions.

@sullivan-sean
Copy link
Author

Okay, I think I have a good understanding of the desired API then -- I can take a stab at this and open a PR?

@Thomasdezeeuw
Copy link
Collaborator

Okay, I think I have a good understanding of the desired API then -- I can take a stab at this and open a PR?

Sounds good.

@aviramha
Copy link

aviramha commented Feb 22, 2023

Hey, this seems inactive and we need it for metalbear-co/mirrord#1105 .
I read the comments and will follow the desired design.

@Thomasdezeeuw
Copy link
Collaborator

Hey, this seems inactive and we need it for metalbear-co/mirrord#1105 . I read the comments and will follow the desired design.

Pr would be welcome 👍

@Thomasdezeeuw
Copy link
Collaborator

This has been done in #403.

@t4lz
Copy link
Contributor

t4lz commented Mar 8, 2023

This has been done in #403.

Only on unix though, so maybe there should still be an open issue for Windows.

@Thomasdezeeuw
Copy link
Collaborator

Reopening for Windows

@Thomasdezeeuw Thomasdezeeuw reopened this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants