Post

Replies

Boosts

Views

Activity

how to extract the hostname from a https/tls request in NEFilterSocketFlow
Hi guys, I try to create a content filter app by using network extension api. When it comes to a https/tls remote endpoint, the remoteEndpoint.hostname will always be "" instead of the actual hostname. How can I extract the actual hostname? private func filterTraffic(flow: NEFilterSocketFlow) -> NEFilterNewFlowVerdict { // Default action from settings will be used if no rules match logger.error("filter traffic...") guard let remoteEndpoint = flow.remoteEndpoint as? NWHostEndpoint else { logger.error("not a NWHostEndpoint)") return .allow() } logger.error("host name: \(remoteEndpoint.hostname)") if remoteEndpoint.hostname.hasSuffix("google.com"){ logger.error("google.com") return .drop() } return .allow() } code-block
1
0
412
Jun ’25
How to create a socket connection and handle data stream in swift ?
Hi, I try to create a socket client to connect to a server, and get/send data as well. My code as below, it connected successfully to the server, but I don't how to receive /send data. Can somebody help me out of this? import Foundation import CoreFoundation class SocketClient {          private(set) var host: String     private(set) var port: Int     private var socket: CFSocket?          init(_ host:String, _ port: Int){         self.host = host         self.port = port     }     func connect(){         //create socket         self.socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, CFSocketCallBackType.dataCallBack.rawValue, {             socket, callBackType, address, data, info in             if CFSocketCallBackType.dataCallBack == callBackType && data != nil {                 debugPrint("incomming。。。")                              }         }, nil)                  guard self.socket != nil else{             debugPrint("create socket failed")             return         }         //binding ip         var address: sockaddr_in = sockaddr_in()         address.sin_family = sa_family_t(PF_INET)         address.sin_port = in_port_t(self.port)         var inAddr = in_addr()         inAddr.s_addr = inet_addr(self.host)         address.sin_addr = inAddr         let addrData = CFDataCreate(kCFAllocatorDefault, &address, MemoryLayout.size(ofValue: address))         let result = CFSocketConnectToAddress(self.socket, addrData, 5)         if result == .success {             debugPrint("connect succeed")         } else {             debugPrint("connect failed")         }         let source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, self.socket, 1)         CFRunLoopAddSource(CFRunLoopGetCurrent(), source, .commonModes)     } }
0
0
463
Oct ’22
how can i get two wheel picker in one row display correctly
How can I get two wheel picker in one row display correctly?I tried to use HStack, but it did not work. see my code below: import SwiftUI @available(iOS 15.0, *) struct ContentView: View {       @State var min:Int = 0   @State var sec:Int = 0       var body: some View {     Form{       Section{         HStack{           Picker("min", selection: $min){             Text("0")               .tag(0)             Text("1")               .tag(1)             Text("2")               .tag(2)             Text("3")               .tag(3)                         }           .pickerStyle(.wheel)           Picker("sec", selection: $sec){             Text("0")               .tag(0)             Text("1")               .tag(1)             Text("2")               .tag(2)             Text("3")               .tag(3)                         }           .pickerStyle(.wheel)                     }         .frame(height:60)       }     }   } } @available(iOS 15.0, *) struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
1
0
2.2k
Mar ’22
how to extract the hostname from a https/tls request in NEFilterSocketFlow
Hi guys, I try to create a content filter app by using network extension api. When it comes to a https/tls remote endpoint, the remoteEndpoint.hostname will always be "" instead of the actual hostname. How can I extract the actual hostname? private func filterTraffic(flow: NEFilterSocketFlow) -> NEFilterNewFlowVerdict { // Default action from settings will be used if no rules match logger.error("filter traffic...") guard let remoteEndpoint = flow.remoteEndpoint as? NWHostEndpoint else { logger.error("not a NWHostEndpoint)") return .allow() } logger.error("host name: \(remoteEndpoint.hostname)") if remoteEndpoint.hostname.hasSuffix("google.com"){ logger.error("google.com") return .drop() } return .allow() } code-block
Replies
1
Boosts
0
Views
412
Activity
Jun ’25
How to create a socket connection and handle data stream in swift ?
Hi, I try to create a socket client to connect to a server, and get/send data as well. My code as below, it connected successfully to the server, but I don't how to receive /send data. Can somebody help me out of this? import Foundation import CoreFoundation class SocketClient {          private(set) var host: String     private(set) var port: Int     private var socket: CFSocket?          init(_ host:String, _ port: Int){         self.host = host         self.port = port     }     func connect(){         //create socket         self.socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, CFSocketCallBackType.dataCallBack.rawValue, {             socket, callBackType, address, data, info in             if CFSocketCallBackType.dataCallBack == callBackType && data != nil {                 debugPrint("incomming。。。")                              }         }, nil)                  guard self.socket != nil else{             debugPrint("create socket failed")             return         }         //binding ip         var address: sockaddr_in = sockaddr_in()         address.sin_family = sa_family_t(PF_INET)         address.sin_port = in_port_t(self.port)         var inAddr = in_addr()         inAddr.s_addr = inet_addr(self.host)         address.sin_addr = inAddr         let addrData = CFDataCreate(kCFAllocatorDefault, &address, MemoryLayout.size(ofValue: address))         let result = CFSocketConnectToAddress(self.socket, addrData, 5)         if result == .success {             debugPrint("connect succeed")         } else {             debugPrint("connect failed")         }         let source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, self.socket, 1)         CFRunLoopAddSource(CFRunLoopGetCurrent(), source, .commonModes)     } }
Replies
0
Boosts
0
Views
463
Activity
Oct ’22
how can i get two wheel picker in one row display correctly
How can I get two wheel picker in one row display correctly?I tried to use HStack, but it did not work. see my code below: import SwiftUI @available(iOS 15.0, *) struct ContentView: View {       @State var min:Int = 0   @State var sec:Int = 0       var body: some View {     Form{       Section{         HStack{           Picker("min", selection: $min){             Text("0")               .tag(0)             Text("1")               .tag(1)             Text("2")               .tag(2)             Text("3")               .tag(3)                         }           .pickerStyle(.wheel)           Picker("sec", selection: $sec){             Text("0")               .tag(0)             Text("1")               .tag(1)             Text("2")               .tag(2)             Text("3")               .tag(3)                         }           .pickerStyle(.wheel)                     }         .frame(height:60)       }     }   } } @available(iOS 15.0, *) struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
Replies
1
Boosts
0
Views
2.2k
Activity
Mar ’22