Call VMCISock_GetAFValue() to obtain the VMCI address family. Declare structure
sockaddr_vm instead of
sockaddr_in. In the
socket() call, replace the
AF_INET address family with the VMCI address family.
When the client creates a connection, instead of providing an IP address to choose its server, the client must provide the context ID (CID) of a virtual machine or host. An application running on a virtual machine uses the local context ID for
bind() and a remote context ID for
connect().
In virtual hardware version 6 (Workstation 6.0.x releases), the VMCI virtual device is not present by default. After you upgrade a virtual machine’s virtual hardware to version 7, the following line appears in the
.vmx configuration file, and when the virtual machine powers on, a new
vmci0.id line also appears there.
In virtual hardware version 7 (Workstation 6.5 releases), the VMCI virtual device is present by default. When you create a virtual machine, the
.vmx configuration file contains lines specifying PCI slot number and the ID of the VMCI device. On the
vmci0.id line, CID is the number in double quotes.
For convenience, you can call the VMCISock_GetLocalCID() function to obtain the local system’s CID. This function works on both the ESXi host and guest virtual machines, although the ESXi host always has CID = 2, even in a nested virtual machine (VM running in a VM).
To initialize the address structure passed to bind(), insert these source code statements, where
sockaddr_vm for VMCI sockets replaces
sockaddr_in for network sockets.
The first line declares my_addr as a
sockaddr_vm structure and initializes it with zeroes.
AF_INET replaces
afVMCI. Both
VMADDR_CID_ANY and
VMADDR_PORT_ANY are predefined so that at runtime, the server can fill in the appropriate CID and port values during a bind operation. The initiating side of the connection, the client, must provide the CID and port, instead of
VMADDR_CID_ANY and
VMADDR_PORT_ANY.