fix broadcast discovery

This commit is contained in:
Ethan Pippin 2022-05-11 09:54:12 -06:00
parent 2b423502ec
commit 8c2219aa00
1 changed files with 2 additions and 3 deletions

View File

@ -129,11 +129,10 @@ open class UDPBroadcastConnection {
var socketAddressLength = socklen_t(MemoryLayout<sockaddr_storage>.size)
let response = [UInt8](repeating: 0, count: 4096)
let UDPSocket = Int32(source.handle)
let pointer = UnsafeMutablePointer<[UInt8]>.allocate(capacity: response.capacity)
pointer.initialize(to: response)
// Do not fix pointer warning. It must work this way.
let bytesRead = withUnsafeMutablePointer(to: &socketAddress) {
recvfrom(UDPSocket, pointer, response.count, 0,
recvfrom(UDPSocket, UnsafeMutableRawPointer(mutating: response), response.count, 0,
UnsafeMutableRawPointer($0).bindMemory(to: sockaddr.self, capacity: 1), &socketAddressLength)
}