xCocoa
xCocoa

Reputation: 553

Send all traffic over VPN connection

i want write a mac vpn client,now ,in the system network ,it has a setting named "Send all traffic over VPN connection",how to set it by code?i think it is not in SCNetworkConfiguration

Upvotes: 0

Views: 1279

Answers (2)

myte
myte

Reputation: 877

here's a method i used before. it illustrates pretty straight forwardly how to get the current ipv4 dictionary to then change it and set it back. change the CFSTR("1") to a 0 or 1 depending on your needs

#define GetCasted(value, type) ((value) && (CFGetTypeID(value) == type##GetTypeID()) ? ((type##Ref)value) : NULL)

-(void)setIPv4Stuff:(SCNetworkServiceRef)service{


    SCNetworkProtocolRef protoR = SCNetworkServiceCopyProtocol(service, kSCNetworkProtocolTypeIPv4);
    CFDictionaryRef proxyDictR = SCNetworkProtocolGetConfiguration(protoR); 

    const void *configMethodP = proxyDictR ? CFDictionaryGetValue(proxyDictR, kSCPropNetIPv4ConfigMethod) : NULL;

    CFStringRef configMethod = GetCasted(configMethodP, CFString);

    CFMutableDictionaryRef newProxyDictR;

    newProxyDictR = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    CFDictionarySetValue(newProxyDictR, kSCPropNetIPv4ConfigMethod, configMethod);
    CFDictionarySetValue(newProxyDictR, kSCPropNetOverridePrimary, CFSTR("1"));

    SCNetworkProtocolSetConfiguration(protoR, newProxyDictR);

    CFRelease(newProxyDictR);

}

Upvotes: 1

helpertask
helpertask

Reputation: 16

kSCPropNetOverridePrimary to 0 should disable this (you can look up that key in the ipv4 dictionary).

You need to set protocol configuration for the ipv4 protocol with that key set to 0 or 1 to disable or enable that flag respectively.

Upvotes: 0

Related Questions