AF_UNIX socket in Linux above Windows WSL fails to bind to /mnt file: error 95, Operation not supported

2022-07-21T21:28:08

We need to connect a Windows client application to a Linux server one. The Linux side runs on top of WSL2 in Windows 10 (10.0.19044).

We want to use UNIX domain sockets, and followed guidance in https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/

The server program succeeds to bind to a file in the 'local' filesystem (such as /tmp/mysock), but fails to bind to a 'Windows-sided" file in the mounted drive (such as /mnt/c/mysock), which is required so that the server can accept connections from a Windows-side AF_UNIX socket.

The errno I get is 95 : "Operation not supported" I've tried running with sudo, but same result.

Any idea on what's going on?

The server code is:

#include <sys/socket.h>
#include <sys/un.h>

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>

#undef NDEBUG

// filename comes as command-line argument
int main(int argc, char *argv[])
{
    struct sockaddr_un addr;
    int ret = -1;
    
    printf("Starting NVC_LINUX...\n");
    
    assert(argc == 2);
    char *filename = argv[1];
    
    int sfd = socket(AF_UNIX, SOCK_STREAM, 0);
    assert(sfd != -1);

    // Delete any file that already exists at the address. Make sure the deletion
    // succeeds. If the error is just that the file/directory doesn't exist, it's fine.
    ret = remove(filename);
    assert(ret != -1 || errno == ENOENT);

    // Zero out the address, and set family and path.
    memset(&addr, 0, sizeof(struct sockaddr_un));
    addr.sun_family = AF_UNIX;
    assert(strlen(filename) <= sizeof(addr.sun_path) - 1);
    strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1);

    ret = bind(sfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
    if (ret == -1) printf("errno : %d - %s\n", errno, strerror(errno));
    assert(ret != -1);

    ret = listen(sfd, 1);
    assert(ret != -1);

    printf("Waiting to accept a connection...\n");
    // NOTE: blocks until a connection request arrives.
    int cfd = accept(sfd, NULL, NULL);
    assert(cfd != -1);
    printf("Accepted socket fd = %d\n", cfd);

    char cmd;
    char res[32];
    while (1)
    {
        // get char from Win side
        ssize_t num_read = read(cfd, (void *) &cmd, sizeof(cmd));
        assert(num_read == sizeof(cmd));

        printf("  cmd=%c\n", cmd);
        
        // generate reply
        sprintf(res, "Hello from Linux, %c\n", cmd);

        // send data
        ssize_t num_written = write(cfd, (const void *) res, sizeof(res));
        assert(num_written == sizeof(res));
    }

    (void) close(cfd);
    (void) close(sfd);

    printf("done.\n");
    return 0;
}

Copyright License:
Author:「Inaki Idigoras Igartua」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/73067135/af-unix-socket-in-linux-above-windows-wsl-fails-to-bind-to-mnt-file-error-95

About “AF_UNIX socket in Linux above Windows WSL fails to bind to /mnt file: error 95, Operation not supported” questions

We need to connect a Windows client application to a Linux server one. The Linux side runs on top of WSL2 in Windows 10 (10.0.19044). We want to use UNIX domain sockets, and followed guidance in ht...
Im trying to open a socket from Perl on Debian in WSL2 and it gives me an operation not supported, whereas it is fine on Debian in a VMWare VM. Diagnostics from my application are as follows: On De...
AF_UNIX sockets are supported on Windows starting in Windows Insider build 17093 (Windows 10 version 1803). See Windows/WSL Interop with AF_UNIX blog post on the Windows Command Line blog. There is...
Ubuntu 16.04.4 is running on windows 7 VM. I am trying to repo init into a shared folder. That shared folder is shared with a Windows VM, and the filesystem of that share does not support symlinks....
I have a windows10 machine with WSL2 and Ubuntu 20.04. I'm following the instructions at http://docs.yoctoproject.org/brief-yoctoprojectqs/index.html it all goes well until I try to run bitbake - ...
I'm using Docker via WSL2 on Windows 10. I only want to be able to create Linux containers and map a directory in the container to a WSL directory. I'm pretty sure WSL must already have access to a...
I'm using Guard inside a docker container, that is watching a mounted docker volume /docs/app. I'm running this container on Windows via WSL2. I find that if I map this docker vol to a path under ...
Regarding running Docker from within WSL without Docker Desktop, there is a comprehensive article here. However, When it comes to sharing the Docker daemon between WSL instances, the article only t...
I'm in need to share files between Linux (using WSL) and Windows, so that I can edit in Windows and compile in Linux. According to recomendations from Microsoft I should then keep my shared files u...
Postgres in WSL 2 - : Operation not permitted when I share volumes enter windows folder. I'm using Windows WSL2 Sub system to emulate Linux on a VM. I'm having trouble sharing the linux volume to a

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.