有没有办法在 iPhone 上获取已启动的 VPN 隧道的套接字描述符,以便我可以在 C++ 库中使用它
Is there a way to get the socket descriptor of the started VPN Tunnel on iPhone so that I could use it in a C++ library
在苹果提供的simpleTunnel示例应用中,容器应用和数据包隧道提供者使用IPC进行通信。
每当启用连接切换按钮时 startVPNTunnel() API 将被调用并且 OS 启动数据包隧道提供程序,后者又调用被覆盖的方法 startTunnelWithOptions()。这是我们开始连接到 VPN 服务器的地方。 startTunnelWithOptions 依次调用 startTunnel,后者调用 createTCPConnectionToEndpoint (connection = provider.createTCPConnectionToEndpoint(端点, enableTLS:false, TLSParameters:nil, delegate:nil))
我们如何从此连接获取套接字描述符(以便我可以在另一个发送 SSL 和其他自定义消息的 C++ 库中使用它)?
(连接是 class NWTCPConnection 的实例,但 NWTCPConnection 似乎不包含套接字描述符)
不确定我是否理解你的意思,但如果你正在寻找套接字的文件描述符 - 你找不到它。
我还没有找到从中取出套接字的方法。这就是他们在 NWTCPConnection
上公开高级别 API read/write/cancel 的全部原因。
但是,createTCPConnectionToEndpoint
不是必需的。这只是一种方便的方法。您可以在套接字级别上执行所有操作并忽略此 API(如果它更适合您)。
试试这样的东西:
let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32;
并将 tunFd
发送到您的 C/C++ 端用作 file-descriptor and/or 套接字。
另见
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)
在苹果提供的simpleTunnel示例应用中,容器应用和数据包隧道提供者使用IPC进行通信。
每当启用连接切换按钮时 startVPNTunnel() API 将被调用并且 OS 启动数据包隧道提供程序,后者又调用被覆盖的方法 startTunnelWithOptions()。这是我们开始连接到 VPN 服务器的地方。 startTunnelWithOptions 依次调用 startTunnel,后者调用 createTCPConnectionToEndpoint (connection = provider.createTCPConnectionToEndpoint(端点, enableTLS:false, TLSParameters:nil, delegate:nil))
我们如何从此连接获取套接字描述符(以便我可以在另一个发送 SSL 和其他自定义消息的 C++ 库中使用它)? (连接是 class NWTCPConnection 的实例,但 NWTCPConnection 似乎不包含套接字描述符)
不确定我是否理解你的意思,但如果你正在寻找套接字的文件描述符 - 你找不到它。
我还没有找到从中取出套接字的方法。这就是他们在 NWTCPConnection
上公开高级别 API read/write/cancel 的全部原因。
但是,createTCPConnectionToEndpoint
不是必需的。这只是一种方便的方法。您可以在套接字级别上执行所有操作并忽略此 API(如果它更适合您)。
试试这样的东西:
let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32;
并将 tunFd
发送到您的 C/C++ 端用作 file-descriptor and/or 套接字。
另见
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)