mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-09-09 05:50:57 +00:00
Cleanup socketport construction (#668)
This commit is contained in:
parent
c8cf0db1c5
commit
74f4f1c0b1
@ -133,20 +133,22 @@ private extension SocketPort {
|
||||
|
||||
convenience init(path: String) {
|
||||
var addr = sockaddr_un()
|
||||
addr.sun_family = sa_family_t(AF_UNIX)
|
||||
|
||||
var len: Int = 0
|
||||
withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
|
||||
let length = withUnsafeMutablePointer(to: &addr.sun_path.0) { pointer in
|
||||
path.withCString { cstring in
|
||||
len = strlen(cstring)
|
||||
let len = strlen(cstring)
|
||||
strncpy(pointer, cstring, len)
|
||||
return len
|
||||
}
|
||||
}
|
||||
addr.sun_len = UInt8(len+2)
|
||||
// This doesn't seem to be _strictly_ neccessary with SocketPort.
|
||||
// but just for good form.
|
||||
addr.sun_family = sa_family_t(AF_UNIX)
|
||||
// This mirrors the SUN_LEN macro format.
|
||||
addr.sun_len = UInt8(MemoryLayout<sockaddr_un>.size - MemoryLayout.size(ofValue: addr.sun_path) + length)
|
||||
|
||||
var data: Data!
|
||||
withUnsafePointer(to: &addr) { pointer in
|
||||
data = Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
|
||||
let data = withUnsafePointer(to: &addr) { pointer in
|
||||
Data(bytes: pointer, count: MemoryLayout<sockaddr_un>.size)
|
||||
}
|
||||
|
||||
self.init(protocolFamily: AF_UNIX, socketType: SOCK_STREAM, protocol: 0, address: data)!
|
||||
|
Loading…
Reference in New Issue
Block a user