如何查找数据包类型

How to find packet type

我正在 android 使用 toyvpn 示例实现 vpn 客户端。 我想检查通过隧道发送和接收的数据包的详细信息。我正在使用 jpcap 库读取数据包,但我真的不知道数据包采用什么协议。我的问题是如何找到数据包的类型。

        // Packets to be sent are queued in this input stream.
        FileInputStream in = new FileInputStream(mInterface.getFileDescriptor());

        // Packets received need to be written to this output stream.
        FileOutputStream out = new FileOutputStream(mInterface.getFileDescriptor());

        // Allocate the buffer for a single packet.
        ByteBuffer packet = ByteBuffer.allocate(32767);
        // Read the outgoing packet from the input stream.
        int length = in.read(packet.array());
        if (length > 0) {
                // Write the outgoing packet to the tunnel.
                packet.limit(length);
                tunnel.write(packet);

                // i use ip packet of jpcap but i think it is wrong
                IPPacket ipPacket = new IPPacket(length,packet.array());
        }

好的,我找到了答案。 vpn 隧道中收到的任何数据包都是互联网层数据包。在这种情况下,我们收到 ip 数据包,然后我们可以从中提取 tcp 或 udp 数据包。