[vbox-dev] Patch to enable intnet and hifdev networking in VBoxBFE on Win32 V2
Jan Schunk
scpcom at web.de
Sun Jul 1 06:59:03 PDT 2007
Now I implemented automatic insertion of the GUID determined by device name.
Note:
VBoxBFE is a qemu like command-line/SDL Frontend. Its useful if you don't have a commercial license of QT win32 or MSVC++ compiler without ATL.
intnet is the command-line argument equal to selecting "Internal Network" in network settings of the full VirtualBox Frontend,
hifdev is the command-line argument equal to selecting "Host Interface" in network settings of the full VirtualBox Frontend.
------------------------------------------------------------
--- e:\SOFTWARE\opsystem\vbox-build\VirtualBox-OSE-1.4.0\src\VBox\Frontends\VBoxBFE\VBoxBFE.cpp Wed Jun 06 08:05:56 2007
+++ e:\SOFTWARE\opsystem\vbox-build\VirtualBox-OSE-trunk\src\VBox\Frontends\VBoxBFE\VBoxBFE.cpp Tue Jun 12 01:51:30 2007
@@ -203,12 +203,141 @@
bool fHaveFd; /**< Set if fd is valid. */
int32_t fd; /**< The file descriptor of a HIF device.*/
#endif
+#if defined(__WIN__)
+ char szGUID[39]; /**< The device GUID of a HIF device. */
+#endif
} BFENETDEV, *PBFENETDEV;
/** Array of network device configurations. */
static BFENETDEV g_aNetDevs[NetworkAdapterCount];
+#ifdef __WIN__
+
+static bool IsTAPDevice(const char *guid)
+{
+ HKEY hNetcard;
+ LONG status;
+ DWORD len;
+ int i = 0;
+ bool ret = false;
+
+ status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);
+ if (status != ERROR_SUCCESS)
+ return false;
+
+ while(true)
+ {
+ char szEnumName[256];
+ char szNetCfgInstanceId[256];
+ DWORD dwKeyType;
+ HKEY hNetCardGUID;
+
+ len = sizeof(szEnumName);
+ status = RegEnumKeyExA(hNetcard, i, szEnumName, &len, NULL, NULL, NULL, NULL);
+ if (status != ERROR_SUCCESS)
+ break;
+
+ status = RegOpenKeyExA(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
+ if (status == ERROR_SUCCESS)
+ {
+ len = sizeof (szNetCfgInstanceId);
+ status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
+ if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
+ {
+ char szNetProductName[256];
+ char szNetProviderName[256];
+
+ szNetProductName[0] = 0;
+ len = sizeof(szNetProductName);
+ status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
+
+ szNetProviderName[0] = 0;
+ len = sizeof(szNetProviderName);
+ status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
+
+ if ( !strcmp(szNetCfgInstanceId, guid)
+ && !strcmp(szNetProductName, "VirtualBox TAP Adapter")
+ && !strcmp(szNetProviderName, "innotek GmbH"))
+ {
+ ret = true;
+ RegCloseKey(hNetCardGUID);
+ break;
+ }
+ }
+ RegCloseKey(hNetCardGUID);
+ }
+ ++i;
+ }
+
+ RegCloseKey (hNetcard);
+ return ret;
+}
+
+/**
+ * Returns the GUID of host network interface.
+ */
+static bool GetTAPDeviceGUID(const char *name, char *guid, size_t maxguid)
+{
+
+ bool ret = false;
+ static const char *NetworkKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\"
+ "{4D36E972-E325-11CE-BFC1-08002BE10318}";
+ HKEY hCtrlNet;
+ LONG status;
+ DWORD len;
+ status = RegOpenKeyExA (HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
+ if (status != ERROR_SUCCESS)
+ {
+ RTPrintf("Error: Could not open registry key \"%s\"", NetworkKey);
+ return false;
+ }
+
+ for (int i = 0;; ++ i)
+ {
+ char szNetworkGUID [256];
+ HKEY hConnection;
+ char szNetworkConnection [256];
+
+ len = sizeof (szNetworkGUID);
+ status = RegEnumKeyExA (hCtrlNet, i, szNetworkGUID, &len, NULL, NULL, NULL, NULL);
+ if (status != ERROR_SUCCESS)
+ break;
+
+ if (!IsTAPDevice(szNetworkGUID))
+ continue;
+
+ RTStrPrintf (szNetworkConnection, sizeof (szNetworkConnection),
+ "%s\\Connection", szNetworkGUID);
+ status = RegOpenKeyExA (hCtrlNet, szNetworkConnection, 0, KEY_READ, &hConnection);
+ if (status == ERROR_SUCCESS)
+ {
+ DWORD dwKeyType;
+ status = RegQueryValueEx (hConnection, "Name", NULL,
+ &dwKeyType, NULL, &len);
+ if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
+ {
+ char szEnumName [256];
+ len = sizeof(szEnumName);
+ status = RegQueryValueEx (hConnection, "Name", NULL,
+ &dwKeyType, (LPBYTE) szEnumName, &len);
+ if (status == ERROR_SUCCESS && !strcmp(szEnumName, name))
+ {
+ strncpy(guid, szNetworkGUID, maxguid);
+ ret = true;
+ break;
+ }
+ }
+ RegCloseKey (hConnection);
+ }
+ }
+ RegCloseKey (hCtrlNet);
+
+ return ret;
+}
+#endif /* __WIN__ */
+
+
/** @todo currently this is only set but never read. */
static char szError[512];
@@ -1539,11 +1671,17 @@
#elif defined(__WIN__)
/*
- * We need the GUID too here...
+ * The HIF device GUID.
*/
+ if (!GetTAPDeviceGUID(g_aNetDevs[ulInstance].pszName, g_aNetDevs[ulInstance].szGUID, sizeof(g_aNetDevs[ulInstance].szGUID)))
+ {
+ FatalError("The TAP network device GUID is missing! (%s)\n", g_aNetDevs[ulInstance].pszName);
+ return -1;
+ }
+
rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
rc = CFGMR3InsertString(pCfg, "HostInterfaceName", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
- rc = CFGMR3InsertString(pCfg, "GUID", g_aNetDevs[ulInstance].pszName /*pszGUID*/); UPDATE_RC();
+ rc = CFGMR3InsertBytes(pCfg, "GUID", &g_aNetDevs[ulInstance].szGUID[0], strlen(g_aNetDevs[ulInstance].szGUID)+1); UPDATE_RC();
#else /* !__LINUX__ && !__L4__ */
@@ -1557,6 +1695,9 @@
/*
* Internal networking.
*/
+ rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); UPDATE_RC();
+ rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
+
rc = CFGMR3InsertString(pCfg, "Network", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
}
}
------------------------------------------------------------
License: GPLv2, based on parts of src/VBox/Main/HostImpl.cpp
_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066
More information about the vbox-dev
mailing list