9.0

Table Of Contents
VMware, Inc. 11
2
Thischapterincludesthefollowingtopics:
“PortingExistingSocketApplications”onpage 11
“CommunicatingBetweenHostandGuest”onpage 12
Porting Existing Socket Applications
Modifyingexistingsocketimplementationsisstraightforward.Thischapterdescribesthelinesofcodeyou
mustchange.
Include a New Header File
ToobtainthedefinitionsforVMCIsockets,includethevmci_sockets.hheaderfile.
#include "vmci_sockets.h"
Change AF_INET to VMCI Sockets
CallVMCISock_GetAFValue()toobtaintheVMCIaddressfamily.Declarestructuresockaddr_vminsteadof
sockaddr_in.Inthesocket()call,replacetheAF_INETaddressfamilywiththeVMCIaddressfamily.
Whentheclientcreatesaconnection,insteadofprovidinganIPaddresstochooseitsserver,theclientmust
providethecontextID(CID)ofavi
rtualmachineorhost.Anapplicationrunningonavirtualmachineuses
thelocalcontextIDforbind()andaremotecontextIDforconnect().
Obtain the CID
Invirtualhardwareversion6(Workstation6.0.xreleases),theVMCIvirtualdeviceisnotpresentbydefault.
Afteryouupgradeavirtualmachine’svirtualhardwaretoversion7,thefollowinglineappearsinthe.vmx
configurationfile,andwhenthevirtualmachinepowerson,anewvmci0.idlinealsoappearsthere.
vmci0.present = "TRUE"
Invirtualhardwareversion7(Workstation6.5releases),theVMCIvirtualdeviceispresentbydefault.When
youcreateavirtualmachine,the.vmxconfigurationfilecontainslinesspecifyingPCIslotnumberandtheID
oftheVMCIdevice.Onthevmci0.idline,CIDisthenumberindoublequotes.
vmci0.pciSlotNumber = "36"
vmci0.id = "1066538581"
The VMCISock_GetLocalCID() Function
Forconvenience,youcancalltheVMCISock_GetLocalCID()functiontoobtainthelocalsystem’sCID.This
functionworksonboththeESXihostandguestvirtualmachines,althoughtheESXihostalwayshasCID=2,
eveninanestedvirtualmachine(VMrunninginaVM).
Porting to VMCI Sockets
2