当前位置: 首页>>代码示例>>Java>>正文


Java PcapHandler类代码示例

本文整理汇总了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();
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:26,代码来源:TestWinPcapExtensions.java

示例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);
			}
		};

	}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:20,代码来源:TestWinPcapExtensions.java


注:本文中的org.jnetpcap.PcapHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。