wireguard-go-bridge: use C string instead of gostring_t
Signed-off-by: Andrej Mihajlov <and@mullvad.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
edde27a0a0
commit
30406dec6d
@@ -70,7 +70,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
}
|
||||
ifnamePtr.deallocate()
|
||||
wg_log(.info, message: "Tunnel interface is \(self.ifname ?? "unknown")")
|
||||
let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration().withGoString { return wgTurnOn($0, fileDescriptor) }
|
||||
let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration()
|
||||
.withCString { return wgTurnOn($0, fileDescriptor) }
|
||||
if handle < 0 {
|
||||
wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(handle)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend)
|
||||
@@ -146,18 +147,10 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
|
||||
#if os(iOS)
|
||||
if let packetTunnelSettingsGenerator = packetTunnelSettingsGenerator {
|
||||
_ = packetTunnelSettingsGenerator.endpointUapiConfiguration().withGoString { return wgSetConfig(handle, $0) }
|
||||
_ = packetTunnelSettingsGenerator.endpointUapiConfiguration()
|
||||
.withCString { return wgSetConfig(handle, $0) }
|
||||
}
|
||||
#endif
|
||||
wgBumpSockets(handle)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func withGoString<R>(_ call: (gostring_t) -> R) -> R {
|
||||
func helper(_ pointer: UnsafePointer<Int8>?, _ call: (gostring_t) -> R) -> R {
|
||||
return call(gostring_t(p: pointer, n: utf8.count))
|
||||
}
|
||||
return helper(self, call)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user