How can I run route command use Swift API or other system API?

for example, sudo route add default  192.168.10.1 convert to system api code use swift/c/oc.

Answered by Systems Engineer in 687566022

Is there any way without modifying the VPN type to change route?

Using the NEPacketTunnelProvider API is the default way to alter the route table to create a virtual interface. If you are wanting to alter the routing table for other non-app usage then the route command will work for you in this context. NEVPNManager will not specifically allow you to define routes like NEPacketTunnelProvider.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

It looks like you are wanting to alter the routing table here with a Swift API. In general, that is what the Network Extension APIs for NEPacketTunnelProvider allow you to do, create a virtual interface for your VPN in the routing table. Now, it looks like you are wanting to do this on watchOS based on the tag for wwdc21-10002, is that correct or did you mean iOS or macOS here instead?

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer

Is there any way without modifying the VPN type to change route?

Using the NEPacketTunnelProvider API is the default way to alter the route table to create a virtual interface. If you are wanting to alter the routing table for other non-app usage then the route command will work for you in this context. NEVPNManager will not specifically allow you to define routes like NEPacketTunnelProvider.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
How can I run route command use Swift API or other system API?
 
 
Q