- Timestamp:
- Jul 5, 2013 9:31:09 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/solaris/NetIf-solaris.cpp
r44742 r46994 25 25 #include <iprt/err.h> 26 26 #include <iprt/ctype.h> 27 #include <iprt/mem.h> 27 28 #include <iprt/path.h> 28 29 #include <list> … … 199 200 */ 200 201 NETIFINFO Info; 201 memset(&Info, 0, sizeof(Info));202 RT_ZERO(Info); 202 203 int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 203 204 if (Sock > 0) … … 413 414 { 414 415 struct lifnum IfNum; 415 memset(&IfNum, 0, sizeof(IfNum));416 RT_ZERO(IfNum); 416 417 IfNum.lifn_family = AF_INET; 417 418 int rc = ioctl(Sock, SIOCGLIFNUM, &IfNum); 418 419 if (!rc) 419 420 { 420 struct lifreq Ifaces[24]; 421 struct lifconf IfConfig; 422 memset(&IfConfig, 0, sizeof(IfConfig)); 423 IfConfig.lifc_family = AF_INET; 424 IfConfig.lifc_len = sizeof(Ifaces); 425 IfConfig.lifc_buf = (caddr_t)&(Ifaces[0]); 426 rc = ioctl(Sock, SIOCGLIFCONF, &IfConfig); 427 if (!rc) 421 int cbIfaces = IfNum.lifn_count * sizeof(struct lifreq); 422 struct lifreq *Ifaces = (struct lifreq *Ifaces)RTMemTmpAlloc(cbIfaces); 423 if (Ifaces) 428 424 { 429 for (int i = 0; i < IfNum.lifn_count; i++) 425 struct lifconf IfConfig; 426 RT_ZERO(IfConfig); 427 IfConfig.lifc_family = AF_INET; 428 IfConfig.lifc_len = cbIfaces; 429 IfConfig.lifc_buf = (caddr_t)Ifaces; 430 rc = ioctl(Sock, SIOCGLIFCONF, &IfConfig); 431 if (!rc) 430 432 { 431 /* 432 * Skip loopback interfaces. 433 */ 434 if (!strncmp(Ifaces[i].lifr_name, "lo", 2)) 435 continue; 433 for (int i = 0; i < IfNum.lifn_count; i++) 434 { 435 /* 436 * Skip loopback interfaces. 437 */ 438 if (!strncmp(Ifaces[i].lifr_name, "lo", 2)) 439 continue; 436 440 437 441 #if 0 438 rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i])); 439 if (rc >= 0) 440 { 441 memcpy(Info.IPAddress.au8, ((struct sockaddr *)&Ifaces[i].lifr_addr)->sa_data, 442 sizeof(Info.IPAddress.au8)); 443 // SIOCGLIFNETMASK 444 struct arpreq ArpReq; 445 memcpy(&ArpReq.arp_pa, &Ifaces[i].lifr_addr, sizeof(struct sockaddr_in)); 446 447 /* 448 * We might fail if the interface has not been assigned an IP address. 449 * That doesn't matter; as long as it's plumbed we can pick it up. 450 * But, if it has not acquired an IP address we cannot obtain it's MAC 451 * address this way, so we just use all zeros there. 452 */ 453 rc = ioctl(Sock, SIOCGARP, &ArpReq); 442 rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i])); 454 443 if (rc >= 0) 455 memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress)); 456 457 char szNICDesc[LIFNAMSIZ + 256]; 444 { 445 memcpy(Info.IPAddress.au8, ((struct sockaddr *)&Ifaces[i].lifr_addr)->sa_data, 446 sizeof(Info.IPAddress.au8)); 447 // SIOCGLIFNETMASK 448 struct arpreq ArpReq; 449 memcpy(&ArpReq.arp_pa, &Ifaces[i].lifr_addr, sizeof(struct sockaddr_in)); 450 451 /* 452 * We might fail if the interface has not been assigned an IP address. 453 * That doesn't matter; as long as it's plumbed we can pick it up. 454 * But, if it has not acquired an IP address we cannot obtain it's MAC 455 * address this way, so we just use all zeros there. 456 */ 457 rc = ioctl(Sock, SIOCGARP, &ArpReq); 458 if (rc >= 0) 459 memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress)); 460 461 char szNICDesc[LIFNAMSIZ + 256]; 462 char *pszIface = Ifaces[i].lifr_name; 463 strcpy(szNICDesc, pszIface); 464 465 vboxSolarisAddLinkHostIface(pszIface, &list); 466 } 467 #endif 468 458 469 char *pszIface = Ifaces[i].lifr_name; 459 strcpy(szNICDesc, pszIface);460 461 470 vboxSolarisAddLinkHostIface(pszIface, &list); 462 471 } 463 #endif464 465 char *pszIface = Ifaces[i].lifr_name;466 vboxSolarisAddLinkHostIface(pszIface, &list);467 472 } 473 RTMemTempFree(Ifaces); 468 474 } 469 475 }
Note:
See TracChangeset
for help on using the changeset viewer.