SCNetworkServiceRef vpnSrvcRef = SCNetworkServiceCreate(prefs, ipsecIfRef);
SCNetworkServiceSetName(vpnSrvcRef, (__bridge CFStringRef)vpnServiceName);
CFStringRef keysIPSec[9] = { NULL, NULL, NULL ,NULL, NULL, NULL ,NULL, NULL, NULL };
CFStringRef valsIPSec[9] = { NULL, NULL, NULL ,NULL, NULL, NULL ,NULL, NULL, NULL };
CFIndex numkeys = 0;
keysIPSec[numkeys] = kSCPropNetIPSecAuthenticationMethod;
valsIPSec[numkeys++] = kSCValNetIPSecAuthenticationMethodSharedSecret;
keysIPSec[numkeys] = kSCPropNetIPSecLocalIdentifier;
valsIPSec[numkeys++] = (__bridge CFStringRef)vpnGrpName;
keysIPSec[numkeys] = kSCPropNetIPSecLocalIdentifierType;
valsIPSec[numkeys++] = kSCValNetIPSecLocalIdentifierTypeKeyID;
keysIPSec[numkeys] = kSCPropNetIPSecRemoteAddress;
valsIPSec[numkeys++] = (__bridge CFStringRef)vpnGWAddress;
keysIPSec[numkeys] = kSCPropNetIPSecSharedSecret;
valsIPSec[numkeys++] = (__bridge CFStringRef)vpnGrpPwd;
keysIPSec[numkeys] = kSCPropNetIPSecSharedSecretEncryption;
valsIPSec[numkeys++] = kSCValNetIPSecSharedSecretEncryptionKeychain;
keysIPSec[numkeys] = kSCPropNetIPSecXAuthName;
valsIPSec[numkeys++] = (__bridge CFStringRef)vpnUsrName;
keysIPSec[numkeys] = kSCPropNetIPSecXAuthPassword;
valsIPSec[numkeys++] = (__bridge CFStringRef)vpnUsrPwd;
keysIPSec[numkeys] = kSCPropNetIPSecXAuthPasswordEncryption;
valsIPSec[numkeys] = kSCValNetIPSecXAuthPasswordEncryptionPrompt;
CFDictionaryRef ipsecOptions
= CFDictionaryCreate
(NULL, (const void **)&keysIPSec,
(const void **)&valsIPSec, numkeys,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
BOOL success = SCNetworkInterfaceSetConfiguration (ipsecIfRef, ipsecOptions);