aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/VPN
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-11-02 05:34:17 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-11-02 05:34:17 +0100
commit7fc0e3ee94753ca3b8e4d9e5cd5af4a6bffdff93 (patch)
tree35d960aef27711cc6fc6efd784f333f67650309c /WireGuard/WireGuard/VPN
parentwireguard-go-bridge: use boottime instead of monotonic (diff)
downloadwireguard-apple-7fc0e3ee94753ca3b8e4d9e5cd5af4a6bffdff93.tar.xz
wireguard-apple-7fc0e3ee94753ca3b8e4d9e5cd5af4a6bffdff93.zip
DNSResolver: getaddrinfo returns a sockaddr and inet_ntop takes strlen
The way this was written before was totally wrong. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/VPN')
-rw-r--r--WireGuard/WireGuard/VPN/DNSResolver.swift10
1 files changed, 6 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/VPN/DNSResolver.swift b/WireGuard/WireGuard/VPN/DNSResolver.swift
index 9de2d8e..43e7c41 100644
--- a/WireGuard/WireGuard/VPN/DNSResolver.swift
+++ b/WireGuard/WireGuard/VPN/DNSResolver.swift
@@ -111,18 +111,20 @@ extension DNSResolver {
while (resultPointer != nil) {
let result = resultPointer!.pointee
resultPointer = result.ai_next
- if (result.ai_family == AF_INET && result.ai_addrlen == INET_ADDRSTRLEN) {
- if (inet_ntop(result.ai_family, result.ai_addr, ipv4Buffer, result.ai_addrlen) != nil) {
+ if (result.ai_family == AF_INET && result.ai_addrlen == MemoryLayout<sockaddr_in>.size) {
+ var sa4 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in.self).pointee
+ if (inet_ntop(result.ai_family, &sa4.sin_addr, ipv4Buffer, socklen_t(INET_ADDRSTRLEN)) != nil) {
ipv4AddressString = String(cString: ipv4Buffer)
// If we found an IPv4 address, we can stop
break
}
- } else if (result.ai_family == AF_INET6 && result.ai_addrlen == INET6_ADDRSTRLEN) {
+ } else if (result.ai_family == AF_INET6 && result.ai_addrlen == MemoryLayout<sockaddr_in6>.size) {
if (ipv6AddressString != nil) {
// If we already have an IPv6 address, we can skip this one
continue
}
- if (inet_ntop(result.ai_family, result.ai_addr, ipv6Buffer, result.ai_addrlen) != nil) {
+ var sa6 = UnsafeRawPointer(result.ai_addr)!.assumingMemoryBound(to: sockaddr_in6.self).pointee
+ if (inet_ntop(result.ai_family, &sa6.sin6_addr, ipv6Buffer, socklen_t(INET6_ADDRSTRLEN)) != nil) {
ipv6AddressString = String(cString: ipv6Buffer)
}
}