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


Java PcapPktHdr类代码示例

本文整理汇总了Java中org.jnetpcap.PcapPktHdr的典型用法代码示例。如果您正苦于以下问题:Java PcapPktHdr类的具体用法?Java PcapPktHdr怎么用?Java PcapPktHdr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PcapPktHdr类属于org.jnetpcap包,在下文中一共展示了PcapPktHdr类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queue

import org.jnetpcap.PcapPktHdr; //导入依赖的package包/类
/**
 * Add a packet to a send queue. This method adds a packet at the end of the
 * send queue pointed by the queue parameter. <code>hdr</code> points to a
 * PcapPktHdr structure with the timestamp and the length of the packet, data
 * points to a buffer with the data of the packet. The PcapPktHdr structure is
 * the same used by WinPcap and libpcap to store the packets in a file,
 * therefore sending a capture file is straightforward. 'Raw packet' means
 * that the sending application will have to include the protocol headers,
 * since every packet is sent to the network 'as is'. The CRC of the packets
 * needs not to be calculated, because it will be transparently added by the
 * network interface.
 * 
 * @param hdr
 *          all fields need to be initialized as they are all used
 * @param data
 *          Buffer containing packet data. The length of the data must much
 *          what is in the header. Also the queue has to be large enough to
 *          hold all of the data, or an exception will be thrown.
 * @return 0 on success; exception thrown on failure
 * @deprecated replaced with new versions of the same method
 */
@Deprecated
public int queue(PcapPktHdr hdr, byte[] data) {

	if (data.length != hdr.getCaplen()) {
		throw new IllegalArgumentException("Buffer length "
				+ "does not equal length in packet header");
	}

	int p = getLen();

	/*
	 * Write the packet header first
	 */
	buffer.setInt(p, (int) hdr.getSeconds());
	buffer.setInt(p + 4, hdr.getUseconds());
	buffer.setInt(p + 8, hdr.getCaplen());
	buffer.setInt(p + 12, hdr.getLen());

	buffer.setByteArray(p + 16, data);
	incLen(16 + data.length);

	return 0;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:45,代码来源:WinPcapSendQueue.java

示例2: testSendQueueDepracated

import org.jnetpcap.PcapPktHdr; //导入依赖的package包/类
/**
 * Test send queue depracated.
 */
@SuppressWarnings("deprecation")
 public void testSendQueueDepracated() {
	WinPcapSendQueue queue = WinPcap.sendQueueAlloc(512);

	WinPcap pcap = WinPcap
	    .openLive(device, snaplen, promisc, oneSecond, errbuf);

	byte[] pkt = new byte[128];
	Arrays.fill(pkt, (byte) 255);

	PcapPktHdr hdr = new PcapPktHdr(128, 128);
	queue.queue(hdr, pkt); // Packet #1
	queue.queue(hdr, pkt); // Packet #2

	Arrays.fill(pkt, (byte) 0x11);
	queue.queue(hdr, pkt); // Packet #3
	int r = pcap.sendQueueTransmit(queue, WinPcap.TRANSMIT_SYNCH_ASAP);
	if (r != queue.getLen()) {

		assertEquals("transmit() call failed [", queue.getLen(), r);
	}

	pcap.close();

	WinPcap.sendQueueDestroy(queue);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:30,代码来源:TestWinPcapExtensions.java

示例3: offlineFilter

import org.jnetpcap.PcapPktHdr; //导入依赖的package包/类
/**
 * Returns if a given filter applies to an offline packet. This function is
 * used to apply a filter to a packet that is currently in memory. This
 * process does not need to open an adapter; we need just to create the proper
 * filter (by settings parameters like the snapshot length, or the link-layer
 * type) by means of the pcap_compile_nopcap(). The current API of libpcap
 * does not allow to receive a packet and to filter the packet after it has
 * been received. However, this can be useful in case you want to filter
 * packets in the application, instead of into the receiving process. This
 * function allows you to do the job.
 * 
 * @param program
 *          bpf filter
 * @param header
 *          packets header
 * @param buf
 *          buffer containing packet data
 * @return snaplen of the packet or 0 if packet should be rejected
 * @deprecated replaced by
 *             {@link #offlineFilter(PcapBpfProgram, PcapHeader, JBuffer)}
 * @see #offlineFilter(PcapBpfProgram, PcapHeader, ByteBuffer)
 * @see #offlineFilter(PcapBpfProgram, PcapHeader, JBuffer)
 */
@Deprecated
@LibraryMember("pcap_offline_filter")
public static native int offlineFilter(PcapBpfProgram program,
		PcapPktHdr header,
		ByteBuffer buf);
 
开发者ID:pvenne,项目名称:jgoose,代码行数:29,代码来源:WinPcap.java

示例4: offlineFilter

import org.jnetpcap.PcapPktHdr; //导入依赖的package包/类
/**
 * Returns if a given filter applies to an offline packet. This function is
 * used to apply a filter to a packet that is currently in memory. This
 * process does not need to open an adapter; we need just to create the proper
 * filter (by settings parameters like the snapshot length, or the link-layer
 * type) by means of the pcap_compile_nopcap(). The current API of libpcap
 * does not allow to receive a packet and to filter the packet after it has
 * been received. However, this can be useful in case you want to filter
 * packets in the application, instead of into the receiving process. This
 * function allows you to do the job.
 * 
 * @param program
 *          bpf filter
 * @param header
 *          packets header
 * @param buf
 *          buffer containing packet data
 * @return snaplen of the packet or 0 if packet should be rejected
 * @deprecated replaced by
 *             {@link #offlineFilter(PcapBpfProgram, PcapHeader, JBuffer)}
 * @see #offlineFilter(PcapBpfProgram, PcapHeader, ByteBuffer)
 * @see #offlineFilter(PcapBpfProgram, PcapHeader, JBuffer)
 */
@Deprecated
public static native int offlineFilter(PcapBpfProgram program,
		PcapPktHdr header,
		ByteBuffer buf);
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:28,代码来源:WinPcap.java


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