Creating a vsock socket on the host results in ENODEV

I'm trying to create a vsock socket on the host but it fails with ENODEV. I know I can use a VZVirtioSocketDeviceConfiguration and get one through the Virtualization Framework, but for my use case it would be easier to integrate if I can create the socket myself.

This works from inside a VM assuming I've configured a VZVirtioSocketDeviceConfiguration, but not on the host.

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
int main() {

  int fd = socket(PF_VSOCK, SOCK_STREAM, 0);
  if (fd < 0 ) {
        perror("socket");
  }

  return 0;
}
Post not yet marked as solved Up vote post of tzzz Down vote post of tzzz
523 views

Replies

This is expected.

On the host side, it is Virtualization framework that takes care of establishing and maintaining the connections. The sockets can only be established from VZVirtioSocketDevice.

On the guest side, the macOS kernel interacts with Virtualization framework which is why you can create such sockets inside the VM.