VirtualBox

Changeset 8287 in vbox


Ignore:
Timestamp:
Apr 22, 2008 1:24:22 PM (17 years ago)
Author:
vboxsync
Message:

NAT: make the network configurable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r8285 r8287  
    3232#include <iprt/string.h>
    3333#include <iprt/critsect.h>
     34#include <iprt/ip.h>
    3435
    3536#include "Builtins.h"
     
    386387    PDRVNAT pData = PDMINS2DATA(pDrvIns, PDRVNAT);
    387388    char szNetAddr[16];
     389    char szNetwork[32]; /* xxx.xxx.xxx.xxx/yy */
    388390    LogFlow(("drvNATConstruct:\n"));
    389391
     
    391393     * Validate the config.
    392394     */
    393     if (!CFGMR3AreValuesValid(pCfgHandle, "PassDomain\0TFTPPrefix\0BootFile\0"))
     395    if (!CFGMR3AreValuesValid(pCfgHandle, "PassDomain\0TFTPPrefix\0BootFile\0Network\0"))
    394396        return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, N_("Unknown NAT configuration option, only supports PassDomain, TFTPPrefix and BootFile"));
    395397
     
    438440
    439441    /* Generate a network address for this network card. */
    440     RTStrPrintf(szNetAddr, sizeof(szNetAddr), "10.0.%d.0", pDrvIns->iInstance + 2);
     442    rc = CFGMR3QueryString(pCfgHandle, "Network", szNetwork, sizeof(szNetwork));
     443    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     444        RTStrPrintf(szNetwork, sizeof(szNetwork), "10.0.%d.0/24", pDrvIns->iInstance + 2);
     445    else if (VBOX_FAILURE(rc))
     446        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Network\" string failed"), pDrvIns->iInstance);
     447
     448    RTIPV4ADDR Network;
     449    RTIPV4ADDR Netmask;
     450    rc = RTCidrStrToIPv4(szNetwork, &Network, &Netmask);
     451    if (RT_FAILURE(rc))
     452        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: Configuration error: network '%s' describes not a valid IPv4 network"));
     453
     454    RTStrPrintf(szNetAddr, sizeof(szNetAddr), "%d.%d.%d.%d",
     455               (Network & 0xFF000000) >> 24, (Network & 0xFF0000) >> 16, (Network & 0xFF00) >> 8, Network & 0xFF);
    441456
    442457    /*
     
    461476             * Initialize slirp.
    462477             */
    463             rc = slirp_init(&pData->pNATState, &szNetAddr[0], 0xffffff00, fPassDomain, pData->pszTFTPPrefix, pData->pszBootFile, pData);
     478            rc = slirp_init(&pData->pNATState, &szNetAddr[0], Netmask, fPassDomain, pData->pszTFTPPrefix, pData->pszBootFile, pData);
    464479            if (VBOX_SUCCESS(rc))
    465480            {
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