2014-10-30 491 views

回答

0

PcapPacket类有方法 public int transferStateAndDataTo(byte [] buffer)它将数据包的内容复制到字节数组。
与大小定义字节[]作为packet.getTotalSize()

如果你正在寻找的有效载荷

//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)还有其它方法可用与执行

+0

谢谢。但是,在将字节数组数据包解码回pcap数据包时,异常发生在IP4()协议中。是否足够做这样的转换:PcapPacket包=新的PcapPacket(字节)? – user3823859 2014-12-13 05:30:38