代码之家  ›  专栏  ›  技术社区  ›  nariman amani

如何查找数据包类型

  •  0
  • nariman amani  · 技术社区  · 10 年前

    我正在使用toyvpn示例在android中实现一个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());
            }
    
    1 回复  |  直到 10 年前
        1
  •  0
  •   nariman amani    10 年前

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