ios - 有没有办法在 iPhone 上获取启动的 VPN 隧道的套接字描述符,以便我可以在 C++ 库中使用它

标签 ios sockets tcp vpn tunnel

在苹果提供的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/

相关文章:

c++ - 向 TCP 流添加加密?

iphone - NSLog 在外部返回 nil (id)

ios - 将事件添加到以编程方式生成的 UIView

ios - UIViewController 的根 UIView 的 Superview 是 nil 吗?

c++ - 使用 cygwin 在 Windows 中使用套接字

java - 套接字:BufferedReader readLine() block

java - 跨 TCP 套接字与 ObjectInputStream、Java 和 Lua 客户端联网

ios - UIAlertController 抛出 NSInvalidArgumentException

python telnet 客户端通过带选项卡完成的套接字

Android Socket 读取缓冲区大小问题