public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* On abstract sockets
       [not found] <1010129621.187968.1686049280947.ref@mail.yahoo.com>
@ 2023-06-06 11:01 ` Mike Gran
  0 siblings, 0 replies; only message in thread
From: Mike Gran @ 2023-06-06 11:01 UTC (permalink / raw)
  To: cygwin

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;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-06 11:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1010129621.187968.1686049280947.ref@mail.yahoo.com>
2023-06-06 11:01 ` On abstract sockets Mike Gran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).