简体   繁体   中英

How to use the NEPacketTunnelProvider in an ipv6 environment

My application implements an IPv4 tunnel using NEPacketTunnelProvider . The tunneling system works perfect but it doesn't work when it is in the IPv6.

I am trying to make my VPN app adapt to ipv6 environment, but I don't know how to start, please tell me how to do.

Here's my code:

let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
let ip = "32.432.53.1"
let subnet = "10.3.21.1"
newSettings.ipv4Settings = NEIPv4Settings(addresses: [ip], subnetMasks: [subnet])
newSettings.mtu = 1432
newSettings.ipv4Settings?.includedRoutes = [NEIPv4Route.default()]
newSettings.ipv6Settings?.includedRoutes = [NEIPv6Route.default()]
newSettings.dnsSettings = NEDNSSettings(servers: ["8.8.8.8"])
let endPoint = NWHostEndpoint(hostname: "12.432.55.22", port: 9090)
var session = self.createUDPSession(to: endPoint, from: nil)

self.session?.writeDatagram(newData, completionHandler: { (error) in

})
self.session?.setReadHandler({ (newPackets: [Data]?, error: Error?) -> Void in

}, maxDatagrams: NSIntegerMax)

newSettings.ipv4Settings = NEIPv4Settings(addresses: [ip], subnetMasks: [subnet]) there is only a ipv4Settings for the newSettings

You should add these lines:

let ipv6Settings = NEIPv6Settings.init(addresses: ["fe80:1ca8:5ee3:4d6d:aaf5"], networkPrefixLengths: [64])
newSettings.ipv6Settings = ipv6Settings

But my demo's UDPSession setReadHandler is not involved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM