上章介绍过VPN 的创建,本章主要介绍抓取数据包,VPN数据出来的IP包,先对IP包做简单介绍。
IP数据包是在网络层进行传输的,主要是用于路由间寻址传输,下面看一下IP数据包内都有些什么东西。
版本:占4位,指ip协议的版本
如:IP 数据包第一个字节 右移4位就得到IP协议 等于4为IPV4 等于6为IPV6
/**
* 处理IP数据包
*/
private static void handleIpPacakge(int readBytes, ByteBuffer bufferToNetwork) {
byte[] data = new byte[readBytes];
SoftReference<byte[]> softReferencedata = new SoftReference(data);
bufferToNetwork.flip();
bufferToNetwork.get(data, 0, readBytes);
BerTlvBuilder berTlvBuilder = new BerTlvBuilder();
ByteBufferPool.release(bufferToNetwork);
if (data[0] >> 4 == 4) {
Logger.d("ipAddress = " + (data[16] & 0xff) + "." + (data[17] & 0xff) + "." + (data[18] & 0xff)

最低0.47元/天 解锁文章
2245






