diff options
author | Felix Geyer <fgeyer@debian.org> | 2013-01-25 18:09:04 +0100 |
---|---|---|
committer | Felix Geyer <fgeyer@debian.org> | 2013-01-25 18:09:04 +0100 |
commit | 490244144bf10ecd165f2f81f2c88b7781c91d85 (patch) | |
tree | 7bc392b380dda58cfee860a4db82fc1b133ac663 /src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp | |
parent | b0bc77b9da451781ff6b93f0e1b470f2bd41537c (diff) | |
download | virtualbox-490244144bf10ecd165f2f81f2c88b7781c91d85.tar.gz |
Imported Upstream version 4.2.6-dfsgupstream/4.2.6-dfsg
Diffstat (limited to 'src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp')
-rw-r--r-- | src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp | 87 |
1 files changed, 53 insertions, 34 deletions
diff --git a/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp b/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp index 926a296e9..435a1cb8a 100644 --- a/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp +++ b/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp @@ -5,7 +5,7 @@ /** @todo r=bird: Cut&Past rules... Please fix DHCP refs! */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -16,12 +16,6 @@ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. */ -/** @page pg_net_dhcp VBoxNetDHCP - * - * Write a few words... - * - */ - /******************************************************************************* * Header Files * *******************************************************************************/ @@ -38,6 +32,7 @@ #include <iprt/stream.h> #include <iprt/string.h> #include <iprt/time.h> +#include <iprt/mem.h> #include <VBox/sup.h> #include <VBox/intnet.h> @@ -51,8 +46,6 @@ #include "VBoxNetLib.h" #include "VBoxNetBaseService.h" -#include "VBoxNetLib.h" -#include "VBoxNetBaseService.h" #ifdef RT_OS_WINDOWS /* WinMain */ # include <Windows.h> @@ -63,17 +56,18 @@ /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ +static RTGETOPTDEF g_aGetOptDef[] = +{ + { "--name", 'N', RTGETOPT_REQ_STRING }, + { "--network", 'n', RTGETOPT_REQ_STRING }, + { "--trunk-name", 't', RTGETOPT_REQ_STRING }, + { "--trunk-type", 'T', RTGETOPT_REQ_STRING }, + { "--mac-address", 'a', RTGETOPT_REQ_MACADDR }, + { "--ip-address", 'i', RTGETOPT_REQ_IPV4ADDR }, + { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, +}; VBoxNetBaseService::VBoxNetBaseService() { - /* numbers from DrvIntNet */ - m_cbSendBuf = 36 * _1K; - m_cbRecvBuf = 218 * _1K; - m_hIf = INTNET_HANDLE_INVALID; - m_pIfBuf = NULL; - - m_cVerbosity = 0; - m_Name = "VBoxNetNAT"; - m_Network = "intnet"; } VBoxNetBaseService::~VBoxNetBaseService() { @@ -98,6 +92,22 @@ VBoxNetBaseService::~VBoxNetBaseService() m_pSession = NIL_RTR0PTR; } } + +int VBoxNetBaseService::init() +{ + /* numbers from DrvIntNet */ + m_cbSendBuf = 36 * _1K; + m_cbRecvBuf = 218 * _1K; + m_hIf = INTNET_HANDLE_INVALID; + m_pIfBuf = NULL; + + m_cVerbosity = 0; + m_Name = "VBoxNetNAT"; + m_Network = "intnet"; + for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i) + m_vecOptionDefs.push_back(&g_aGetOptDef[i]); + return VINF_SUCCESS; +} /** * Parse the arguments. * @@ -108,19 +118,10 @@ VBoxNetBaseService::~VBoxNetBaseService() */ int VBoxNetBaseService::parseArgs(int argc, char **argv) { - static const RTGETOPTDEF s_aOptionDefs[] = - { - { "--name", 'N', RTGETOPT_REQ_STRING }, - { "--network", 'n', RTGETOPT_REQ_STRING }, - { "--trunk-name", 't', RTGETOPT_REQ_STRING }, - { "--trunk-type", 'T', RTGETOPT_REQ_STRING }, - { "--mac-address", 'a', RTGETOPT_REQ_MACADDR }, - { "--ip-address", 'i', RTGETOPT_REQ_IPV4ADDR }, - { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, - }; RTGETOPTSTATE State; - int rc = RTGetOptInit(&State, argc, argv, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0 /*fFlags*/); + PRTGETOPTDEF paOptionArray = getOptionsPtr(); + int rc = RTGetOptInit(&State, argc, argv, paOptionArray, m_vecOptionDefs.size(), 0, 0 /*fFlags*/); AssertRCReturn(rc, 49); Log2(("BaseService: parseArgs enter\n")); @@ -182,18 +183,23 @@ int VBoxNetBaseService::parseArgs(int argc, char **argv) "\n" "Options:\n", RTBldCfgVersion()); - for (size_t i = 0; i < RT_ELEMENTS(s_aOptionDefs); i++) - RTPrintf(" -%c, %s\n", s_aOptionDefs[i].iShort, s_aOptionDefs[i].pszLong); + for (unsigned int i = 0; i < m_vecOptionDefs.size(); i++) + RTPrintf(" -%c, %s\n", m_vecOptionDefs[i]->iShort, m_vecOptionDefs[i]->pszLong); usage(); /* to print Service Specific usage */ return 1; default: - rc = RTGetOptPrintError(rc, &Val); - RTPrintf("Use --help for more information.\n"); - return rc; + int rc1 = parseOpt(rc, Val); + if (RT_FAILURE(rc1)) + { + rc = RTGetOptPrintError(rc, &Val); + RTPrintf("Use --help for more information.\n"); + return rc; + } } } + RTMemFree(paOptionArray); return rc; } @@ -342,3 +348,16 @@ void VBoxNetBaseService::debugPrintV(int iMinLevel, bool fMsg, const char *pszFm } +PRTGETOPTDEF VBoxNetBaseService::getOptionsPtr() +{ + PRTGETOPTDEF pOptArray = NULL; + pOptArray = (PRTGETOPTDEF)RTMemAlloc(sizeof(RTGETOPTDEF) * m_vecOptionDefs.size()); + if (!pOptArray) + return NULL; + for (unsigned int i = 0; i < m_vecOptionDefs.size(); ++i) + { + PRTGETOPTDEF pOpt = m_vecOptionDefs[i]; + memcpy(&pOptArray[i], m_vecOptionDefs[i], sizeof(RTGETOPTDEF)); + } + return pOptArray; +} |