mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-08 14:29:56 +00:00
vbox: Rewrite vboxConnectListDefinedNetworks
This commit is contained in:
parent
638afcf5c9
commit
85a3cd993a
@ -242,3 +242,60 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
|
|||||||
VIR_DEBUG("numActive: %d", ret);
|
VIR_DEBUG("numActive: %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames)
|
||||||
|
{
|
||||||
|
vboxGlobalData *data = conn->privateData;
|
||||||
|
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
||||||
|
IHost *host = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!data->vboxObj)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UIVirtualBox.GetHost(data->vboxObj, &host);
|
||||||
|
if (!host)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host,
|
||||||
|
gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host));
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) {
|
||||||
|
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
||||||
|
PRUint32 interfaceType = 0;
|
||||||
|
char *nameUtf8 = NULL;
|
||||||
|
PRUnichar *nameUtf16 = NULL;
|
||||||
|
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
||||||
|
|
||||||
|
if (!networkInterface)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
|
||||||
|
|
||||||
|
if (interfaceType != HostNetworkInterfaceType_HostOnly)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status);
|
||||||
|
|
||||||
|
if (status != HostNetworkInterfaceStatus_Down)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16);
|
||||||
|
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
|
||||||
|
|
||||||
|
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
|
||||||
|
if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
|
||||||
|
ret++;
|
||||||
|
|
||||||
|
VBOX_UTF8_FREE(nameUtf8);
|
||||||
|
VBOX_UTF16_FREE(nameUtf16);
|
||||||
|
}
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces);
|
||||||
|
|
||||||
|
VBOX_RELEASE(host);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -2060,51 +2060,6 @@ _registerDomainEvent(virDriverPtr driver)
|
|||||||
* The Network Functions here on
|
* The Network Functions here on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
|
|
||||||
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
|
||||||
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces);
|
|
||||||
|
|
||||||
for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) {
|
|
||||||
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
|
||||||
|
|
||||||
if (networkInterface) {
|
|
||||||
PRUint32 interfaceType = 0;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
|
|
||||||
|
|
||||||
if (interfaceType == HostNetworkInterfaceType_HostOnly) {
|
|
||||||
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetStatus(networkInterface, &status);
|
|
||||||
|
|
||||||
if (status == HostNetworkInterfaceStatus_Down) {
|
|
||||||
char *nameUtf8 = NULL;
|
|
||||||
PRUnichar *nameUtf16 = NULL;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetName(networkInterface, &nameUtf16);
|
|
||||||
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
|
|
||||||
|
|
||||||
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
|
|
||||||
if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
|
|
||||||
ret++;
|
|
||||||
|
|
||||||
VBOX_UTF8_FREE(nameUtf8);
|
|
||||||
VBOX_UTF16_FREE(nameUtf16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vboxArrayRelease(&networkInterfaces);
|
|
||||||
|
|
||||||
VBOX_RELEASE(host);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static virNetworkPtr
|
static virNetworkPtr
|
||||||
vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
||||||
{
|
{
|
||||||
|
@ -551,6 +551,7 @@ int vboxNetworkClose(virConnectPtr conn);
|
|||||||
int vboxConnectNumOfNetworks(virConnectPtr conn);
|
int vboxConnectNumOfNetworks(virConnectPtr conn);
|
||||||
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
|
int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
|
||||||
int vboxConnectNumOfDefinedNetworks(virConnectPtr conn);
|
int vboxConnectNumOfDefinedNetworks(virConnectPtr conn);
|
||||||
|
int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
Reference in New Issue
Block a user