Post

Replies

Boosts

Views

Activity

Reply to Unable to configure routing in NEPacketTunnelNetworkSettings
The code I use to test routing is below. private func sendUDPRequestWithSocket() { let clientSocket = socket(AF_INET, SOCK_DGRAM, 0) guard clientSocket != -1 else { perror("Error creating socket") return } var addr = sockaddr_in() addr.sin_family = sa_family_t(AF_INET) addr.sin_port = in_port_t(UInt16(59178).bigEndian) addr.sin_addr.s_addr = inet_addr("192.168.0.103") withUnsafePointer(to: addr) { ptrAddr in ptrAddr.withMemoryRebound(to: sockaddr.self, capacity: 1) { ptrSockaddr in guard connect(clientSocket, ptrSockaddr, socklen_t(MemoryLayout<sockaddr_in>.size)) != -1 else { perror("Error connecting to server") close(clientSocket) return } } } let message = ““Text message”” guard let messageData = message.data(using: .utf8) else { print("Error encoding message") return } _ = messageData.withUnsafeBytes { bufferPointer in send(clientSocket, bufferPointer.baseAddress, messageData.count, 0) } } I have an active UDP server on "192.168.0.103" Behavior depending on includedRoutes option value: includedRoutes = [NEIPv4Route.default())] - no packets in the packet flow includedRoutes = [NEIPv4Route.default(), NEIPv4Route(destinationAddress: "192.168.0.103", subnetMask: "255.255.255.0")] - no packets in the packet flow includedRoutes = [NEIPv4Route.default(), NEIPv4Route(destinationAddress: "192.168.0.103", subnetMask: "255.255.255.252")] - packets present in the packet flow
Apr ’24
Reply to Unable to configure routing in NEPacketTunnelNetworkSettings
@eskimo thanks for you answer. You are right. There is missed curly bracket at the end. Unfortunately it does not explains the problem. Snipped with fixed curly brackets: override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) { ... let networkSettings = self.initTunnelSettings(proxyHost: self.localProxyHost, proxyPort: PacketTunnelProvider.localProxyPort) setTunnelNetworkSettings(networkSettings) { (error) in if let error = error { completionHandler(error) return } self.readPackets() NSLog("Proxy address: \(networkSettings.proxySettings?.httpsServer?.address)") completionHandler(nil) } }
Apr ’24