@@ -30,21 +30,24 @@ fileprivate func socktouint(_ sock: inout sockaddr) -> UInt32 {
3030 return addr. s_addr. bigEndian
3131}
3232
33- struct NetInfo : Hashable , CustomStringConvertible {
34- let name : String
35-
36- let hostIP : String
37- let maskIP : String
33+ public struct NetInfo : Hashable , CustomStringConvertible {
34+ public let name : String
35+ public let hostIP : String
36+ public let destIP : String
37+ public let maskIP : String
3838
3939 private let host : UInt32
40+ private let dest : UInt32
4041 private let mask : UInt32
4142
42- init ( name: String , host: UInt32 , mask: UInt32 ) {
43+ init ( name: String , host: UInt32 , dest : UInt32 , mask: UInt32 ) {
4344 self . name = name
4445 self . host = host
46+ self . dest = dest
4547 self . mask = mask
46- self . hostIP = uti ( host) ?? " nil "
47- self . maskIP = uti ( mask) ?? " nil "
48+ self . hostIP = uti ( host) ?? " 10.7.0.0 "
49+ self . destIP = uti ( dest) ?? " 10.7.0.1 "
50+ self . maskIP = uti ( mask) ?? " 255.255.255.0 "
4851 }
4952
5053 init ? ( _ ifaddr: ifaddrs ) {
@@ -53,33 +56,37 @@ struct NetInfo: Hashable, CustomStringConvertible {
5356 else { return nil }
5457
5558 let host = socktouint ( & ifaddr. ifa_addr. pointee)
59+ let dest = socktouint ( & ifaddr. ifa_dstaddr. pointee)
5660 let mask = socktouint ( & ifaddr. ifa_netmask. pointee)
5761
58- self . init ( name: ianame, host: host, mask: mask)
62+ self . init ( name: ianame, host: host, dest : dest , mask: mask)
5963 }
6064
6165 // computed networking values (still numeric internally)
62- var minIPInSubnet : UInt32 { host & mask }
63- var maxIPInSubnet : UInt32 { host | ~ mask }
66+ public var minIP : UInt32 { host & mask }
67+ public var maxIP : UInt32 { host | ~ mask }
6468
65- var minIPString : String { uti ( minIPInSubnet ) ?? " nil " }
66- var maxIPString : String { uti ( maxIPInSubnet ) ?? " nil " }
69+ public var minIPString : String { uti ( minIP ) ?? " nil " }
70+ public var maxIPString : String { uti ( maxIP ) ?? " nil " }
6771
68- var description : String {
69- " \( name) | ip= \( hostIP) mask= \( maskIP) range= \( minIPString) - \( maxIPString) "
72+ public var description : String {
73+ " \( name) | ip= \( hostIP) dest= \( destIP ) mask=\( maskIP) range= \( minIPString) - \( maxIPString) "
7074 }
7175}
7276
73- final class IfManager : @unchecked Sendable {
77+ final class IfManager : Sendable {
78+ public static let shared = IfManager ( )
79+ nonisolated ( unsafe) private( set) var addrs : Set < NetInfo > = Set ( )
7480
75- private init ( ) { }
76- static let shared = IfManager ( )
77-
78- // always get freshly computed addresses
79- var addrs : Set < NetInfo > {
80- Self . query ( )
81+ private init ( ) {
82+ self . addrs = IfManager . query ( )
8183 }
84+
8285
86+ public func query( ) {
87+ addrs = IfManager . query ( )
88+ }
89+
8390 private static func query( ) -> Set < NetInfo > {
8491 var addrs = Set < NetInfo > ( )
8592 var head : UnsafeMutablePointer < ifaddrs > ? = nil
@@ -112,15 +119,14 @@ final class IfManager: @unchecked Sendable {
112119 // try old 10.7.0.1 first, then fallback to next v4
113120 // user should only be connected to StosVPN/LocalDevVPN
114121 addrs. first {
115- $0. minIPString == " 10.7.0.1 " ||
116- $0. minIPString == " 192.168.56.1 " ||
122+ $0. hostIP == " 10.7.0.1 " ||
117123 $0. name. starts ( with: " utun " )
118124 }
119125 }
120126
121127 var sideVPNPatched : Bool {
122128 nextLAN? . maskIP == nextProbableSideVPN? . maskIP &&
123- nextLAN? . maxIPInSubnet == nextProbableSideVPN? . maxIPInSubnet
129+ nextLAN? . maxIP == nextProbableSideVPN? . maxIP
124130 }
125131}
126132
0 commit comments