本文整理汇总了Java中org.jnetpcap.PcapHandler类的典型用法代码示例。如果您正苦于以下问题:Java PcapHandler类的具体用法?Java PcapHandler怎么用?Java PcapHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PcapHandler类属于org.jnetpcap包,在下文中一共展示了PcapHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SKIPtestOpenLiveAndDispatch
import org.jnetpcap.PcapHandler; //导入依赖的package包/类
/**
* Test disabled, as it requires live packets to capture. To enable the test
* just rename the method, by removing the prefix SKIP. Then make sure there
* are live packets to be captured.
*/
public void SKIPtestOpenLiveAndDispatch() {
WinPcap winPcap = WinPcap.openLive(device, 10000, 1, 60 * 1000, errbuf);
assertNotNull(winPcap);
PcapHandler<String> handler = new PcapHandler<String>() {
public void nextPacket(String user, long seconds, int useconds,
int caplen, int len, ByteBuffer buffer) {
System.out.printf("%s, ts=%s caplen=%d len=%d capacity=%d\n", user
.toString(), new Date(seconds * 1000).toString(), caplen, len,
buffer.capacity());
}
};
winPcap.dispatch(10, handler, "Hello");
winPcap.close();
}
示例2: setUp
import org.jnetpcap.PcapHandler; //导入依赖的package包/类
protected void setUp() throws Exception {
errbuf = new StringBuilder();
printTimestampHandler = new PcapHandler<String>() {
private int i = 0;
public void nextPacket(String msg, long seconds, int useconds,
int caplen, int len, ByteBuffer buffer) {
Date ts = new Date(seconds * 1000);
msg = (msg == null) ? "captured on" : msg;
System.out.printf("Packet #%d %s %s (cap=%d, len=%d)\n", i++, msg, ts,
caplen, len);
}
};
}