简体   繁体   English

在打开Socket之前,Android VpnService如何处理传入的数据包?

[英]How does Android VpnService handle incoming packets before Socket is opened?

I am trying to use the VpnService API to capture packets (on Android 4.4). 我正在尝试使用VpnService API捕获数据包(在Android 4.4上)。 I've been following an example at: 我一直在关注以下示例:

http://www.thegeekstuff.com/2014/06/android-vpn-service/ http://www.thegeekstuff.com/2014/06/android-vpn-service/

I establish the vpn connection using a builder, which is configured using the following code (which is borrowed from the ToyVPN sample, as I'm sure many of you will recognize): 我使用构建器建立了vpn连接,该构建器使用以下代码进行配置(该构建器是从ToyVPN示例中借用的,因为我敢肯定你们中的许多人会认识到):

        // Configure a builder while parsing the parameters.
    Builder builder = new Builder();
    builder.setMtu(1500);
    builder.addAddress("192.168.0.1", 24);
    builder.addRoute("0.0.0.0", 0);
    try {
        mInterface.close();
    } catch (Exception e) {
        // ignore
    }

    mInterface = builder.establish();

The general concept is that with VpnService, I am able to get outbound packets and log them. 一般的概念是,使用VpnService,我可以获取出站数据包并记录它们。 Then I open a Socket to the original destination and forward the packets. 然后,我打开一个到原始目的地的套接字并转发数据包。 When the response comes, it will be via the Socket that was opened. 当响应到来时,它将通过已打开的套接字。

So my question is, what happens when an IP address sends me a packet before I've opened a Socket to that address? 所以我的问题是,当我在打开该地址的套接字之前,某个IP地址向我发送数据包时,会发生什么? I'm guessing that either it bypasses the VPN and arrives as normal, or is dropped entirely (probably the former?). 我猜想它要么绕过VPN并正常到达,要么被完全丢弃(可能是前者?)。 Any insight is appreciated. 任何见解均表示赞赏。

When you addRoute("0.0.0.0",0); 当您添加Route(“ 0.0.0.0”,0); All packets will be routed to this Tun interface. 所有数据包将被路由到此Tun接口。 Now its upto you whether you want to forward them to original destination or not. 现在由您决定是否要将它们转发到原始目的地。

So answer to your question is you still get packets from the application which is trying to connect to its server, and now its up to you whether you allow its are not. 因此,您的问题的答案是,您仍然会从尝试连接到其服务器的应用程序中获取数据包,而现在,是否允许它取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM