- Timestamp:
- Aug 29, 2008 11:39:12 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/darwin/iokit.cpp
r11856 r11857 1433 1433 1434 1434 /* 1435 * Get the current preferences and make a copy of the network services so we 1436 * can look up the right interface names. The IfsRef is just for fallback. 1437 */ 1438 CFArrayRef ServicesRef = NULL; 1439 CFIndex cServices = 0; 1440 SCPreferencesRef PrefsRef = SCPreferencesCreate(kCFAllocatorDefault, CFSTR("org.virtualbox.VBoxSVC"), NULL); 1441 if (PrefsRef) 1442 { 1443 SCNetworkSetRef SetRef = SCNetworkSetCopyCurrent(PrefsRef); 1444 CFRelease(PrefsRef); 1445 if (SetRef) 1446 { 1447 ServicesRef = SCNetworkSetCopyServices(SetRef); 1448 CFRelease(SetRef); 1449 cServices = ServicesRef ? CFArrayGetCount(ServicesRef) : 0; 1450 } 1451 } 1452 1453 /* 1435 1454 * Enumerate the ethernet controller services. 1436 1455 */ … … 1515 1534 *psz++ = ' '; 1516 1535 size_t cchLeft = sizeof(szTmp) - (psz - &szTmp[0]) - (sizeof(" (Wireless)") - 1); 1536 bool fFound = false; 1517 1537 CFIndex i; 1518 for (i = 0; i < cIfs; i++) 1538 1539 /* look it up among the current services */ 1540 for (CFIndex i = 0; i < cServices; i++) 1519 1541 { 1520 SCNetworkInterfaceRef IfRef = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(IfsRef, i); 1521 CFStringRef BSDNameRef = SCNetworkInterfaceGetBSDName(IfRef); 1522 if ( BSDNameRef 1523 && CFStringGetCString(BSDNameRef, psz, cchLeft, kCFStringEncodingUTF8) 1524 && !strcmp(psz, szBSDName)) 1542 SCNetworkServiceRef ServiceRef = (SCNetworkServiceRef)CFArrayGetValueAtIndex(ServicesRef, i); 1543 SCNetworkInterfaceRef IfRef = SCNetworkServiceGetInterface(ServiceRef); 1544 if (IfRef) 1525 1545 { 1526 CFStringRef DisplayNameRef = SCNetworkInterfaceGetLocalizedDisplayName(IfRef); 1527 if ( DisplayNameRef 1528 && CFStringGetCString(DisplayNameRef, psz, cchLeft, kCFStringEncodingUTF8)) 1529 break; 1546 CFStringRef BSDNameRef = SCNetworkInterfaceGetBSDName(IfRef); 1547 if ( BSDNameRef 1548 && CFStringGetCString(BSDNameRef, psz, cchLeft, kCFStringEncodingUTF8) 1549 && !strcmp(psz, szBSDName)) 1550 { 1551 CFStringRef ServiceNameRef = SCNetworkServiceGetName(ServiceRef); 1552 if ( ServiceNameRef 1553 && CFStringGetCString(ServiceNameRef, psz, cchLeft, kCFStringEncodingUTF8)) 1554 { 1555 fFound = true; 1556 break; 1557 } 1558 } 1530 1559 } 1531 1560 } 1561 /* Look it up in the interface list. */ 1562 if (!fFound) 1563 for (i = 0; i < cIfs; i++) 1564 { 1565 SCNetworkInterfaceRef IfRef = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(IfsRef, i); 1566 CFStringRef BSDNameRef = SCNetworkInterfaceGetBSDName(IfRef); 1567 if ( BSDNameRef 1568 && CFStringGetCString(BSDNameRef, psz, cchLeft, kCFStringEncodingUTF8) 1569 && !strcmp(psz, szBSDName)) 1570 { 1571 CFStringRef DisplayNameRef = SCNetworkInterfaceGetLocalizedDisplayName(IfRef); 1572 if ( DisplayNameRef 1573 && CFStringGetCString(DisplayNameRef, psz, cchLeft, kCFStringEncodingUTF8)) 1574 { 1575 fFound = true; 1576 break; 1577 } 1578 } 1579 } 1532 1580 /* Generate a half plausible name if we for some silly reason didn't find the interface. */ 1533 if ( i >= cIfs)1581 if (!fFound) 1534 1582 RTStrPrintf(szTmp, sizeof(szTmp), "%s: %s%s(?)", 1535 1583 szBSDName, … … 1538 1586 /* If we did find it and it's wireless but without "AirPort" or "Wireless", fix it */ 1539 1587 else if ( fWireless 1540 && !strstr( szTmp, "AirPort")1541 && !strstr( szTmp, "Wireless"))1542 strcat(szTmp, " (Wireless)");1588 && !strstr(psz, "AirPort") 1589 && !strstr(psz, "Wireless")) 1590 strcat(szTmp, fAirPort ? " (AirPort)" : " (Wireless)"); 1543 1591 1544 1592 /* … … 1624 1672 1625 1673 IOObjectRelease(EtherIfServices); 1626 CFRelease(IfsRef); 1674 if (ServicesRef) 1675 CFRelease(ServicesRef); 1676 if (IfsRef) 1677 CFRelease(IfsRef); 1627 1678 return pHead; 1628 1679 } … … 1685 1736 } 1686 1737 1738 CFRelease(ServicesRef); 1687 1739 CFRelease(SetRef); 1688 1740 }
Note:
See TracChangeset
for help on using the changeset viewer.