vsock(7) Miscellaneous Information Manual vsock(7) vsock - Linux VSOCK #include #include stream_socket = socket(AF_VSOCK, SOCK_STREAM, 0); datagram_socket = socket(AF_VSOCK, SOCK_DGRAM, 0); VSOCK , . , , . : SOCK_STREAM SOCK_DGRAM. SOCK_STREAM . SOCK_DGRAM . . socket(AF_VSOCK, socket_type, 0); , connect(2) . , . bind(2) listen(2). send(2) write(2), recv(2) read(2). 32- (CID) 32- . CID , . , . struct sockaddr_vm { sa_family_t svm_family; /* Address family: AF_VSOCK */ unsigned short svm_reserved1; unsigned int svm_port; /* Port # in host byte order */ unsigned int svm_cid; /* Address in host byte order */ unsigned char svm_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - sizeof(unsigned short) - sizeof(unsigned int) - sizeof(unsigned int)]; }; svm_family is always set to AF_VSOCK. svm_reserved1 is always set to 0. svm_port contains the port number in host byte order. The port numbers below 1024 are called privileged ports. Only a process with the CAP_NET_BIND_SERVICE capability may bind(2) to these port numbers. svm_zero must be zero-filled. There are several special addresses: VMADDR_CID_ANY (-1U) means any address for binding; VMADDR_CID_HYPERVISOR (0) is reserved for services built into the hypervisor; VMADDR_CID_LOCAL (1) is the well-known address for local communication (loopback); VMADDR_CID_HOST (2) is the well-known address of the host. VMADDR_PORT_ANY (-1U) . . SOCK_STREAM , . . CID , CID . CID. ioctl The following ioctls are available on the /dev/vsock device. IOCTL_VM_SOCKETS_GET_LOCAL_CID CID . unsigned int. ioctl(fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid); VMADDR_CID_ANY , CID IOCTL_VM_SOCKETS_GET_LOCAL_CID. VMADDR_CID_LOCAL (1) directs packets to the same host that generated them. This is useful for testing applications on a single host and for debugging. The local CID obtained with IOCTL_VM_SOCKETS_GET_LOCAL_CID can be used for the same purpose, but it is preferable to use VMADDR_CID_LOCAL . EACCES CAP_NET_BIND_SERVICE. EADDRINUSE , . EADDRNOTAVAIL CID. EINVAL . : , sockaddr_vm . ENOPROTOOPT setsockopt(2) getsockopt(2). ENOTCONN . EOPNOTSUPP . : MSG_OOB, send(2), MSG_PEEK recv(2). EPROTONOSUPPORT . 0. ESOCKTNOSUPPORT socket(2). SOCK_STREAM SOCK_DGRAM. VMware (VMCI) Linux 3.9. KVM (virtio) Linux 4.8. Hyper-V Linux 4.14. VMADDR_CID_LOCAL is supported since Linux 5.6. Local communication in the guest and on the host is available since Linux 5.6. Previous versions supported only local communication within a guest (not on the host), and with only some transports (VMCI and virtio). . bind(2), connect(2), listen(2), recv(2), send(2), socket(2), capabilities(7) Azamat Hackimov , Dmitriy Ovchinnikov , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . vsock(7)