Changeset 17441 in vbox
- Timestamp:
- Mar 6, 2009 7:05:58 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/getopt.h
r17319 r17441 73 73 * (Not a name, but 4 values in the 0..255 range with dots separating them). */ 74 74 #define RTGETOPT_REQ_IPV4ADDR 10 75 #if 0 76 /** The value must be a valid IPv4 CIDR. 77 * As with RTGETOPT_REQ_IPV4ADDR, no name. 78 * @todo Mix CIDR with types.h or/and net.h first and find a way to make the 79 * mask optional like with ifconfig. See RTCidrStrToIPv4. */ 80 #define RTGETOPT_REQ_IPV4CIDR 11 81 #endif 82 /** The value must be a valid ethernet MAC address. */ 83 #define RTGETOPT_REQ_MACADDR 14 75 84 /** The mask of the valid required types. */ 76 85 #define RTGETOPT_REQ_MASK 15 … … 147 156 RTNETADDRIPV4 IPv4Addr; 148 157 #endif 158 /** A RTGETOPT_REQ_MACADDR option argument. */ 159 RTMAC MacAddr; 149 160 /** A signed integer value. */ 150 161 int64_t i; -
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: -
trunk/src/VBox/Runtime/testcase/tstGetOpt.cpp
r17319 r17441 88 88 { "nodashval", 388, RTGETOPT_REQ_STRING }, 89 89 { "--gateway", 'g', RTGETOPT_REQ_IPV4ADDR }, 90 { "--mac", 'm', RTGETOPT_REQ_MACADDR }, 90 91 }; 91 92 … … 125 126 126 127 "-g192.168.1.1", 128 129 "-m08:0:27:00:ab:f3", 130 "--mac:1:::::c", 131 127 132 NULL 128 133 }; … … 202 207 CHECK(Val.IPv4Addr.u == RT_H2N_U32_C(RT_BSWAP_U32_C(RT_MAKE_U32_FROM_U8(192,168,1,1)))); 203 208 209 /* Ethernet MAC address. */ 210 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'm', 1); 211 CHECK( Val.MacAddr.au8[0] == 0x08 212 && Val.MacAddr.au8[1] == 0x00 213 && Val.MacAddr.au8[2] == 0x27 214 && Val.MacAddr.au8[3] == 0x00 215 && Val.MacAddr.au8[4] == 0xab 216 && Val.MacAddr.au8[5] == 0xf3); 217 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'm', 1); 218 CHECK( Val.MacAddr.au8[0] == 0x01 219 && Val.MacAddr.au8[1] == 0x00 220 && Val.MacAddr.au8[2] == 0x00 221 && Val.MacAddr.au8[3] == 0x00 222 && Val.MacAddr.au8[4] == 0x00 223 && Val.MacAddr.au8[5] == 0x0c); 224 204 225 /* the end */ 205 226 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.