mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-23 14:07:07 +00:00
Fix
This commit is contained in:
parent
84dd9403c3
commit
64b2cc6f29
@ -45,20 +45,14 @@ public class SocketController {
|
||||
var addr = sockaddr_un()
|
||||
addr.sun_family = sa_family_t(AF_UNIX)
|
||||
|
||||
var len: Int = 0
|
||||
let len = MemoryLayout.size(ofValue: addr.sun_path) - 1
|
||||
withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
|
||||
path.withCString { cstring in
|
||||
len = strlen(cstring)
|
||||
strncpy(pointer, cstring, len)
|
||||
}
|
||||
}
|
||||
addr.sun_len = UInt8(len+2)
|
||||
|
||||
var data: Data!
|
||||
withUnsafePointer(to: &addr) { pointer in
|
||||
data = Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
|
||||
// The buffer is pre-zeroed, so manual termination is unnecessary.
|
||||
precondition(memccpy(pointer, path, 0, len) != nil)
|
||||
}
|
||||
addr.sun_len = UInt8(len)
|
||||
|
||||
let data = withUnsafeBytes(of: &addr, Data.init(_:))
|
||||
return SocketPort(protocolFamily: AF_UNIX, socketType: SOCK_STREAM, protocol: 0, address: data)!
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user