Changeset 25826 in vbox for trunk/src/apps/adpctl
- Timestamp:
- Jan 14, 2010 10:59:36 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp
r24854 r25826 56 56 #define VBOXADPCTL_IFCONFIG_PATH "/sbin/ifconfig" 57 57 58 #ifdef RT_OS_LINUX 59 #define VBOXADPCTL_DEL_CMD "del" 58 #if defined(RT_OS_LINUX) 59 # define VBOXADPCTL_DEL_CMD "del" 60 # define VBOXADPCTL_ADD_CMD "add" 61 #elif defined(RT_OS_SOLARIS) 62 # define VBOXADPCTL_DEL_CMD "removeif" 63 # define VBOXADPCTL_ADD_CMD "addif" 60 64 #else 61 #define VBOXADPCTL_DEL_CMD "delete" 65 # define VBOXADPCTL_DEL_CMD "delete" 66 # define VBOXADPCTL_ADD_CMD "add" 62 67 #endif 63 68 … … 224 229 { 225 230 char szAdapterName[VBOXNETADP_MAX_NAME_LEN]; 226 char *pszAdapterName ;227 const char *pszAddress ;231 char *pszAdapterName = NULL; 232 const char *pszAddress = NULL; 228 233 const char *pszNetworkMask = NULL; 229 234 const char *pszOption = NULL; … … 235 240 { 236 241 case 5: 242 { 243 /* Add a netmask to existing interface */ 237 244 if (strcmp("netmask", argv[3])) 238 245 { … … 246 253 pszAddress = argv[2]; 247 254 break; 255 } 256 248 257 case 4: 258 { 259 /* Remove a single address from existing interface */ 249 260 if (strcmp("remove", argv[3])) 250 261 { … … 257 268 pszAddress = argv[2]; 258 269 break; 270 } 271 259 272 case 3: 273 { 274 /* Remove an existing interface */ 260 275 pszAdapterName = argv[1]; 261 276 pszAddress = argv[2]; … … 265 280 if (rc) 266 281 return rc; 282 #ifdef RT_OS_SOLARIS 283 return 1; 284 #else 267 285 memset(&Req, '\0', sizeof(Req)); 268 286 snprintf(Req.szName, sizeof(Req.szName), "%s", szAdapterName); 269 287 return doIOCtl(VBOXNETADP_CTL_REMOVE, &Req); 288 #endif 270 289 } 271 290 break; 291 } 292 272 293 case 2: 294 { 295 /* Create a new interface */ 273 296 if (strcmp("add", argv[1]) == 0) 274 297 { 298 #ifdef RT_OS_SOLARIS 299 return 1; 300 #else 275 301 memset(&Req, '\0', sizeof(Req)); 276 302 rc = doIOCtl(VBOXNETADP_CTL_ADD, &Req); 277 303 if (rc == 0) 278 304 puts(Req.szName); 305 #endif 279 306 return rc; 280 307 } 281 308 /* Fall through */ 309 } 310 282 311 default: 283 312 fprintf(stderr, "Invalid number of arguments.\n\n"); … … 300 329 else 301 330 { 302 #if def RT_OS_LINUX331 #if defined(RT_OS_LINUX) 303 332 rc = executeIfconfig(pszAdapterName, "0.0.0.0"); 304 333 #else 305 rc = executeIfconfig(pszAdapterName, "delete", pszAddress); 334 rc = executeIfconfig(pszAdapterName, VBOXADPCTL_DEL_CMD, pszAddress); 335 #endif 336 337 #ifdef RT_OS_SOLARIS 338 /* On Solaris we can unplumb the ipv4 interface */ 339 executeIfconfig(pszAdapterName, "inet", "unplumb"); 306 340 #endif 307 341 } … … 312 346 if (strchr(pszAddress, ':')) 313 347 { 348 #ifdef RT_OS_SOLARIS 349 /* On Solaris we need to plumb the interface first if it's not already plumbed. */ 350 if (executeIfconfig(pszAdapterName, "inet6") != 0) 351 executeIfconfig(pszAdapterName, "inet6", "plumb", "up"); 352 #endif 314 353 /* 315 354 * Before we set IPv6 address we'd like to remove … … 320 359 rc = EXIT_FAILURE; 321 360 else 322 rc = executeIfconfig(pszAdapterName, "inet6", "add", pszAddress, pszOption, pszNetworkMask);361 rc = executeIfconfig(pszAdapterName, "inet6", VBOXADPCTL_ADD_CMD, pszAddress, pszOption, pszNetworkMask); 323 362 } 324 363 else 364 { 365 #ifdef RT_OS_SOLARIS 366 /* On Solaris we need to plumb the interface first if it's not already plumbed. */ 367 if (executeIfconfig(pszAdapterName, "inet") != 0) 368 executeIfconfig(pszAdapterName, "plumb", "up"); 369 #endif 325 370 rc = executeIfconfig(pszAdapterName, pszAddress, pszOption, pszNetworkMask); 371 } 326 372 } 327 373 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.