From 798b2fed66331f1a7f28bd7d4bdb33bf9e99288d Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Fri, 17 Aug 2018 22:06:39 +0200 Subject: [PATCH] Use first peer's endpoint as the tunnel remote address. --- WireGuardNetworkExtension/PacketTunnelProvider.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index 52752fd..d402aa1 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -37,9 +37,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let validatedEndpoints = endpoints.commaSeparatedToArray().compactMap { try? Endpoint(endpointString: String($0)) }.compactMap {$0} let validatedAddresses = addresses.compactMap { try? CIDRAddress(stringRepresentation: String($0)) }.compactMap { $0 } - if wireGuardWrapper.turnOn(withInterfaceName: interfaceName, settingsString: settings) { - //TODO: Hardcoded values for tunnelRemoteAddress - let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "149.248.160.60") + if let firstEndpoint = validatedEndpoints.first, wireGuardWrapper.turnOn(withInterfaceName: interfaceName, settingsString: settings) { + // We use the first endpoint for the ipAddress + let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: firstEndpoint.ipAddress) newSettings.tunnelOverheadBytes = 80 // IPv4 settings @@ -78,7 +78,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider { } } else { - self.wireGuardWrapper.packetFlow = self.packetFlow completionHandler(PacketTunnelProviderError.tunnelSetupFailed) wireGuardWrapper.configured = false }