On abstract sockets

Mike Gran spk121@yahoo.com
Tue Jun 6 11:01:20 GMT 2023


Hello Cygwin-

I just wanted to double-check my understanding that binding
an abstract socket (a NULL-prefixed filename) is not currently
supported on Cygwin. I think there used to be some sort
of emulation of abstract sockets, but, that's not true anymore,
right?

With the sample program below, bind for AF_UNIX traces into
fhandler_socket_local::bind, since AF_UNIX == AF_LOCAL.

fhandler_socket_local::bind copies the NULL-prefixed abstract
name using 

  strncpy (sun_path, un_addr->sun_path, len);

which truncates sun_path to be an empty string. Searching
for the existence of the empty path causes errno ENOENT.

Also, it seems unclear if winsock2 sockets supports abstract sockets
anyway.

Thanks,
Mike Gran

// tmp.c
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    int s;
    struct sockaddr_un name;
    int ret;

    s = socket(AF_UNIX, SOCK_STREAM, 0);
    if (s == -1) {
        perror("socket");
        exit(1);
    }

    const char path[5] = { 0, 'f', 'o', 'o', 0};
    memset(&name, 0, sizeof(name));    
    name.sun_family = AF_UNIX;
    memcpy(name.sun_path, path, sizeof(path));
    
    ret = bind(s, (const struct sockaddr *) &name, 2 + sizeof(path));
    if (ret == -1) {
        perror("bind");
        exit(1);
    }
    return 0;
}


More information about the Cygwin mailing list