Skip to content

Commit ed84a68

Browse files
committed
FlyingSocks: cast Data to sockaddr type, not sockaddr_storage
Fixes: PADL/inferno_ui#20
1 parent 89afc6a commit ed84a68

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Sources/SwiftOCA/OCP.1/Backend/Ocp1FlyingSocksConnection.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,19 @@ fileprivate extension SocketError {
5050

5151
private extension Data {
5252
var socketAddress: any SocketAddress {
53-
try! withUnsafeBytes { unbound -> (any SocketAddress) in
54-
try unbound
53+
withUnsafeBytes { unbound -> (any SocketAddress) in
54+
unbound
5555
.withMemoryRebound(
56-
to: sockaddr_storage
57-
.self
58-
) { storage -> (any SocketAddress) in
59-
let ss = storage.baseAddress!.pointee
60-
switch ss.ss_family {
56+
to: sockaddr.self
57+
) { addr -> (any SocketAddress) in
58+
let sa = addr.baseAddress!
59+
switch sa.pointee.sa_family {
6160
case sa_family_t(AF_INET):
62-
return try sockaddr_in.make(from: ss)
61+
return sa.withMemoryRebound(to: sockaddr_in.self, capacity: 1) { $0.pointee }
6362
case sa_family_t(AF_INET6):
64-
return try sockaddr_in6.make(from: ss)
63+
return sa.withMemoryRebound(to: sockaddr_in6.self, capacity: 1) { $0.pointee }
6564
case sa_family_t(AF_LOCAL):
66-
return try sockaddr_un.make(from: ss)
65+
return sa.withMemoryRebound(to: sockaddr_un.self, capacity: 1) { $0.pointee }
6766
default:
6867
fatalError("unsupported address family")
6968
}

0 commit comments

Comments
 (0)