Changeset 87798 in vbox for trunk/src/VBox/NetworkServices/NAT
- Timestamp:
- Feb 19, 2021 9:37:34 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87791 r87798 45 45 #include <iprt/param.h> 46 46 #include <iprt/pipe.h> 47 #include <iprt/getopt.h>48 47 #include <iprt/string.h> 49 48 #include <iprt/mem.h> … … 54 53 #include <iprt/cpp/utils.h> 55 54 #include <VBox/log.h> 55 56 #include <iprt/buildconfig.h> 57 #include <iprt/getopt.h> 58 #include <iprt/process.h> 56 59 57 60 #include <VBox/sup.h> … … 182 185 virtual ~VBoxNetLwipNAT(); 183 186 184 virtual void usage() { /** @todo should be implemented */ }; 185 virtual int parseOpt(int c, const RTGETOPTUNION &Value); 186 187 virtual bool isMainNeeded() const { return true; } 187 RTEXITCODE parseArgs(int argc, char *argv[]); 188 188 189 189 virtual int init(); … … 191 191 192 192 private: 193 virtual int parseOpt(int c, const RTGETOPTUNION &Value); 194 virtual void usage(); 195 196 virtual bool isMainNeeded() const { return true; } 197 193 198 int initCom(); 194 199 int initHome(); … … 236 241 INTNETSEG VBoxNetLwipNAT::aXmitSeg[64]; 237 242 238 /**239 * Additional command line options.240 *241 * Our parseOpt() will be called by the base class if any of these are242 * supplied.243 */244 RTGETOPTDEF VBoxNetLwipNAT::s_aGetOptDef[] =245 {246 /*247 * Currently there are no extra options and since arrays can't be248 * empty use a sentinel entry instead, so that the placeholder249 * code to process the options can be supplied nonetheless.250 */251 {} /* sentinel */252 };253 254 243 255 244 256 245 VBoxNetLwipNAT::VBoxNetLwipNAT() 257 : VBoxNetBaseService("VBoxNetNAT", " nat-network")246 : VBoxNetBaseService("VBoxNetNAT", "") 258 247 { 259 248 LogFlowFuncEnter(); … … 292 281 setMacAddress(mac); 293 282 294 /* tell the base class about our command line options */295 for (PCRTGETOPTDEF pcOpt = &s_aGetOptDef[0]; pcOpt->iShort != 0; ++pcOpt)296 addCommandLineOption(pcOpt);297 298 283 m_loOptDescriptor.lomap = NULL; 299 284 m_loOptDescriptor.num_lomap = 0; … … 325 310 326 311 /** 327 * Hook into the option processing.312 * Command line options. 328 313 * 329 * Called by VBoxNetBaseService::parseArgs() for options that are not 330 * recognized by the base class. See s_aGetOptDef[]. 314 * @note This class is currently in transition away from being 315 * inheritted from VBoxNetBaseService, so it no longer calls its 316 * getopt code and has its own parseArgs() instead. 317 */ 318 RTGETOPTDEF VBoxNetLwipNAT::s_aGetOptDef[] = 319 { 320 { "--network", 'n', RTGETOPT_REQ_STRING }, 321 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 322 }; 323 324 325 /** Icky hack to tell the caller it should exit with RTEXITCODE_SUCCESS */ 326 #define RTEXITCODE_DONE RTEXITCODE_32BIT_HACK 327 328 void 329 VBoxNetLwipNAT::usage() 330 { 331 RTPrintf("%s Version %sr%u\n" 332 "(C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n" 333 "All rights reserved.\n" 334 "\n" 335 "Usage: %s <options>\n" 336 "\n" 337 "Options:\n", 338 RTProcShortName(), RTBldCfgVersion(), RTBldCfgRevision(), 339 RTProcShortName()); 340 for (size_t i = 0; i < RT_ELEMENTS(s_aGetOptDef); ++i) 341 RTPrintf(" -%c, %s\n", s_aGetOptDef[i].iShort, s_aGetOptDef[i].pszLong); 342 } 343 344 345 RTEXITCODE 346 VBoxNetLwipNAT::parseArgs(int argc, char *argv[]) 347 { 348 unsigned int uVerbosity = 0; 349 int rc; 350 351 RTGETOPTSTATE State; 352 rc = RTGetOptInit(&State, argc, argv, 353 s_aGetOptDef, RT_ELEMENTS(s_aGetOptDef), 354 1, 0); 355 356 int ch; 357 RTGETOPTUNION Val; 358 while ((ch = RTGetOpt(&State, &Val)) != 0) 359 { 360 switch (ch) 361 { 362 case 'n': /* --network */ 363 if (!getNetworkName().empty()) 364 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "multiple --network options"); 365 setNetworkName(Val.psz); 366 break; 367 368 case 'v': /* --verbose */ 369 ++uVerbosity; 370 break; 371 372 373 /* 374 * Standard options recognized by RTGetOpt() 375 */ 376 377 case 'V': /* --version */ 378 RTPrintf("%sr%u\n", RTBldCfgVersion(), RTBldCfgRevision()); 379 return RTEXITCODE_DONE; 380 381 case 'h': /* --help */ 382 usage(); 383 return RTEXITCODE_DONE; 384 385 case VINF_GETOPT_NOT_OPTION: 386 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "unexpected non-option argument"); 387 388 default: 389 return RTGetOptPrintError(ch, &Val); 390 } 391 } 392 393 if (getNetworkName().empty()) 394 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "missing --network option"); 395 396 /* tell the base class while we're still joined at the hip */ 397 setVerbosityLevel((int32_t)uVerbosity); 398 399 return RTEXITCODE_SUCCESS; 400 } 401 402 403 /** 404 * @note This class is currently in transition away from being 405 * inheritted from VBoxNetBaseService, so it no longer calls its 406 * getopt code and has its own parseArgs() instead. 331 407 */ 332 408 int VBoxNetLwipNAT::parseOpt(int c, const RTGETOPTUNION &Value) … … 2117 2193 VBoxNetLwipNAT NAT; 2118 2194 2119 int rcExit = NAT.parseArgs(argc - 1, argv + 1);2195 int rcExit = NAT.parseArgs(argc, argv); 2120 2196 if (rcExit != RTEXITCODE_SUCCESS) 2121 return rcExit; /* messages are already printed */ 2197 { 2198 /* messages are already printed */ 2199 return rcExit == RTEXITCODE_DONE ? RTEXITCODE_SUCCESS : rcExit; 2200 } 2122 2201 2123 2202 rc = NAT.init();
Note:
See TracChangeset
for help on using the changeset viewer.