Changeset 17441 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Mar 6, 2009 7:05:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r17319 r17441 72 72 * Converts an stringified IPv4 address into the RTNETADDRIPV4 representation. 73 73 * 74 * This should be move to some generic part of the runtime.74 * @todo This should be move to some generic part of the runtime. 75 75 * 76 76 * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on … … 102 102 103 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 110 return VINF_SUCCESS; 111 } 112 113 114 /** 115 * Converts an stringified Ethernet MAC address into the RTMAC representation. 116 * 117 * @todo This should be move to some generic part of the runtime. 118 * 119 * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on 120 * failure. 121 * 122 * @param pszValue The value to convert. 123 * @param pAddr Where to store the result. 124 */ 125 static int rtgetoptConvertMacAddr(const char *pszValue, PRTMAC pAddr) 126 { 127 /* 128 * Not quite sure if I should accept stuff like "08::27:::1" here... 129 * The code is accepting "::" patterns now, except for for the first 130 * and last parts. 131 */ 132 133 /* first */ 134 char *pszNext; 135 int rc = RTStrToUInt8Ex(RTStrStripL(pszValue), &pszNext, 16, &pAddr->au8[0]); 136 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS) 137 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 138 if (*pszNext++ != ':') 139 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 140 141 /* middle */ 142 for (unsigned i = 1; i < 5; i++) 143 { 144 if (*pszNext == ':') 145 pAddr->au8[i] = 0; 146 else 147 { 148 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &pAddr->au8[i]); 149 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS) 150 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 151 if (*pszNext != ':') 152 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 153 } 154 pszNext++; 155 } 156 157 /* last */ 158 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &pAddr->au8[5]); 104 159 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES) 105 160 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; … … 371 426 break; 372 427 } 428 #if 0 /** @todo CIDR */ 429 #endif 430 431 case RTGETOPT_REQ_MACADDR: 432 { 433 RTMAC Addr; 434 if (rtgetoptConvertMacAddr(pszValue, &Addr) != VINF_SUCCESS) 435 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; 436 pValueUnion->MacAddr = Addr; 437 break; 438 } 373 439 374 440 default:
Note:
See TracChangeset
for help on using the changeset viewer.