microsoft / microsoft/WSL

AF_UNIX abstract on Windows do not work

Open
#4,240 40 comments 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    18362.175
  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)
    Trying to create an "abstract" namespace AF_UNIX application.
  • What's wrong / what should be happening instead:
    connect always returns EINVAL, regardless of what I try.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <afunix.h>
#include <stdio.h>

typedef SOCKET fd_t;
#define INVALID_FD INVALID_SOCKET

int socketpair(int domain, int type, int protocol, fd_t sv[2])

{
	SOCKET fd0 = INVALID_FD;
	SOCKET fd1 = INVALID_FD;
	SOCKET fdListen = INVALID_FD;
	struct sockaddr_un sa;
	int  len = 0;
	static int counter = 666;

	memset(&sa, 0, sizeof sa);
	sa.sun_family = AF_UNIX;
	_snprintf_s(sa.sun_path, ARRAYSIZE(sa.sun_path),_TRUNCATE, " ./xyx-%d-%d", GetCurrentProcessId(),counter++);
	len = sizeof(sa);
	sa.sun_path[0] = 0;

	if (domain != AF_UNIX || type != SOCK_STREAM || protocol != PF_UNSPEC)
	{
		return -1;
	}
	fdListen = socket(domain, type, protocol);// WSASocketW(domain, type, protocol, NULL, 0, 0);
	if (fdListen == INVALID_SOCKET)
	{
		goto Error;
	}
	printf("before bind address %s\n",sa.sun_path+1);
	if (bind(fdListen, (struct sockaddr *)&sa, len) == SOCKET_ERROR) {
		goto Error;
	}
	if (listen(fdListen, 5) == SOCKET_ERROR) {
		goto Error;
	}
	fd0 = socket(domain, type, protocol);
	if (fd0 == INVALID_SOCKET)
	{
		goto Error;
	}
	len = sizeof(sa);
	getsockname(fdListen, (struct sockaddr*)&sa, &len);
	printf("bound address %s\n",sa.sun_path+1);
	if (connect(fd0, (const struct sockaddr*)&sa, len) == SOCKET_ERROR)
	{
		fprintf(stderr,"connect error %d\n",WSAGetLastError());
		goto Error;
	}
	{
		int addrLen = sizeof(sa);;
		fd1 = accept(fdListen, (struct sockaddr*) & sa, &addrLen);
	}
	if (fd1 == SOCKET_ERROR)
	{
		goto Error;
	}

	sv[0] = fd0;
	sv[1] = fd1;
	closesocket(fdListen);
	printf("success\n");
	return 0;
Error:
	if (fd0 != INVALID_FD)
	{
		closesocket(fd0);
	}
	if (fd1 != INVALID_FD)
	{
		closesocket(fd1);
	}
	if (fdListen != INVALID_FD)
	{
		closesocket(fdListen);
	}
	return -1;
}
int main(int argc, char **argv) {
	
	fd_t x[2];
	WSADATA wsd;
	WSAStartup(WINSOCK_VERSION,&wsd);
	socketpair(AF_UNIX,SOCK_STREAM,0,x);
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the standalone C++ reproducer in the issue and run it on Windows build 18362.175. Trace the AF_UNIX socket, bind, getsockname, and connect calls, recording the Winsock error and checking whether abstract namespaces are supported in this environment. Done means establishing and addressing the cause of the EINVAL result, with the reproducer demonstrating the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
networking, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.