gPrefsRef = SCPreferencesCreate(nil, CFSTR("InterfaceConfig2"), nil);
if (gPrefsRef == nil)
errorAndExit("InterfaceConfig failure: SCPreferencesCreate failed");
if (!SCPreferencesLock(gPrefsRef, YES))
errorAndExit("InterfaceConfig failure: SCPreferencesLock could not get a lock");
NSEnumerator *e = [(NSArray *)SCNetworkSetCopyServices(SCNetworkSetCopyCurrent(gPrefsRef)) objectEnumerator];
SCNetworkServiceRef service;
while (service = (SCNetworkServiceRef)[e nextObject]) {
interfaceRef = SCNetworkServiceGetInterface(service);
if (isInterfaceOfType(interfaceRef, kSCNetworkInterfaceTypeIEEE80211)) {
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);