當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。