- 時間撮記:
- 2011-12-8 上午05:55:10 (13 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp
r36217 r39557 39 39 #include <iprt/string.h> 40 40 #include <iprt/time.h> 41 #include <iprt/mem.h> 41 42 42 43 #include <VBox/sup.h> … … 52 53 #include "VBoxNetLib.h" 53 54 #include "VBoxNetBaseService.h" 54 #include "VBoxNetLib.h"55 #include "VBoxNetBaseService.h"56 55 57 56 #ifdef RT_OS_WINDOWS /* WinMain */ … … 64 63 * Structures and Typedefs * 65 64 *******************************************************************************/ 65 static RTGETOPTDEF g_aGetOptDef[] = 66 { 67 { "--name", 'N', RTGETOPT_REQ_STRING }, 68 { "--network", 'n', RTGETOPT_REQ_STRING }, 69 { "--trunk-name", 't', RTGETOPT_REQ_STRING }, 70 { "--trunk-type", 'T', RTGETOPT_REQ_STRING }, 71 { "--mac-address", 'a', RTGETOPT_REQ_MACADDR }, 72 { "--ip-address", 'i', RTGETOPT_REQ_IPV4ADDR }, 73 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 74 }; 66 75 VBoxNetBaseService::VBoxNetBaseService() 67 76 { 68 /* numbers from DrvIntNet */69 m_cbSendBuf = 36 * _1K;70 m_cbRecvBuf = 218 * _1K;71 m_hIf = INTNET_HANDLE_INVALID;72 m_pIfBuf = NULL;73 74 m_cVerbosity = 0;75 m_Name = "VBoxNetNAT";76 m_Network = "intnet";77 77 } 78 78 VBoxNetBaseService::~VBoxNetBaseService() … … 99 99 } 100 100 } 101 102 int VBoxNetBaseService::init() 103 { 104 /* numbers from DrvIntNet */ 105 m_cbSendBuf = 36 * _1K; 106 m_cbRecvBuf = 218 * _1K; 107 m_hIf = INTNET_HANDLE_INVALID; 108 m_pIfBuf = NULL; 109 110 m_cVerbosity = 0; 111 m_Name = "VBoxNetNAT"; 112 m_Network = "intnet"; 113 for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i) 114 m_vecOptionDefs.push_back(&g_aGetOptDef[i]); 115 return VINF_SUCCESS; 116 } 101 117 /** 102 118 * Parse the arguments. … … 109 125 int VBoxNetBaseService::parseArgs(int argc, char **argv) 110 126 { 111 static const RTGETOPTDEF s_aOptionDefs[] =112 {113 { "--name", 'N', RTGETOPT_REQ_STRING },114 { "--network", 'n', RTGETOPT_REQ_STRING },115 { "--trunk-name", 't', RTGETOPT_REQ_STRING },116 { "--trunk-type", 'T', RTGETOPT_REQ_STRING },117 { "--mac-address", 'a', RTGETOPT_REQ_MACADDR },118 { "--ip-address", 'i', RTGETOPT_REQ_IPV4ADDR },119 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },120 };121 127 122 128 RTGETOPTSTATE State; 123 int rc = RTGetOptInit(&State, argc, argv, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0 /*fFlags*/); 129 PRTGETOPTDEF paOptionArray = getOptionsPtr(); 130 int rc = RTGetOptInit(&State, argc, argv, paOptionArray, m_vecOptionDefs.size(), 0, 0 /*fFlags*/); 124 131 AssertRCReturn(rc, 49); 125 132 Log2(("BaseService: parseArgs enter\n")); … … 183 190 "Options:\n", 184 191 RTBldCfgVersion()); 185 for ( size_t i = 0; i < RT_ELEMENTS(s_aOptionDefs); i++)186 RTPrintf(" -%c, %s\n", s_aOptionDefs[i].iShort, s_aOptionDefs[i].pszLong);192 for (unsigned int i = 0; i < m_vecOptionDefs.size(); i++) 193 RTPrintf(" -%c, %s\n", m_vecOptionDefs[i]->iShort, m_vecOptionDefs[i]->pszLong); 187 194 usage(); /* to print Service Specific usage */ 188 195 return 1; 189 196 190 197 default: 191 rc = RTGetOptPrintError(rc, &Val); 192 RTPrintf("Use --help for more information.\n"); 193 return rc; 198 int rc1 = parseOpt(rc, Val); 199 if (RT_FAILURE(rc1)) 200 { 201 rc = RTGetOptPrintError(rc, &Val); 202 RTPrintf("Use --help for more information.\n"); 203 return rc; 204 } 194 205 } 195 206 } 196 207 208 RTMemFree(paOptionArray); 197 209 return rc; 198 210 } … … 343 355 } 344 356 357 PRTGETOPTDEF VBoxNetBaseService::getOptionsPtr() 358 { 359 PRTGETOPTDEF pOptArray = NULL; 360 pOptArray = (PRTGETOPTDEF)RTMemAlloc(sizeof(RTGETOPTDEF) * m_vecOptionDefs.size()); 361 if (!pOptArray) 362 return NULL; 363 for (unsigned int i = 0; i < m_vecOptionDefs.size(); ++i) 364 { 365 PRTGETOPTDEF pOpt = m_vecOptionDefs[i]; 366 memcpy(&pOptArray[i], m_vecOptionDefs[i], sizeof(RTGETOPTDEF)); 367 } 368 return pOptArray; 369 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器