AF_UNIX equivalent for Windows [duplicate] AF_UNIX equivalent for Windows [duplicate] windows windows

AF_UNIX equivalent for Windows [duplicate]


Windows has recently (Windows 10 Insider build 17063) implemented support for AF_UNIX, so you can use it in future windows builds.

However not all of it is implemented, the below features don't work.

  • AF_UNIX datagram (SOCK_DGRAM) or sequence packet (SOCK_SEQPACKET) socket type.
  • Ancillary data: Linux's unix socket implementation supports passing ancillary data such as passing file descriptors (SCM_RIGHTS) or credentials (‘SCM_CREDENTIALS`) over the socket. There is no support for ancillary data in the Windows unix socket implementation.
  • Autobind feature (see the section on ‘sockaddr_un’ for details).
  • socketpair: socketpair socket API is not supported in Winsock 2.0.

Source: https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/


Probably not the answer you want to hear, but COM is one of several standard mechanisms to achieve inter-process communication in Windows. It has it's issues that annoy developers - but it works quite well for all the requirements you listed.

As for IP sockets, you mentioned the issue of "can be seen in the network". This is not the case if you just simply bind your server socket to the localhost address (127.0.0.1). (2021 disclaimer - there is a potential vulnerability - see comments below).

SOCKET s;const DWORD LOCAL_HOST_IP = 0x7f000001; // 127.0.0.1sockaddr_in addrLocal = {};   s = socket(AF_INET, SOCK_STREAM, 0);addrLocal.sin_family = AF_INET;addrLocal.sin_port = htons(YOUR_APPLICATION_PORT);addrLocal.sin_addr.s_addr = htonl(LOCAL_HOST_IP);s = SOCKET(AF_INET, SOCK_STREAM, 0);bind(s, (sockadr*)&addrLocal, sizeof(addrLocal));


I have found the answer.

The big difference is that the handle the waits a connection is the same that does communications to a client. I would have to create a new named pipe for the server to wait for the next client.

References:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365799%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365588%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365603%28v=vs.85%29.aspx