我正在查看ToyVpn项目中的VpnService.java。

我最初在run方法中看到以下几行

 // Create a DatagramChannel as the VPN tunnel.
 tunnel = DatagramChannel.open();

 // Protect the tunnel before connecting to avoid loopback.
 if (!protect(tunnel.socket())) {
      throw new IllegalStateException("Cannot protect the tunnel");
 }

我知道第一行创建了一个数据报/UDP channel 来连接到远程服务器。但是我不明白“保护”方法到底在做什么。

有人可以向我解释尽可能多的技术细节。谢谢你。

最佳答案

您可以从android.net.VpnService library中看到,它是从ToyVpnService.java类中导入的the source code中获得的函数。

您可以找到它的作用here

10-07 13:38