Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,25 @@ extension IPAddress.IPv6 {
func sys_inet_ntop(family: CInt, bytes: UnsafeRawPointer, length: Int) -> String? {
var addressBytes: [Int8] = Array(repeating: 0, count: length)
return addressBytes.withUnsafeMutableBufferPointer { addressBytesPtr -> String? in
// The returned pointer is the same as addressBytesPtr.baseAddress but nil on error.
// Unwrapped once here because Bionic annotates `dst` as `char * _Nonnull`, so it
// imports as a non-optional pointer; Darwin, Glibc and WinSDK import it as optional.
guard let destination = addressBytesPtr.baseAddress else {
return nil
}

// The returned pointer is the same as destination but nil on error.
#if os(Windows)
// On Windows `inet_ntop`'s size argument is `size_t` (imported as `Int`).
if inet_ntop(family, bytes, addressBytesPtr.baseAddress, length) == nil {
if inet_ntop(family, bytes, destination, length) == nil {
return nil
}
#else
if inet_ntop(family, bytes, addressBytesPtr.baseAddress, socklen_t(length)) == nil {
if inet_ntop(family, bytes, destination, socklen_t(length)) == nil {
return nil
}
#endif

return addressBytesPtr.baseAddress!.withMemoryRebound(
return destination.withMemoryRebound(
to: UInt8.self,
capacity: addressBytesPtr.count
) {
Expand Down