All I'm attempting to do is turn of Airport using the System Configuration Framework
This is the code (there may be a few release functions missing). The program actually flows without any problems and returns zero but nothing in the SystemConfig changes.
static SCDynamicStoreRef storeRef = nil;
static SCPreferencesRef gPrefsRef = nil;
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
SCNetworkInterfaceRef interfaceRef;
CFArrayRef interfaces = nil;
CFIndex interfaceCount;
CFIndex interfaceIndex;
storeRef = SCDynamicStoreCreate(nil, CFSTR("interfaceConfig"), nil, nil);
if (storeRef == nil)
errorAndExit("InterfaceConfig failure: SCDynamicStoreCreate failed");
gPrefsRef = SCPreferencesCreate(nil, CFSTR("InterfaceConfig"), nil);
if (gPrefsRef == nil)
errorAndExit("InterfaceConfig failure: SCPreferencesCreate failed");
if (!SCPreferencesLock(gPrefsRef, YES))
errorAndExit("InterfaceConfig failure: SCPreferencesLock could not get a lock");
interfaces = SCNetworkInterfaceCopyAll();
if (interfaces == nil)
errorAndExit("InterfaceConfig failure: SCNetworkInterfaceCopyAll return nil interfaces");
interfaceCount = CFArrayGetCount(interfaces);
for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) {
interfaceRef = CFArrayGetValueAtIndex(interfaces, interfaceIndex);
if (isInterfaceOfType(interfaceRef, kSCNetworkInterfaceTypeIEEE80211)) {
// Airport interface needs to be powered off
CFDictionaryRef dict = (CFMutableDictionaryRef)[NSMutableDictionary dictionaryWithObjectsAndKeys:(NSString *)kSCValNetAirPortJoinModeAutomatic,
(NSString *)kSCPropNetAirPortJoinMode,
[NSNumber numberWithInt:0],
(NSString *)kSCPropNetAirPortPowerEnabled, nil];
if (SCNetworkInterfaceSetConfiguration(interfaceRef, dict) == NO) {
syslog(LOG_LOCAL7 | LOG_ALERT, "InterfaceConfig failure: Could not set Airport interface settings");
}
}
}
if (SCPreferencesCommitChanges(gPrefsRef) == NO)
errorAndExit("InterfaceConfig failure: SCPreferencesCommitChanges failed");
if (SCPreferencesApplyChanges(gPrefsRef) == NO)
errorAndExit("InterfaceConfig failure: SCPreferencesApplyChanges failed");
SCPreferencesUnlock(gPrefsRef);
CFRelease(gPrefsRef);
CFRelease(storeRef);
[pool release];
return 0;
}