在苹果提供的simpleTunnel示例应用中,容器应用和数据包隧道提供者使用IPC进行通信。
每当启用连接切换按钮时,startVPNTunnel() API 将被调用,操作系统将启动数据包隧道提供程序,后者又会调用重写方法 startTunnelWithOptions()。这是我们开始连接到 VPN 服务器的地方。 startTunnelWithOptions 依次调用 startTunnel,后者调用 createTCPConnectionToEndpoint (connection = provider.createTCPConnectionToEndpoint(endpoint, enableTLS:false, TLSParameters:无,委托(delegate):无))
我们如何从这个连接中获取套接字描述符(以便我可以在另一个发送 SSL 和其他自定义消息的 C++ 库中使用它)? (connnection 是类NWTCPConnection 的实例,但是NWTCPConnection 似乎不包含套接字描述符)
最佳答案
尝试这样的事情:
let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32;
并将 tunFd
发送到您的 C/C++ 端以用作文件描述符和/或套接字。
另见 How to parse network-extension packets?
Note that although Apple recommends against using this method in production, it's end-year 2021, and works just fine yet.
Apple claims that "iOS is in the process of moving to a user space networking stack."
(but they did not change anything yet)
关于ios - 有没有办法在 iPhone 上获取启动的 VPN 隧道的套接字描述符,以便我可以在 C++ 库中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35466167/