Changeset 17319 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Mar 4, 2009 3:18:37 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 43691
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r17143 r17319 32 32 * Header Files * 33 33 *******************************************************************************/ 34 #include <iprt/net.h> 34 35 #include <iprt/getopt.h> 35 36 #include <iprt/err.h> … … 64 65 /** @todo Add an flag for sorting the arguments so that all the options comes 65 66 * first. */ 67 return VINF_SUCCESS; 68 } 69 70 71 /** 72 * Converts an stringified IPv4 address into the RTNETADDRIPV4 representation. 73 * 74 * This should be move to some generic part of the runtime. 75 * 76 * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on 77 * failure. 78 * 79 * @param pszValue The value to convert. 80 * @param pAddr Where to store the result. 81 */ 82 static int rtgetoptConvertIPv4Addr(const char *pszValue, PRTNETADDRIPV4 pAddr) 83 { 84 char *pszNext; 85 int rc = RTStrToUInt8Ex(RTStrStripL(pszValue), &pszNext, 10, &pAddr->au8[0]); 86 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS) 87 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 88 if (*pszNext++ != '.') 89 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 90 91 rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[1]); 92 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS) 93 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 94 if (*pszNext++ != '.') 95 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 96 97 rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[2]); 98 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS) 99 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 100 if (*pszNext++ != '.') 101 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 102 103 rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[3]); 104 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES) 105 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 106 pszNext = RTStrStripL(pszNext); 107 if (*pszNext) 108 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 109 66 110 return VINF_SUCCESS; 67 111 } … … 315 359 MY_BASE_INT_CASE(RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT, uint32_t, u, RTStrToUInt32Full, 8) 316 360 MY_BASE_INT_CASE(RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_OCT, uint64_t, u, RTStrToUInt64Full, 8) 361 317 362 #undef MY_INT_CASE 318 363 #undef MY_BASE_INT_CASE 364 365 case RTGETOPT_REQ_IPV4ADDR: 366 { 367 RTNETADDRIPV4 Addr; 368 if (rtgetoptConvertIPv4Addr(pszValue, &Addr) != VINF_SUCCESS) 369 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 370 pValueUnion->IPv4Addr = Addr; 371 break; 372 } 319 373 320 374 default: -
trunk/src/VBox/Runtime/testcase/tstGetOpt.cpp
r17141 r17319 30 30 31 31 32 /******************************************************************************* 33 * Header Files * 34 *******************************************************************************/ 35 #include <iprt/net.h> 32 36 #include <iprt/getopt.h> 33 37 #include <iprt/stream.h> … … 83 87 { "nodash", 387, RTGETOPT_REQ_NOTHING }, 84 88 { "nodashval", 388, RTGETOPT_REQ_STRING }, 89 { "--gateway", 'g', RTGETOPT_REQ_IPV4ADDR }, 85 90 }; 86 91 … … 118 123 119 124 "-vqi999", 125 126 "-g192.168.1.1", 120 127 NULL 121 128 }; … … 191 198 CHECK(Val.i32 == 999); 192 199 200 /* IPv4 */ 201 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'g', 1); 202 CHECK(Val.IPv4Addr.u == RT_H2N_U32_C(RT_BSWAP_U32_C(RT_MAKE_U32_FROM_U8(192,168,1,1)))); 203 193 204 /* the end */ 194 205 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.