VirtualBox

Ignore:
Timestamp:
Mar 11, 2009 3:39:29 PM (16 years ago)
Author:
vboxsync
Message:

#3569: IPv4 static ip config for unix platforms + darwin NetIfList update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/generic/NetIf-generic.cpp

    r17679 r17703  
    2020 */
    2121
     22#include <VBox/err.h>
     23#include <VBox/log.h>
     24#include <iprt/process.h>
     25#include <iprt/env.h>
     26#include <iprt/path.h>
     27
    2228#include "HostNetworkInterfaceImpl.h"
    2329#include "netif.h"
    2430
     31#define VBOXNETADPCTL_NAME "VBoxNetAdpCtl"
     32
     33static int NetIfAdpCtl(HostNetworkInterface * pIf, char *pszAddr, char *pszMask)
     34{
     35    const char *args[] = { NULL, NULL, pszAddr, NULL, NULL, NULL };
     36    if (pszMask)
     37    {
     38        args[3] = "netmask";
     39        args[4] = pszMask;
     40    }
     41   
     42    char szAdpCtl[PATH_MAX];
     43    int rc = RTPathProgram(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME));
     44    if (RT_FAILURE(rc))
     45        return rc;
     46    strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME);
     47    args[0] = szAdpCtl;
     48    Bstr interfaceName;
     49    pIf->COMGETTER(Name)(interfaceName.asOutParam());
     50    Utf8Str strName(interfaceName);
     51    args[1] = strName;
     52    if (!RTPathExists(szAdpCtl))
     53    {
     54        LogRel(("NetIf: path %s does not exist. Failed to run " VBOXNETADPCTL_NAME " helper.\n",
     55                szAdpCtl));
     56        return VERR_FILE_NOT_FOUND;
     57    }
     58   
     59    RTPROCESS pid;
     60    rc = RTProcCreate(VBOXNETADPCTL_NAME, args, RTENV_DEFAULT, 0, &pid);
     61    if (RT_SUCCESS(rc))
     62    {
     63        RTPROCSTATUS Status;
     64        rc = RTProcWait(pid, 0, &Status);
     65        if (   RT_SUCCESS(rc)
     66            && Status.iStatus == 0
     67            && Status.enmReason == RTPROCEXITREASON_NORMAL)
     68            return VINF_SUCCESS;
     69    }
     70    return rc;
     71}
     72
    2573int NetIfEnableStaticIpConfig(HostNetworkInterface * pIf, ULONG ip, ULONG mask)
    2674{
    27     return VERR_NOT_IMPLEMENTED;
     75    char szAddress[16]; /* 4*3 + 3*1 + 1 */
     76    char szNetMask[16]; /* 4*3 + 3*1 + 1 */
     77    uint8_t *pu8Addr = (uint8_t *)&ip;
     78    uint8_t *pu8Mask = (uint8_t *)&mask;
     79    RTStrPrintf(szAddress, sizeof(szAddress), "%d.%d.%d.%d",
     80                pu8Addr[0], pu8Addr[1], pu8Addr[2], pu8Addr[3]);
     81    RTStrPrintf(szNetMask, sizeof(szNetMask), "%d.%d.%d.%d",
     82                pu8Mask[0], pu8Mask[1], pu8Mask[2], pu8Mask[3]);
     83    return NetIfAdpCtl(pIf, szAddress, szNetMask);
    2884}
    2985
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette