我需要将数据包转换为字节格式并对其进行解码。如何将使用 jnetpcap 库捕获的数据包转换为数组 [字节],反之亦然?
问问题
3016 次
1 回答
0
PcapPacket 类有方法 public int transferStateAndDataTo(byte[] buffer) 将数据包的内容复制到字节数组。
定义大小为 packet.getTotalSize() 的 byte[]
如果您正在寻找有效载荷
//opens an offline pcap file
Pcap pcap = Pcap.openOffline(pcapIpFile, errbuf);
//packet object
PcapPacket packet = new PcapPacket(JMemory.POINTER);
Payload pl = new Payload();
pcap.nextEx(packet); // retrieves the next packet from input loop thru until eof
if(packet.hasHeader(pl)) //this will check for and retrieve the payload
pl.data() // this will give you the data in the payload as a byte stream
对于不同标头(以太网/ip/tcp)中的数据,实现中还有其他可用的方法
于 2014-11-04T19:01:38.550 回答