NAME

zmq_vsock - 0MQ transport over Linux VSOCK (AF_VSOCK)

SYNOPSIS

The AF_VSOCK address family facilitates communication between virtual machines and the host they are running on. This address family is used by guest agents and hypervisor services that need a communications channel that is independent of virtual machine network configuration.

Note
AF_VSOCK is only supported on linux, https://man7.org/linux/man-pages/man7/vsock.7.html

ADDRESSING

A 0MQ endpoint is a string consisting of a 'transport'`://` followed by an 'address'. The 'transport' specifies the underlying protocol to use. The 'address' specifies the transport-specific address to connect to.

For the VSOCK transport, the transport is vsock, and the meaning of the 'address' part is defined below.

Binding a socket

When binding a 'socket' to a local address using zmq_bind() with the 'vsock' transport, the 'endpoint' shall be interpreted as an 'interface' followed by a colon and the port number to use.

An 'interface' may be specified by either of the following:

  • The wild-card *, meaning all available interfaces.

  • An integer returned by VMADDR_CID_LOCAL or @.

The port may be specified by:

  • A numeric value, usually above 1024 on POSIX systems.

  • The wild-card *, meaning a system-assigned ephemeral port.

Unbinding wild-card address from a socket

When wild-card * 'endpoint' was used in zmq_bind(), the caller should use real 'endpoint' obtained from the ZMQ_LAST_ENDPOINT socket option to unbind this 'endpoint' from a socket using zmq_unbind().

Connecting a socket

When connecting a socket to a peer address using zmq_connect() with the 'vsock' transport, the 'endpoint' shall be interpreted as a 'peer address' followed by a colon and the port number to use.

A 'peer address' must be a CID of the peer.

EXAMPLES

Assigning a local address to a socket
//  VSOCK port 5555 on all available interfaces
rc = zmq_bind(socket, "vsock://*:5555");
assert (rc == 0);
//  VSOCK port 5555 on the local loop-back interface on all platforms
cid = VMADDR_CID_LOCAL;
sprintf(endpoint, "vsock://%d:5555", cid);
rc = zmq_bind(socket, endpoint);
assert (rc == 0);
Connecting a socket
//  Connecting using a CID
sprintf(endpoint, "vsock://%d:5555", cid);
rc = zmq_connect(socket, endpoint);
assert (rc == 0);

SEE ALSO

AUTHORS

This page was written by the 0MQ community. To make a change please read the 0MQ Contribution Policy at https://zeromq.org/how-to-contribute/.