-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
- Your Windows build number: (Type
verat 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);
}
therealkenc, poscat0x04, huangqinjin, enzy, lusitania and 19 more