public inbox for
 help / color / mirror / Atom feed
From: Ken Brown <>
Subject: [PATCH 0/1] Recognizing native Windows AF_UNIX sockets
Date: Sat, 30 Jan 2021 11:34:35 -0500	[thread overview]
Message-ID: <> (raw)

This patch attempts to fix the problem reported here:

See also the followup here:

The problem, briefly, is that on certain recent versions of Windows
10, including 2004 but not 1909, native Windows AF_UNIX sockets are
represented by reparse points that Cygwin doesn't recognize.  As a
result, tools like 'ls' and 'rm' don't work.

I will get access to a machine running 2004 so I can test my patch,
but I'm posting it now in case someone else wants to test it before I
can.  To test it, compile and run the program native_unix_socket.c
appended below, and then try to remove the file foo.sock that it
creates.  This should fail on W10 2004 without my patch, but it should
succeed like this with the patch:

$ gcc -o native_unix_socket native_unix_socket.c -lws2_32

$ ./native_unix_socket.exe
getsockname works
fam = 1, len = 11
offsetof clen = 9
strlen = 8
name = foo.sock

$ ls -l foo.sock
-rwxr-xr-x 1 kbrown None 0 2021-01-30 10:46 foo.sock*

$ rm foo.sock

$ ls -l foo.sock
ls: cannot access 'foo.sock': No such file or directory

$ cat native_unix_socket.c

   gcc -o native_unix_socket native_unix_socket.c -lws2_32



#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stddef.h>
#include <stdio.h>
/* #include <afunix.h> */


#define UNIX_PATH_MAX 108

typedef struct sockaddr_un
     ADDRESS_FAMILY sun_family;     /* AF_UNIX */
     char sun_path[UNIX_PATH_MAX];  /* pathname */

int __cdecl main(int argc, char *argv[])
    WSADATA wsadata;
    struct sockaddr_un addr;
    socklen_t len;
    int z = AF_UNIX;
    SOCKET s, s0;

    if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
        printf("STartup failed\n");
        return 0;
    s0 = socket(AF_UNIX, SOCK_STREAM, 0);
    memset(&addr, 0, sizeof(addr));

    addr.sun_family = AF_UNIX;
    //strcpy(addr.sun_path, argv[1]);
    strcpy(addr.sun_path, "foo.sock");

    z = bind(s0, (const struct sockaddr *) &addr, strlen(addr.sun_path) + sizeof (addr.sun_family));
    if (z != 0) {
        printf("bind failed %ld\n", WSAGetLastError());
    len = sizeof(addr);
    z = getsockname(s0, (struct sockaddr *)&addr, &len);
    if (z != 0) {
        printf("getsockname failed %ld\n", WSAGetLastError());
    } else {
        printf("getsockname works\n");
        printf("fam = %d, len = %d\n", addr.sun_family, len);
        int clen = len - offsetof(struct sockaddr_un, sun_path);
        printf("offsetof clen = %d\n", clen);
        printf("strlen = %zd\n", strlen(addr.sun_path));
        printf("name = %s\n", addr.sun_path);

Ken Brown (1):
  Cygwin: recognize native Windows AF_UNIX sockets as reparse points

 winsup/cygwin/ | 4 ++++
 1 file changed, 4 insertions(+)


             reply	other threads:[~2021-01-30 16:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-30 16:34 Ken Brown [this message]
2021-01-30 16:34 ` [PATCH 1/1] Cygwin: recognize native Windows AF_UNIX sockets as reparse points Ken Brown
2021-01-30 20:58 ` [PATCH 0/1] Recognizing native Windows AF_UNIX sockets Ken Brown
2021-02-01  9:54 ` Corinna Vinschen

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:

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

  git send-email \ \ \ \

* 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).