static CFSetRef /* of SCNetworkInterfaceRef's */ copyExcludedInterfaces(SCPreferencesRef prefs) { CFMutableSetRef excluded; CFArrayRef interfaces; excluded = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); #if !TARGET_OS_IPHONE // exclude Bond [member] interfaces interfaces = SCBondInterfaceCopyAll(prefs); if (interfaces != NULL) { __SCBondInterfaceListCollectMembers(interfaces, excluded); CFRelease(interfaces); } #endif // !TARGET_OS_IPHONE // exclude Bridge [member] interfaces interfaces = SCBridgeInterfaceCopyAll(prefs); if (interfaces != NULL) { __SCBridgeInterfaceListCollectMembers(interfaces, excluded); CFRelease(interfaces); } return excluded; }
CFArrayRef SCVLANInterfaceCopyAvailablePhysicalInterfaces() { CFMutableArrayRef available; CFArrayRef bond_interfaces = NULL; CFArrayRef bridge_interfaces = NULL; CFMutableSetRef excluded = NULL; CFArrayRef interfaces; SCPreferencesRef prefs; available = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); prefs = SCPreferencesCreate(NULL, CFSTR("SCVLANInterfaceCopyAvailablePhysicalInterfaces"), NULL); if (prefs != NULL) { #if !TARGET_OS_IPHONE bond_interfaces = SCBondInterfaceCopyAll(prefs); if (bond_interfaces != NULL) { excluded = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); __SCBondInterfaceListCollectMembers(bond_interfaces, excluded); } #endif // !TARGET_OS_IPHONE bridge_interfaces = SCBridgeInterfaceCopyAll(prefs); if (bridge_interfaces != NULL) { if (excluded == NULL) { excluded = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); } __SCBridgeInterfaceListCollectMembers(bridge_interfaces, excluded); } CFRelease(prefs); } // add real interfaces that aren't part of a bond or bridge interfaces = __SCNetworkInterfaceCopyAll_IONetworkInterface(); if (interfaces != NULL) { addAvailableInterfaces(available, interfaces, excluded); CFRelease(interfaces); } // add bond interfaces if (bond_interfaces != NULL) { addAvailableInterfaces(available, bond_interfaces, NULL); CFRelease(bond_interfaces); } // add bridge interfaces if (bridge_interfaces != NULL) { addAvailableInterfaces(available, bridge_interfaces, NULL); CFRelease(bridge_interfaces); } if (excluded != NULL) { CFRelease(excluded); } return available; }
static SCBridgeInterfaceRef copyAutoBridgeInterface(SCPreferencesRef prefs, CFStringRef bridgeName) { SCBridgeInterfaceRef bridge = NULL; CFArrayRef interfaces; // exclude Bridge [member] interfaces interfaces = SCBridgeInterfaceCopyAll(prefs); if (interfaces != NULL) { CFIndex i; CFIndex n; n = CFArrayGetCount(interfaces); for (i = 0; i < n; i++) { SCBridgeInterfaceRef interface; CFStringRef name = NULL; CFDictionaryRef options; interface = CFArrayGetValueAtIndex(interfaces, i); options = SCBridgeInterfaceGetOptions(interface); if ((options != NULL) && CFDictionaryGetValueIfPresent(options, CFSTR("__AUTO__"), (const void **)&name) && _SC_CFEqual(name, bridgeName)) { bridge = interface; CFRetain(bridge); break; } } CFRelease(interfaces); } if (bridge == NULL) { bridge = SCBridgeInterfaceCreate(prefs); if (bridge != NULL) { CFMutableDictionaryRef newOptions; Boolean ok; newOptions = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(newOptions, CFSTR("__AUTO__"), bridgeName); ok = SCBridgeInterfaceSetOptions(bridge, newOptions); CFRelease(newOptions); if (!ok) { CFRelease(bridge); bridge = NULL; } } } return bridge; }
CFArrayRef /* of SCNetworkInterfaceRef's */ SCNetworkSetCopyAvailableInterfaces(SCNetworkSetRef set) { CFMutableArrayRef available; CFMutableSetRef excluded = NULL; int i; CFArrayRef interfaces; CFIndex n_interfaces; CFIndex n_exclusions = 0; SCPreferencesRef prefs; SCNetworkSetPrivateRef setPrivate; setPrivate = (SCNetworkSetPrivateRef)set; prefs = setPrivate->prefs; interfaces = _SCNetworkInterfaceCopyAllWithPreferences(prefs); n_interfaces = CFArrayGetCount(interfaces); if (n_interfaces == 0) { return interfaces; } if (prefs != NULL) { CFArrayRef bridges = NULL; excluded = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); #if !TARGET_OS_IPHONE CFArrayRef bonds = NULL; bonds = SCBondInterfaceCopyAll(prefs); if (bonds != NULL) { __SCBondInterfaceListCollectMembers(bonds, excluded); CFRelease(bonds); } #endif /* !TARGET_OS_IPHONE */ bridges = SCBridgeInterfaceCopyAll(prefs); if (bridges != NULL) { __SCBridgeInterfaceListCollectMembers(bridges, excluded); CFRelease(bridges); } n_exclusions = CFSetGetCount(excluded); } if (n_exclusions == 0) { if (excluded != NULL) { CFRelease(excluded); } return interfaces; } available = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); for (i = 0; i < n_interfaces; i++) { SCNetworkInterfaceRef interface; interface = CFArrayGetValueAtIndex(interfaces, i); if (CFSetContainsValue(excluded, interface)) { // if excluded continue; } CFArrayAppendValue(available, interface); } CFRelease(interfaces); CFRelease(excluded); return available; }
CFArrayRef /* of SCNetworkInterfaceRef's */ SCBondInterfaceCopyAvailableMemberInterfaces(SCPreferencesRef prefs) { CFMutableArrayRef available; CFMutableSetRef excluded; CFArrayRef interfaces; available = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); excluded = CFSetCreateMutable (NULL, 0, &kCFTypeSetCallBacks); // exclude Bond [member] interfaces interfaces = SCBondInterfaceCopyAll(prefs); if (interfaces != NULL) { __SCBondInterfaceListCollectMembers(interfaces, excluded); CFRelease(interfaces); } // exclude Bridge [member] interfaces interfaces = SCBridgeInterfaceCopyAll(prefs); if (interfaces != NULL) { __SCBridgeInterfaceListCollectMembers(interfaces, excluded); CFRelease(interfaces); } // exclude VLAN [physical] interfaces interfaces = SCVLANInterfaceCopyAll(prefs); if (interfaces != NULL) { CFIndex i; CFIndex n; n = CFArrayGetCount(interfaces); for (i = 0; i < n; i++) { SCVLANInterfaceRef vlanInterface; SCNetworkInterfaceRef physical; // exclude the physical interface of this VLAN vlanInterface = CFArrayGetValueAtIndex(interfaces, i); physical = SCVLANInterfaceGetPhysicalInterface(vlanInterface); CFSetAddValue(excluded, physical); } CFRelease(interfaces); } // identify available interfaces interfaces = __SCNetworkInterfaceCopyAll_IONetworkInterface(); if (interfaces != NULL) { CFIndex i; CFIndex n; n = CFArrayGetCount(interfaces); for (i = 0; i < n; i++) { SCNetworkInterfaceRef interface; SCNetworkInterfacePrivateRef interfacePrivate; interface = CFArrayGetValueAtIndex(interfaces, i); interfacePrivate = (SCNetworkInterfacePrivateRef)interface; if (!interfacePrivate->supportsBond) { // if this interface is not available continue; } if (CFSetContainsValue(excluded, interface)) { // if excluded continue; } CFArrayAppendValue(available, interface); } CFRelease(interfaces); } CFRelease(excluded); return available; }