Changeset 17508 in vbox
- Timestamp:
- Mar 6, 2009 11:53:31 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 43941
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/win/NetIfList-win.cpp
r17502 r17508 146 146 } 147 147 148 static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, GUID * pGuid, IWbemClassObject **pAdapterConfig)148 static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const Guid &guid, IWbemClassObject **pAdapterConfig) 149 149 { 150 150 HRESULT hres; 151 151 WCHAR aQueryString[256]; 152 char uuidStr[RTUUID_STR_LENGTH]; 153 int rc = RTUuidToStr((PCRTUUID)pGuid, uuidStr, sizeof(uuidStr)); 154 if(RT_SUCCESS(rc)) 155 { 156 swprintf(aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"{%S}\"", uuidStr); 152 // char uuidStr[RTUUID_STR_LENGTH]; 153 // int rc = RTUuidToStr(guid.toString().raw(), uuidStr, sizeof(uuidStr)); 154 { 155 swprintf(aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"{%S}\"", guid.toString().raw()); 157 156 // Step 6: -------------------------------------------------- 158 157 // Use the IWbemServices pointer to make requests of WMI ---- … … 200 199 Log(("Query for operating system name failed. Error code = 0x%x\n", hres)); 201 200 } 202 }203 else204 {205 hres = -1;206 201 } 207 202 … … 664 659 //} 665 660 666 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask)661 static int netIfEnableStaticIpConfig(const Guid &guid, ULONG ip, ULONG mask) 667 662 { 668 663 HRESULT hr; 669 GUID guid;670 hr = pIf->COMGETTER(Id) (&guid);671 if(SUCCEEDED(hr))672 {673 664 ComPtr <IWbemServices> pSvc; 674 665 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); … … 676 667 { 677 668 ComPtr <IWbemClassObject> pAdapterConfig; 678 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam());669 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam()); 679 670 if(SUCCEEDED(hr)) 680 671 { … … 705 696 } 706 697 } 707 }708 698 709 699 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 710 700 } 711 701 712 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)702 static int netIfEnableStaticIpConfigV6(const Guid & guid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway) 713 703 { 714 704 HRESULT hr; 715 GUID guid;716 hr = pIf->COMGETTER(Id) (&guid);717 if(SUCCEEDED(hr))718 {719 705 ComPtr <IWbemServices> pSvc; 720 706 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); … … 722 708 { 723 709 ComPtr <IWbemClassObject> pAdapterConfig; 724 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam());710 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam()); 725 711 if(SUCCEEDED(hr)) 726 712 { … … 745 731 } 746 732 } 747 }748 733 749 734 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 750 735 } 751 736 752 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)737 static int netIfEnableStaticIpConfigV6(const Guid &guid, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength) 753 738 { 754 739 RTNETADDRIPV6 Mask; … … 757 742 { 758 743 Bstr maskStr = composeIPv6Address(&Mask); 759 rc = NetIfEnableStaticIpConfigV6(pIf, aIPV6Address, maskStr, NULL);744 rc = netIfEnableStaticIpConfigV6(guid, aIPV6Address, maskStr, NULL); 760 745 } 761 746 return rc; 762 747 } 763 748 764 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf)749 static HRESULT netIfEnableDynamicIpConfig(const Guid &guid) 765 750 { 766 751 HRESULT hr; 767 GUID guid;768 hr = pIf->COMGETTER(Id) (&guid);769 if(SUCCEEDED(hr))770 {771 752 ComPtr <IWbemServices> pSvc; 772 753 hr = netIfWinCreateIWbemServices(pSvc.asOutParam()); … … 774 755 { 775 756 ComPtr <IWbemClassObject> pAdapterConfig; 776 hr = netIfWinFindAdapterClassById(pSvc, &guid, pAdapterConfig.asOutParam());757 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam()); 777 758 if(SUCCEEDED(hr)) 778 759 { … … 790 771 } 791 772 } 792 } 793 794 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;773 774 775 return hr; 795 776 } 796 777 … … 976 957 vrc = aClient->write (d->msgCode); 977 958 if (RT_FAILURE (vrc)) break; 978 vrc = aClient->write ( Utf8Str (d->name));959 vrc = aClient->write (d->guid); 979 960 if (RT_FAILURE (vrc)) break; 980 961 … … 1029 1010 vrc = aClient->write (d->msgCode); 1030 1011 if (RT_FAILURE (vrc)) break; 1031 vrc = aClient->write ( Utf8Str (d->name));1012 vrc = aClient->write (d->guid); 1032 1013 if (RT_FAILURE (vrc)) break; 1033 1014 vrc = aClient->write (d->u.StaticIP.IPAddress); … … 1086 1067 vrc = aClient->write (d->msgCode); 1087 1068 if (RT_FAILURE (vrc)) break; 1088 vrc = aClient->write ( Utf8Str (d->name));1069 vrc = aClient->write (d->guid); 1089 1070 if (RT_FAILURE (vrc)) break; 1090 1071 vrc = aClient->write (Utf8Str(d->u.StaticIPV6.IPV6Address)); … … 1845 1826 break; 1846 1827 } 1828 case SVCHlpMsg::EnableStaticIpConfigV6: 1829 { 1830 LogFlowFunc (("EnableStaticIpConfigV6:\n")); 1831 1832 Guid guid; 1833 Utf8Str ipV6; 1834 ULONG maskLengthV6; 1835 vrc = aClient->read (guid); 1836 if (RT_FAILURE (vrc)) break; 1837 vrc = aClient->read (ipV6); 1838 if (RT_FAILURE (vrc)) break; 1839 vrc = aClient->read (maskLengthV6); 1840 if (RT_FAILURE (vrc)) break; 1841 1842 Utf8Str errMsg; 1843 vrc = netIfEnableStaticIpConfigV6 (guid, Bstr(ipV6), maskLengthV6); 1844 1845 if (RT_SUCCESS (vrc)) 1846 { 1847 /* write success followed by GUID */ 1848 vrc = aClient->write (SVCHlpMsg::OK); 1849 if (RT_FAILURE (vrc)) break; 1850 } 1851 else 1852 { 1853 /* write failure followed by error message */ 1854 if (errMsg.isEmpty()) 1855 errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc); 1856 vrc = aClient->write (SVCHlpMsg::Error); 1857 if (RT_FAILURE (vrc)) break; 1858 vrc = aClient->write (errMsg); 1859 if (RT_FAILURE (vrc)) break; 1860 } 1861 1862 break; 1863 } 1864 case SVCHlpMsg::EnableStaticIpConfig: 1865 { 1866 LogFlowFunc (("EnableStaticIpConfig:\n")); 1867 1868 Guid guid; 1869 ULONG ip, mask; 1870 vrc = aClient->read (guid); 1871 if (RT_FAILURE (vrc)) break; 1872 vrc = aClient->read (ip); 1873 if (RT_FAILURE (vrc)) break; 1874 vrc = aClient->read (mask); 1875 if (RT_FAILURE (vrc)) break; 1876 1877 Utf8Str errMsg; 1878 vrc = netIfEnableStaticIpConfig (guid, ip, mask); 1879 1880 if (RT_SUCCESS (vrc)) 1881 { 1882 /* write success followed by GUID */ 1883 vrc = aClient->write (SVCHlpMsg::OK); 1884 if (RT_FAILURE (vrc)) break; 1885 } 1886 else 1887 { 1888 /* write failure followed by error message */ 1889 if (errMsg.isEmpty()) 1890 errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc); 1891 vrc = aClient->write (SVCHlpMsg::Error); 1892 if (RT_FAILURE (vrc)) break; 1893 vrc = aClient->write (errMsg); 1894 if (RT_FAILURE (vrc)) break; 1895 } 1896 1897 break; 1898 } 1899 case SVCHlpMsg::EnableDynamicIpConfig: 1900 { 1901 LogFlowFunc (("EnableDynamicIpConfig:\n")); 1902 1903 Guid guid; 1904 vrc = aClient->read (guid); 1905 if (RT_FAILURE (vrc)) break; 1906 1907 Utf8Str errMsg; 1908 vrc = netIfEnableDynamicIpConfig (guid); 1909 1910 if (RT_SUCCESS (vrc)) 1911 { 1912 /* write success followed by GUID */ 1913 vrc = aClient->write (SVCHlpMsg::OK); 1914 if (RT_FAILURE (vrc)) break; 1915 } 1916 else 1917 { 1918 /* write failure followed by error message */ 1919 if (errMsg.isEmpty()) 1920 errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc); 1921 vrc = aClient->write (SVCHlpMsg::Error); 1922 if (RT_FAILURE (vrc)) break; 1923 vrc = aClient->write (errMsg); 1924 if (RT_FAILURE (vrc)) break; 1925 } 1926 1927 break; 1928 } 1847 1929 default: 1848 1930 AssertMsgFailedBreakStmt ( … … 1907 1989 /* end */ 1908 1990 1909 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IN_BSTR aName,1910 IHostNetworkInterface **aHostNetworkInterface,1911 IProgress **aProgress)1912 {1913 /* create a progress object */1914 ComObjPtr <Progress> progress;1915 progress.createObject();1916 1917 ComPtr<IHost> host;1918 HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());1919 if(SUCCEEDED(rc))1920 {1921 rc = progress->init (pVBox, host,1922 Bstr (_T ("Creating host only network interface")),1923 FALSE /* aCancelable */);1924 if(SUCCEEDED(rc))1925 {1926 CheckComRCReturnRC (rc);1927 progress.queryInterfaceTo (aProgress);1928 1929 /* create a new uninitialized host interface object */1930 ComObjPtr <HostNetworkInterface> iface;1931 iface.createObject();1932 iface.queryInterfaceTo (aHostNetworkInterface);1933 1934 /* create the networkInterfaceHelperClient() argument */1935 std::auto_ptr <NetworkInterfaceHelperClientData>1936 d (new NetworkInterfaceHelperClientData());1937 AssertReturn (d.get(), E_OUTOFMEMORY);1938 1939 d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface;1940 d->name = aName;1941 d->iface = iface;1942 1943 rc = pVBox->startSVCHelperClient (1944 IsUACEnabled() == TRUE /* aPrivileged */,1945 netIfNetworkInterfaceHelperClient,1946 static_cast <void *> (d.get()),1947 progress);1948 1949 if (SUCCEEDED (rc))1950 {1951 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */1952 d.release();1953 }1954 }1955 }1956 1957 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;1958 }1959 1960 int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId,1961 IHostNetworkInterface **aHostNetworkInterface,1962 IProgress **aProgress)1963 {1964 /* create a progress object */1965 ComObjPtr <Progress> progress;1966 progress.createObject();1967 ComPtr<IHost> host;1968 HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam());1969 if(SUCCEEDED(rc))1970 {1971 rc = progress->init (pVBox, host,1972 Bstr (_T ("Removing host network interface")),1973 FALSE /* aCancelable */);1974 if(SUCCEEDED(rc))1975 {1976 CheckComRCReturnRC (rc);1977 progress.queryInterfaceTo (aProgress);1978 1979 /* create the networkInterfaceHelperClient() argument */1980 std::auto_ptr <NetworkInterfaceHelperClientData>1981 d (new NetworkInterfaceHelperClientData());1982 AssertReturn (d.get(), E_OUTOFMEMORY);1983 1984 d->msgCode = SVCHlpMsg::RemoveHostOnlyNetworkInterface;1985 d->guid = aId;1986 1987 rc = pVBox->startSVCHelperClient (1988 IsUACEnabled() == TRUE /* aPrivileged */,1989 netIfNetworkInterfaceHelperClient,1990 static_cast <void *> (d.get()),1991 progress);1992 1993 if (SUCCEEDED (rc))1994 {1995 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */1996 d.release();1997 }1998 }1999 }2000 2001 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;2002 }2003 2004 1991 # define VBOX_APP_NAME L"VirtualBox" 2005 1992 … … 2052 2039 } 2053 2040 2054 #else /* #ifndef VBOX_WITH_NETFLT */2055 /**2056 * Windows helper function for NetIfList().2057 *2058 * @returns true / false.2059 *2060 * @param guid The GUID.2061 */2062 static bool IsTAPDevice(const char *guid)2063 {2064 HKEY hNetcard;2065 LONG status;2066 DWORD len;2067 int i = 0;2068 bool ret = false;2069 2070 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);2071 if (status != ERROR_SUCCESS)2072 return false;2073 2074 for (;;)2075 {2076 char szEnumName[256];2077 char szNetCfgInstanceId[256];2078 DWORD dwKeyType;2079 HKEY hNetCardGUID;2080 2081 len = sizeof(szEnumName);2082 status = RegEnumKeyExA(hNetcard, i, szEnumName, &len, NULL, NULL, NULL, NULL);2083 if (status != ERROR_SUCCESS)2084 break;2085 2086 status = RegOpenKeyExA(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);2087 if (status == ERROR_SUCCESS)2088 {2089 len = sizeof(szNetCfgInstanceId);2090 status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);2091 if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)2092 {2093 char szNetProductName[256];2094 char szNetProviderName[256];2095 2096 szNetProductName[0] = 0;2097 len = sizeof(szNetProductName);2098 status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);2099 2100 szNetProviderName[0] = 0;2101 len = sizeof(szNetProviderName);2102 status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);2103 2104 if ( !strcmp(szNetCfgInstanceId, guid)2105 && !strcmp(szNetProductName, "VirtualBox TAP Adapter")2106 && ( (!strcmp(szNetProviderName, "innotek GmbH"))2107 || (!strcmp(szNetProviderName, "Sun Microsystems, Inc."))))2108 {2109 ret = true;2110 RegCloseKey(hNetCardGUID);2111 break;2112 }2113 }2114 RegCloseKey(hNetCardGUID);2115 }2116 ++i;2117 }2118 2119 RegCloseKey(hNetcard);2120 return ret;2121 }2122 2041 #endif /* #ifndef VBOX_WITH_NETFLT */ 2123 2042 2124 int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *) 2125 { 2126 return VERR_NOT_IMPLEMENTED; 2127 } 2128 2129 static int NetIfListHostAdapters(std::list <ComObjPtr <HostNetworkInterface> > &list) 2043 2044 static int netIfListHostAdapters(std::list <ComObjPtr <HostNetworkInterface> > &list) 2130 2045 { 2131 2046 #ifndef VBOX_WITH_NETFLT … … 2195 2110 } 2196 2111 2112 int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *) 2113 { 2114 #ifndef VBOX_WITH_NETFLT 2115 return VERR_NOT_IMPLEMENTED; 2116 #else 2117 return VERR_NOT_IMPLEMENTED; 2118 #endif 2119 } 2120 2121 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IN_BSTR aName, 2122 IHostNetworkInterface **aHostNetworkInterface, 2123 IProgress **aProgress) 2124 { 2125 /* create a progress object */ 2126 ComObjPtr <Progress> progress; 2127 progress.createObject(); 2128 2129 ComPtr<IHost> host; 2130 HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam()); 2131 if(SUCCEEDED(rc)) 2132 { 2133 rc = progress->init (pVBox, host, 2134 Bstr (_T ("Creating host only network interface")), 2135 FALSE /* aCancelable */); 2136 if(SUCCEEDED(rc)) 2137 { 2138 CheckComRCReturnRC (rc); 2139 progress.queryInterfaceTo (aProgress); 2140 2141 /* create a new uninitialized host interface object */ 2142 ComObjPtr <HostNetworkInterface> iface; 2143 iface.createObject(); 2144 iface.queryInterfaceTo (aHostNetworkInterface); 2145 2146 /* create the networkInterfaceHelperClient() argument */ 2147 std::auto_ptr <NetworkInterfaceHelperClientData> 2148 d (new NetworkInterfaceHelperClientData()); 2149 AssertReturn (d.get(), E_OUTOFMEMORY); 2150 2151 d->msgCode = SVCHlpMsg::CreateHostOnlyNetworkInterface; 2152 d->name = aName; 2153 d->iface = iface; 2154 2155 rc = pVBox->startSVCHelperClient ( 2156 IsUACEnabled() == TRUE /* aPrivileged */, 2157 netIfNetworkInterfaceHelperClient, 2158 static_cast <void *> (d.get()), 2159 progress); 2160 2161 if (SUCCEEDED (rc)) 2162 { 2163 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */ 2164 d.release(); 2165 } 2166 } 2167 } 2168 2169 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 2170 } 2171 2172 int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVBox, IN_GUID aId, 2173 IHostNetworkInterface **aHostNetworkInterface, 2174 IProgress **aProgress) 2175 { 2176 /* create a progress object */ 2177 ComObjPtr <Progress> progress; 2178 progress.createObject(); 2179 ComPtr<IHost> host; 2180 HRESULT rc = pVBox->COMGETTER(Host)(host.asOutParam()); 2181 if(SUCCEEDED(rc)) 2182 { 2183 rc = progress->init (pVBox, host, 2184 Bstr (_T ("Removing host network interface")), 2185 FALSE /* aCancelable */); 2186 if(SUCCEEDED(rc)) 2187 { 2188 CheckComRCReturnRC (rc); 2189 progress.queryInterfaceTo (aProgress); 2190 2191 /* create the networkInterfaceHelperClient() argument */ 2192 std::auto_ptr <NetworkInterfaceHelperClientData> 2193 d (new NetworkInterfaceHelperClientData()); 2194 AssertReturn (d.get(), E_OUTOFMEMORY); 2195 2196 d->msgCode = SVCHlpMsg::RemoveHostOnlyNetworkInterface; 2197 d->guid = aId; 2198 2199 rc = pVBox->startSVCHelperClient ( 2200 IsUACEnabled() == TRUE /* aPrivileged */, 2201 netIfNetworkInterfaceHelperClient, 2202 static_cast <void *> (d.get()), 2203 progress); 2204 2205 if (SUCCEEDED (rc)) 2206 { 2207 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */ 2208 d.release(); 2209 } 2210 } 2211 } 2212 2213 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 2214 } 2215 2216 int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask) 2217 { 2218 HRESULT rc; 2219 GUID guid; 2220 rc = pIf->COMGETTER(Id) (&guid); 2221 if(SUCCEEDED(rc)) 2222 { 2223 ComPtr<VirtualBox> vBox; 2224 rc = pIf->getVirtualBox (vBox.asOutParam()); 2225 if(SUCCEEDED(rc)) 2226 { 2227 /* create a progress object */ 2228 ComObjPtr <Progress> progress; 2229 progress.createObject(); 2230 ComPtr<IHost> host; 2231 HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam()); 2232 if(SUCCEEDED(rc)) 2233 { 2234 rc = progress->init (vBox, host, 2235 Bstr ("Enabling Dynamic Ip Configuration"), 2236 FALSE /* aCancelable */); 2237 if(SUCCEEDED(rc)) 2238 { 2239 CheckComRCReturnRC (rc); 2240 // progress.queryInterfaceTo (aProgress); 2241 2242 /* create the networkInterfaceHelperClient() argument */ 2243 std::auto_ptr <NetworkInterfaceHelperClientData> 2244 d (new NetworkInterfaceHelperClientData()); 2245 AssertReturn (d.get(), E_OUTOFMEMORY); 2246 2247 d->msgCode = SVCHlpMsg::EnableStaticIpConfig; 2248 d->guid = guid; 2249 d->iface = pIf; 2250 d->u.StaticIP.IPAddress = ip; 2251 d->u.StaticIP.IPNetMask = mask; 2252 2253 rc = vBox->startSVCHelperClient ( 2254 IsUACEnabled() == TRUE /* aPrivileged */, 2255 netIfNetworkInterfaceHelperClient, 2256 static_cast <void *> (d.get()), 2257 progress); 2258 2259 if (SUCCEEDED (rc)) 2260 { 2261 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */ 2262 d.release(); 2263 } 2264 } 2265 } 2266 } 2267 } 2268 2269 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 2270 } 2271 2272 int NetIfEnableStaticIpConfigV6(HostNetworkInterface * pIf, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength) 2273 { 2274 HRESULT rc; 2275 GUID guid; 2276 rc = pIf->COMGETTER(Id) (&guid); 2277 if(SUCCEEDED(rc)) 2278 { 2279 ComPtr<VirtualBox> vBox; 2280 rc = pIf->getVirtualBox (vBox.asOutParam()); 2281 if(SUCCEEDED(rc)) 2282 { 2283 /* create a progress object */ 2284 ComObjPtr <Progress> progress; 2285 progress.createObject(); 2286 ComPtr<IHost> host; 2287 HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam()); 2288 if(SUCCEEDED(rc)) 2289 { 2290 rc = progress->init (vBox, host, 2291 Bstr ("Enabling Dynamic Ip Configuration"), 2292 FALSE /* aCancelable */); 2293 if(SUCCEEDED(rc)) 2294 { 2295 CheckComRCReturnRC (rc); 2296 // progress.queryInterfaceTo (aProgress); 2297 2298 /* create the networkInterfaceHelperClient() argument */ 2299 std::auto_ptr <NetworkInterfaceHelperClientData> 2300 d (new NetworkInterfaceHelperClientData()); 2301 AssertReturn (d.get(), E_OUTOFMEMORY); 2302 2303 d->msgCode = SVCHlpMsg::EnableStaticIpConfigV6; 2304 d->guid = guid; 2305 d->iface = pIf; 2306 d->u.StaticIPV6.IPV6Address = aIPV6Address; 2307 d->u.StaticIPV6.IPV6NetMaskLength = aIPV6MaskPrefixLength; 2308 2309 rc = vBox->startSVCHelperClient ( 2310 IsUACEnabled() == TRUE /* aPrivileged */, 2311 netIfNetworkInterfaceHelperClient, 2312 static_cast <void *> (d.get()), 2313 progress); 2314 2315 if (SUCCEEDED (rc)) 2316 { 2317 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */ 2318 d.release(); 2319 } 2320 } 2321 } 2322 } 2323 } 2324 2325 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 2326 } 2327 2328 int NetIfEnableDynamicIpConfig(HostNetworkInterface * pIf) 2329 { 2330 HRESULT rc; 2331 GUID guid; 2332 rc = pIf->COMGETTER(Id) (&guid); 2333 if(SUCCEEDED(rc)) 2334 { 2335 ComPtr<VirtualBox> vBox; 2336 rc = pIf->getVirtualBox (vBox.asOutParam()); 2337 if(SUCCEEDED(rc)) 2338 { 2339 /* create a progress object */ 2340 ComObjPtr <Progress> progress; 2341 progress.createObject(); 2342 ComPtr<IHost> host; 2343 HRESULT rc = vBox->COMGETTER(Host)(host.asOutParam()); 2344 if(SUCCEEDED(rc)) 2345 { 2346 rc = progress->init (vBox, host, 2347 Bstr ("Enabling Dynamic Ip Configuration"), 2348 FALSE /* aCancelable */); 2349 if(SUCCEEDED(rc)) 2350 { 2351 CheckComRCReturnRC (rc); 2352 // progress.queryInterfaceTo (aProgress); 2353 2354 /* create the networkInterfaceHelperClient() argument */ 2355 std::auto_ptr <NetworkInterfaceHelperClientData> 2356 d (new NetworkInterfaceHelperClientData()); 2357 AssertReturn (d.get(), E_OUTOFMEMORY); 2358 2359 d->msgCode = SVCHlpMsg::EnableDynamicIpConfig; 2360 d->guid = guid; 2361 d->iface = pIf; 2362 2363 rc = vBox->startSVCHelperClient ( 2364 IsUACEnabled() == TRUE /* aPrivileged */, 2365 netIfNetworkInterfaceHelperClient, 2366 static_cast <void *> (d.get()), 2367 progress); 2368 2369 if (SUCCEEDED (rc)) 2370 { 2371 /* d is now owned by netIfNetworkInterfaceHelperClient(), so release it */ 2372 d.release(); 2373 } 2374 } 2375 } 2376 } 2377 } 2378 2379 return SUCCEEDED(rc) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; 2380 } 2381 2197 2382 int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list) 2198 2383 { 2199 2384 #ifndef VBOX_WITH_NETFLT 2200 static const char *NetworkKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\" 2201 "{4D36E972-E325-11CE-BFC1-08002BE10318}"; 2202 HKEY hCtrlNet; 2203 LONG status; 2204 DWORD len; 2205 status = RegOpenKeyExA (HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet); 2206 if (status != ERROR_SUCCESS) 2207 { 2208 Log(("NetIfList: Could not open registry key \"%s\"", NetworkKey)); 2209 return E_FAIL; 2210 } 2211 2212 for (int i = 0;; ++ i) 2213 { 2214 char szNetworkGUID [256]; 2215 HKEY hConnection; 2216 char szNetworkConnection [256]; 2217 2218 len = sizeof (szNetworkGUID); 2219 status = RegEnumKeyExA (hCtrlNet, i, szNetworkGUID, &len, NULL, NULL, NULL, NULL); 2220 if (status != ERROR_SUCCESS) 2221 break; 2222 2223 if (!IsTAPDevice(szNetworkGUID)) 2224 continue; 2225 2226 RTStrPrintf (szNetworkConnection, sizeof (szNetworkConnection), 2227 "%s\\Connection", szNetworkGUID); 2228 status = RegOpenKeyExA (hCtrlNet, szNetworkConnection, 0, KEY_READ, &hConnection); 2229 if (status == ERROR_SUCCESS) 2230 { 2231 DWORD dwKeyType; 2232 status = RegQueryValueExW (hConnection, TEXT("Name"), NULL, 2233 &dwKeyType, NULL, &len); 2234 if (status == ERROR_SUCCESS && dwKeyType == REG_SZ) 2235 { 2236 size_t uniLen = (len + sizeof (OLECHAR) - 1) / sizeof (OLECHAR); 2237 Bstr name (uniLen + 1 /* extra zero */); 2238 status = RegQueryValueExW (hConnection, TEXT("Name"), NULL, 2239 &dwKeyType, (LPBYTE) name.mutableRaw(), &len); 2240 if (status == ERROR_SUCCESS) 2241 { 2242 LogFunc(("Connection name %ls\n", name.mutableRaw())); 2243 /* put a trailing zero, just in case (see MSDN) */ 2244 name.mutableRaw() [uniLen] = 0; 2245 /* create a new object and add it to the list */ 2246 ComObjPtr <HostNetworkInterface> iface; 2247 iface.createObject(); 2248 /* remove the curly bracket at the end */ 2249 szNetworkGUID [strlen(szNetworkGUID) - 1] = '\0'; 2250 2251 NETIFINFO Info; 2252 memset(&Info, 0, sizeof(Info)); 2253 Info.Uuid = *(Guid(szNetworkGUID + 1).raw()); 2254 int rc = collectNetIfInfo(name, &Info); 2255 if (RT_FAILURE(rc)) 2256 { 2257 Log(("vboxNetWinAddComponent: collectNetIfInfo() -> %Vrc\n", rc)); 2258 } 2259 2260 if (SUCCEEDED (iface->init (name, HostNetworkInterfaceType_Bridged, &Info))) 2261 list.push_back (iface); 2262 } 2263 } 2264 RegCloseKey (hConnection); 2265 } 2266 } 2267 RegCloseKey (hCtrlNet); 2385 return VERR_NOT_IMPLEMENTED; 2268 2386 #else /* # if defined VBOX_WITH_NETFLT */ 2269 2387 INetCfg *pNc; … … 2362 2480 } 2363 2481 2364 NetIfListHostAdapters(list); 2482 netIfListHostAdapters(list); 2483 2484 return VINF_SUCCESS; 2365 2485 #endif /* # if defined VBOX_WITH_NETFLT */ 2366 return VINF_SUCCESS; 2367 } 2486 }
Note:
See TracChangeset
for help on using the changeset viewer.