Skip to content

Cannot connect to abstract unix domain socket #52165

Closed
@ghost

Description

Hello,

I'm using stable Rust 1.27.0.

According to man 7 unix, about abstract socket:

an abstract socket address is distinguished (from a pathname socket) by the fact that sun_path[0] is a null byte ('\0'). The socket's address in this namespace is given by the additional bytes in sun_path that are covered by the specified length of the address structure. (Null bytes in the name have no special significance.) The name has no connection with filesystem pathnames. When the address of an abstract socket is returned, the returned addrlen is greater than sizeof(sa_family_t) (i.e., greater than 2), and the name of the socket is contained in the first (addrlen - sizeof(sa_family_t)) bytes of sun_path.

I failed to run this:

use std::os::unix::net::UnixListener;
use std::path::PathBuf;

fn main() {
    let sock_path = PathBuf::from("\0test");
    match UnixListener::bind(&sock_path) {
        Ok(_) => println!("Server running at {:?}", &sock_path),
        Err(err) => eprintln!("Failed to start server: {}", &err),
    };
}

The error message was paths may not contain interior null bytes. I searched and found the code here:

https://doc.rust-lang.org/src/std/sys/unix/ext/net.rs.html#61

I consider this a bug, but I'm really not sure. May I ask if you could help?

Thank you,

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions