/* $Id: NetIf-generic.cpp 17997 2009-03-17 07:56:52Z vboxsync $ */ /** @file * VirtualBox Main - Generic NetIf implementation. */ /* * Copyright (C) 2009 Sun Microsystems, Inc. * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 USA or visit http://www.sun.com if you need * additional information or have any questions. */ #include #include #include #include #include #include #include "HostNetworkInterfaceImpl.h" #include "netif.h" #define VBOXNETADPCTL_NAME "VBoxNetAdpCtl" static int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const char *pszOption, const char *pszMask) { const char *args[] = { NULL, NULL, pszAddr, pszOption, pszMask, NULL }; char szAdpCtl[RTPATH_MAX]; int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME)); if (RT_FAILURE(rc)) { LogRel(("NetIfAdpCtl: failed to get program path, rc=%Vrc.\n", rc)); return rc; } strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME); args[0] = szAdpCtl; Bstr interfaceName; pIf->COMGETTER(Name)(interfaceName.asOutParam()); Utf8Str strName(interfaceName); args[1] = strName; if (!RTPathExists(szAdpCtl)) { LogRel(("NetIfAdpCtl: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n", szAdpCtl)); return VERR_FILE_NOT_FOUND; } RTPROCESS pid; rc = RTProcCreate(szAdpCtl, args, RTENV_DEFAULT, 0, &pid); if (RT_SUCCESS(rc)) { RTPROCSTATUS Status; rc = RTProcWait(pid, 0, &Status); if ( RT_SUCCESS(rc) && Status.iStatus == 0 && Status.enmReason == RTPROCEXITREASON_NORMAL) return VINF_SUCCESS; } else LogRel(("NetIfAdpCtl: failed to create process for %.\n", szAdpCtl)); return rc; } int NetIfEnableStaticIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * pIf, ULONG aOldIp, ULONG aNewIp, ULONG aMask) { const char *pszOption, *pszMask; char szAddress[16]; /* 4*3 + 3*1 + 1 */ char szNetMask[16]; /* 4*3 + 3*1 + 1 */ uint8_t *pu8Addr = (uint8_t *)&aNewIp; uint8_t *pu8Mask = (uint8_t *)&aMask; if (aNewIp == 0) { pu8Addr = (uint8_t *)&aOldIp; pszOption = "remove"; pszMask = NULL; } else { pszOption = "netmask"; pszMask = szNetMask; RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d", pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]); } RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d", pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]); return NetIfAdpCtl(pIf, szAddress, pszOption, pszMask); } int NetIfEnableStaticIpConfigV6(VirtualBox * /* vBox */, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength) { char szAddress[5*8 + 1 + 5 + 1]; if (Bstr(aIPV6Address).length()) { RTStrPrintf(szAddress, sizeof(szAddress), "%ls/%d", aIPV6Address, aIPV6MaskPrefixLength); return NetIfAdpCtl(pIf, szAddress, NULL, NULL); } else { RTStrPrintf(szAddress, sizeof(szAddress), "%ls", aOldIPV6Address); return NetIfAdpCtl(pIf, szAddress, "remove", NULL); } } int NetIfEnableDynamicIpConfig(VirtualBox * /* vBox */, HostNetworkInterface * /* pIf */) { return VERR_NOT_IMPLEMENTED; } int NetIfCreateHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */) { return VERR_NOT_IMPLEMENTED; } int NetIfRemoveHostOnlyNetworkInterface (VirtualBox * /* pVbox */, IN_GUID /* aId */, IHostNetworkInterface ** /* aHostNetworkInterface */, IProgress ** /* aProgress */) { return VERR_NOT_IMPLEMENTED; } int NetIfGetConfig(HostNetworkInterface * /* pIf */, NETIFINFO *) { return VERR_NOT_IMPLEMENTED; } int NetIfDhcpRediscover(VirtualBox * /* pVbox */, HostNetworkInterface * /* pIf */) { return VERR_NOT_IMPLEMENTED; }