9.0

Table Of Contents
VMCI Sockets Programming Guide
12 VMware, Inc.
Connection-Oriented Stream Socket
Toestablishastreamsocket,includethesedeclarationsandcalls,andreplaceAF_INETwithafVMCI,assetby
VMCISock_GetAFValue().
int sockfd_stream;
int afVMCI = VMCISock_GetAFValue();
if ((sockfd_stream = socket(afVMCI, SOCK_STREAM, 0)) == -1) {
perror(“Socket stream”);
}
Connectionless Datagram Socket
Toestablishadatagramsocket,includethesedeclarationsandcalls:
int sockfd_dgram;
int afVMCI = VMCISock_GetAFValue();
if ((sockfd_dgram = socket(afVMCI, SOCK_DGRAM, 0)) == -1) {
perror(“Socket datagram”);
}
Initializing the Address Structure
Toinitializetheaddressstructurepassedtobind(),insertthesesourcecodestatements,wheresockaddr_vm
forVMCIsocketsreplacessockaddr_infornetworksockets.
struct sockaddr_vm my_addr = {0};
my_addr.svm_family = afVMCI;
my_addr.svm_cid = VMADDR_CID_ANY;
my_addr.svm_port = VMADDR_PORT_ANY;
Thefirstlinedeclaresmy_addrasasockaddr_vmstructureandinitializesitwithzeroes.AF_INETreplaces
afVMCI.BothVMADDR_CID_ANYandVMADDR_PORT_ANYarepredefinedsothatatruntime,theservercanfillin
theappropriateCIDandportvaluesduringabindoperation.Theinitiatingsideoftheconnection,theclient,
mustprovidetheCI
Dandport,insteadofVMADDR_CID_ANYandVMADDR_PORT_ANY.
Communicating Between Host and Guest
Tocommunicatebetweenaguestvirtualmachineanditshost,establishaVMCIsocketsconnectionusingthe
SOCK_DGRAMsockettype,oronproductplatformsthatsupportit(mostdo),theSOCK_STREAMsockettype.
VMCI Sockets and Networking
Iflimitednetworkaccessissufficientforavirtualmachine,youcouldreplaceTCPnetworkingwithVMCI
sockets,therebysavingmemoryandprocessorbandwidthbydisablingthenetworkstack.Ifnetworkingis
enabled,asittypicallyis,VMCIsocketscanstillmakesomeoperationsrunfaster.
Setting Up a Networkless Guest
Youcaninstallavirtualmachinewithoutanynetworkingpackages,soitcannotconnecttothenetwork.
The systemimageofanetworkfreeoperatingsystemislikelytobesmall,andisolationisasecurity
advantage,attheexpenseofconvenience.Installnetworkfreesystemsasanetworklessguest.Afterinstalling
VMw
areTools,thehostcanuseVMCIsocketstocommunicatewiththenetworklessguest.
Youcreateanetworklessguestwiththeoption“Donotuseanetworkconnection”intheWorkstationwizard.
Alternatively,youcantransformanetworkcapableguestintoanetworklessguestbyremovingallitsvirtual
networkingdevicesintheW
orkstationUI.