Changeset 17319 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Mar 4, 2009 3:18:37 AM (16 years ago)
- File:
-
- 1 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:
Note:
See TracChangeset
for help on using the changeset viewer.