0

我的应用程序IPv4使用NEPacketTunnelProvider. 隧道系统运行良好,但在 IPv6 中无法运行。

我正在尝试使我的VPN应用程序适应ipv6环境,但我不知道如何开始,请告诉我该怎么做。

这是我的代码:

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)
4

1 回答 1

0

newSettings.ipv4Settings = NEIPv4Settings(addresses: [ip], subnetMasks: [subnet]) 只有一个ipv4Settings用于 newSettings

您应该添加这些行:

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

但是我的demo的UDPSessionsetReadHandler没有涉及

于 2020-04-29T03:38:19.050 回答