當前位置: 首頁>>代碼示例>>Java>>正文


Java PcapPktHdr.getCaplen方法代碼示例

本文整理匯總了Java中org.jnetpcap.PcapPktHdr.getCaplen方法的典型用法代碼示例。如果您正苦於以下問題:Java PcapPktHdr.getCaplen方法的具體用法?Java PcapPktHdr.getCaplen怎麽用?Java PcapPktHdr.getCaplen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jnetpcap.PcapPktHdr的用法示例。


在下文中一共展示了PcapPktHdr.getCaplen方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的org.jnetpcap.PcapPktHdr.getCaplen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。