Reader读取TcpDump读取的Pcap包

测试一个在Android读取Tcpdump抓取的网络包应用,取Packet的代码如下:
(此为AndroidShark中的代码,为一开源项目)
private ArrayList<JPacket> packets = new ArrayList<JPacket>();
StringBuilder errbuf = new StringBuilder();

// Opening the .pcap file.
final Pcap parser = Pcap.openOffline("/mnt/sdcard/shark/shark_capture.pcap",errbuf);

JPacketHandler<String> handler = new JPacketHandler<String>() {
@Override
public void nextPacket(JPacket packet, String user) {
System.out.println("handler is run!!!");
packets.add(packet);
}

};

parser.loop(10, handler, null);
System.out.println("result len is ="+packets .size());
parser.close();

其中,测试中shark_capture.pcap是由wireshark抓取的,在wireshark中正常使用。
现在的问题是packets长度为0,handler中的nextPacket方法似乎一直未被执行,不解,忘做过类似系统的高手指教!

整个项目的源码见附件:

你可能感兴趣的:(android,tcpdump,ArrayList,packet)