20

I am creating an application to connect to a VPN server. I have worked out how to do this, but need to be able to send all traffic over the connection. Is there any code which can do this? So far I have tried:

let manager: NEVPNManager = NEVPNManager.sharedManager()
var p = NEVPNProtocolIPSec()
manager.`protocol` = p

let pw = ""

p.username = ""
p.passwordReference = pw.dataUsingEncoding(NSUTF8StringEncoding)
p.serverAddress = ""
p.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
//p.sharedSecretReference = getPasscodeNSData("vpnSharedSecret")
p.useExtendedAuthentication = true
p.disconnectOnSleep = false
Axel Guilmin
  • 11,454
  • 9
  • 54
  • 64
Calan54
  • 267
  • 3
  • 13
  • Didn't use `NEVPNManager`, but from what I remember when I was configuring VPN networks, you should do this on the server side. In other words, when VPN connection is established, based on server side rules (VPN configuration), your local routing table is modified. You can set up it in a way that just some subnet will be routed through VPN, all traffic, ... Just my $.02, it's a long time ... – zrzka Jul 03 '15 at 15:23
  • It looks like you're configuring a manager without starting it. [This answer](http://stackoverflow.com/a/25027062/860000) appears to have a working example. – Brian Nickel Jul 24 '15 at 16:37
  • Did you see this? https://developer.apple.com/videos/play/wwdc2015-717/ – Gaurav Srivastava Oct 20 '15 at 14:29
  • Maybe my answer could help you http://stackoverflow.com/a/36124092/2858543 – Alexander Yakovlev Mar 21 '16 at 09:42

1 Answers1

1

From Apple:

This is the default routing method. The IP routes are specified by the Packet Tunnel Provider extension at the time that the VPN tunnel is fully established. See NETunnelProvider for more details.

This is something the is specified from the Server end typically, l2tp does allow the user to toggle this setting. For that, take a look at routingMethod part of the NETunnelProvider. Scroll down to the Routing Network Data to the VPN section for the information you are looking for.

Cripto
  • 3,581
  • 7
  • 41
  • 65