Changeset 19233 in vbox for trunk/src/VBox/Main/generic
- Timestamp:
- Apr 28, 2009 10:16:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/generic/NetIf-generic.cpp
r17997 r19233 28 28 29 29 #include "HostNetworkInterfaceImpl.h" 30 #include "ProgressImpl.h" 31 #include "VirtualBoxImpl.h" 30 32 #include "netif.h" 31 33 32 34 #define VBOXNETADPCTL_NAME "VBoxNetAdpCtl" 33 35 34 static int NetIfAdpCtl( HostNetworkInterface * pIf, const char *pszAddr, const char *pszOption, const char *pszMask)35 { 36 const char *args[] = { NULL, NULL, pszAddr, pszOption, pszMask, NULL };36 static int NetIfAdpCtl(const char * pcszIfName, const char *pszAddr, const char *pszOption, const char *pszMask) 37 { 38 const char *args[] = { NULL, pcszIfName, pszAddr, pszOption, pszMask, NULL }; 37 39 38 40 char szAdpCtl[RTPATH_MAX]; … … 45 47 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME); 46 48 args[0] = szAdpCtl; 47 Bstr interfaceName;48 pIf->COMGETTER(Name)(interfaceName.asOutParam());49 Utf8Str strName(interfaceName);50 args[1] = strName;51 49 if (!RTPathExists(szAdpCtl)) 52 50 { … … 73 71 } 74 72 73 static int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const char *pszOption, const char *pszMask) 74 { 75 Bstr interfaceName; 76 pIf->COMGETTER(Name)(interfaceName.asOutParam()); 77 Utf8Str strName(interfaceName); 78 return NetIfAdpCtl(strName, pszAddr, pszOption, pszMask); 79 } 80 75 81 int NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask) 76 82 { … … 120 126 } 121 127 122 int NetIfCreateHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */) 123 { 124 return VERR_NOT_IMPLEMENTED; 125 } 126 127 int NetIfRemoveHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IN_GUID /* aId */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */) 128 { 129 return VERR_NOT_IMPLEMENTED; 128 129 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress) 130 { 131 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 132 /* create a progress object */ 133 ComObjPtr <Progress> progress; 134 progress.createObject(); 135 136 ComPtr<IHost> host; 137 HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam()); 138 if(SUCCEEDED(rc)) 139 { 140 rc = progress->init (pVBox, host, 141 Bstr ("Creating host only network interface"), 142 FALSE /* aCancelable */); 143 if(SUCCEEDED(rc)) 144 { 145 CheckComRCReturnRC (rc); 146 progress.queryInterfaceTo (aProgress); 147 148 char szAdpCtl[RTPATH_MAX]; 149 int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " add")); 150 if (RT_FAILURE(rc)) 151 { 152 progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), 153 "Failed to get program path, rc=%Vrc.\n", rc); 154 return rc; 155 } 156 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " add"); 157 FILE *fp = popen(szAdpCtl, "r"); 158 159 if (fp) 160 { 161 char szBuf[VBOXNET_MAX_SHORT_NAME]; 162 if (fgets(szBuf, sizeof(szBuf), fp)) 163 { 164 char *pLast = szBuf + strlen(szBuf) - 1; 165 if (pLast >= szBuf && *pLast == '\n') 166 *pLast = 0; 167 168 NETIFINFO Info; 169 Bstr IfName(szBuf); 170 rc = NetIfGetConfigByName(IfName, &Info); 171 if (RT_FAILURE(rc)) 172 { 173 progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), 174 "Failed to get config info for %s (as reported by '" VBOXNETADPCTL_NAME " add').\n", szBuf); 175 } 176 else 177 { 178 /* create a new uninitialized host interface object */ 179 ComObjPtr <HostNetworkInterface> iface; 180 iface.createObject(); 181 iface->init(IfName, HostNetworkInterfaceType_HostOnly, &Info); 182 iface.queryInterfaceTo (aHostNetworkInterface); 183 } 184 } 185 if ((rc = pclose(fp)) != 0) 186 { 187 progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), "Failed to execute '"VBOXNETADPCTL_NAME " add' (exit status: %d).", rc); 188 rc = VERR_INTERNAL_ERROR; 189 } 190 } 191 if (RT_SUCCESS(rc)) 192 progress->notifyComplete(rc); 193 } 194 } 195 196 return rc; 197 198 #else 199 return VERR_NOT_IMPLEMENTED; 200 #endif 201 } 202 203 int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress) 204 { 205 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 206 /* create a progress object */ 207 ComObjPtr <Progress> progress; 208 progress.createObject(); 209 ComPtr<IHost> host; 210 int rc = VINF_SUCCESS; 211 HRESULT hr = pVBox->COMGETTER(Host)(host.asOutParam()); 212 if(SUCCEEDED(hr)) 213 { 214 Bstr ifname; 215 ComPtr <IHostNetworkInterface> iface; 216 if (FAILED (host->FindHostNetworkInterfaceById (aId, iface.asOutParam()))) 217 return VERR_INVALID_PARAMETER; 218 iface->COMGETTER (Name) (ifname.asOutParam()); 219 if (ifname.isNull()) 220 return VERR_INTERNAL_ERROR; 221 222 rc = progress->init (pVBox, host, 223 Bstr ("Removing host network interface"), 224 FALSE /* aCancelable */); 225 if(SUCCEEDED(rc)) 226 { 227 CheckComRCReturnRC (rc); 228 progress.queryInterfaceTo (aProgress); 229 iface.queryInterfaceTo (aHostNetworkInterface); 230 rc = NetIfAdpCtl(Utf8Str(ifname), "remove", NULL, NULL); 231 if (RT_FAILURE(rc)) 232 progress->notifyComplete(E_FAIL, COM_IIDOF(IHostNetworkInterface), HostNetworkInterface::getComponentName(), "Failed to execute '"VBOXNETADPCTL_NAME "' (exit status: %d).", rc); 233 else 234 progress->notifyComplete(S_OK); 235 } 236 } 237 else 238 { 239 progress->notifyComplete(hr); 240 rc = VERR_INTERNAL_ERROR; 241 } 242 return rc; 243 #else 244 return VERR_NOT_IMPLEMENTED; 245 #endif 130 246 } 131 247
Note:
See TracChangeset
for help on using the changeset viewer.