[libvirt] [PATCH 3/3] networking API for hostonly networks in VirtualBox driver in libvirt

Daniel P. Berrange berrange at redhat.com
Mon May 11 13:43:28 UTC 2009


On Mon, May 11, 2009 at 02:19:06PM +0200, Pritesh Kothari wrote:
> >   You really don't need to keep any data about the networking driver
> > in libvirt(d) itself ?
> >
> +static int vboxListNetworks(virConnectPtr conn, char **const names, int nnames) {
> +    vboxGlobalData *data = conn->privateData;
> +    int numActive = 0;
> +
> +    if (data->vboxObj) {
> +        IHost *host = NULL;
> +
> +        data->vboxObj->vtbl->GetHost(data->vboxObj, &host);
> +        if (host) {
> +            int i = 0;
> +            PRUint32 networkInterfacesSize = 0;
> +            IHostNetworkInterface **networkInterfaces = NULL;
> +
> +            host->vtbl->GetNetworkInterfaces(host, &networkInterfacesSize, &networkInterfaces);
> +
> +            for (i = 0; (numActive < nnames) && (i < networkInterfacesSize); i++) {
> +                if (networkInterfaces[i]) {
> +                    PRUint32 interfaceType = 0;
> +
> +                    networkInterfaces[i]->vtbl->GetInterfaceType(networkInterfaces[i], &interfaceType);
> +
> +                    if (interfaceType == HostNetworkInterfaceType_HostOnly) {
> +                        PRUint32 status = HostNetworkInterfaceStatus_Unknown;
> +
> +                        networkInterfaces[i]->vtbl->GetStatus(networkInterfaces[i], &status);
> +
> +                        if (status == HostNetworkInterfaceStatus_Up) {
> +                            char *nameUtf8       = NULL;
> +                            PRUnichar *nameUtf16 = NULL;
> +
> +                            networkInterfaces[i]->vtbl->GetName(networkInterfaces[i], &nameUtf16);
> +                            data->pFuncs->pfnUtf16ToUtf8(nameUtf16, &nameUtf8);
> +
> +                            DEBUG("nnames[%d]: %s", numActive, nameUtf8);
> +                            names[numActive++] = strdup(nameUtf8);
> +
> +                            data->pFuncs->pfnUtf8Free(nameUtf8);
> +                            data->pFuncs->pfnUtf16Free(nameUtf16);
> +                        }
> +                    }
> +                }
> +            }
> +
> +            for (i = 0; i < networkInterfacesSize; i++) {
> +                if (networkInterfaces[i]) {
> +                    networkInterfaces[i]->vtbl->nsisupports.Release((nsISupports *) networkInterfaces[i]);
> +                }
> +            }
> +
> +            host->vtbl->nsisupports.Release((nsISupports *) host);
> +        }
> +    }
> +
> +    return numActive;
> +}


There's a strdup() call here that's not checked for failure, and quite a
few more in other functions in the patch.


This reminds me that we really need to make a wrapper for strdup, as we did
for malloc() to validate failure checking at compile time.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list