儲存庫 vbox 的更動 17319
圖例:
- 未更動
- 新增
- 刪除
-
trunk/include/iprt/getopt.h
r17141 r17319 70 70 /** The value must be a valid unsigned 64-bit integer or an error will be returned. */ 71 71 #define RTGETOPT_REQ_UINT64 9 72 /** The value must be a valid IPv4 address. 73 * (Not a name, but 4 values in the 0..255 range with dots separating them). */ 74 #define RTGETOPT_REQ_IPV4ADDR 10 72 75 /** The mask of the valid required types. */ 73 76 #define RTGETOPT_REQ_MASK 15 … … 117 120 * This can be NULL for some errors. */ 118 121 PCRTGETOPTDEF pDef; 119 /** A RTGETOPT_ ARG_FORMAT_STRING option argument. */122 /** A RTGETOPT_REQ_STRING option argument. */ 120 123 const char *psz; 121 124 … … 124 127 #endif 125 128 126 /** A RTGETOPT_ ARG_FORMAT_INT8 option argument. */129 /** A RTGETOPT_REQ_INT8 option argument. */ 127 130 int8_t i8; 128 /** A RTGETOPT_ ARG_FORMAT_UINT8 option argument . */131 /** A RTGETOPT_REQ_UINT8 option argument . */ 129 132 uint8_t u8; 130 /** A RTGETOPT_ ARG_FORMAT_INT16 option argument. */133 /** A RTGETOPT_REQ_INT16 option argument. */ 131 134 int16_t i16; 132 /** A RTGETOPT_ ARG_FORMAT_UINT16 option argument . */135 /** A RTGETOPT_REQ_UINT16 option argument . */ 133 136 uint16_t u16; 134 /** A RTGETOPT_ ARG_FORMAT_INT16 option argument. */137 /** A RTGETOPT_REQ_INT16 option argument. */ 135 138 int32_t i32; 136 /** A RTGETOPT_ ARG_FORMAT_UINT32 option argument . */139 /** A RTGETOPT_REQ_UINT32 option argument . */ 137 140 uint32_t u32; 138 /** A RTGETOPT_ ARG_FORMAT_INT64 option argument. */141 /** A RTGETOPT_REQ_INT64 option argument. */ 139 142 int64_t i64; 140 /** A RTGETOPT_ ARG_FORMAT_UINT64 option argument. */143 /** A RTGETOPT_REQ_UINT64 option argument. */ 141 144 uint64_t u64; 145 #ifdef ___iprt_net_h 146 /** A RTGETOPT_REQ_IPV4ADDR option argument. */ 147 RTNETADDRIPV4 IPv4Addr; 148 #endif 142 149 /** A signed integer value. */ 143 150 int64_t i; -
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);
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器