public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mike Gran <spk121@yahoo.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: On abstract sockets
Date: Tue, 6 Jun 2023 11:01:20 +0000 (UTC)	[thread overview]
Message-ID: <1010129621.187968.1686049280947@mail.yahoo.com> (raw)
In-Reply-To: <1010129621.187968.1686049280947.ref@mail.yahoo.com>

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

           reply	other threads:[~2023-06-06 11:05 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1010129621.187968.1686049280947.ref@mail.yahoo.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1010129621.187968.1686049280947@mail.yahoo.com \
    --to=spk121@yahoo.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).