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