• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: doInBackground

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
protected Integer doInBackground(Void...params){

			JBufferHandler<IntHolder> bufferHandler = new JBufferHandler<IntHolder>() {  
	            public void nextPacket(PcapHeader header, JBuffer buffer, IntHolder length){
	            	++length.value;
	            }
			};
			
			int expectedValue=0;
			while (true){
				if (isCancelled()){
					return -1;
				}
				if (length.value!=expectedValue){
					return 0;
				}
				pcap.loop(blockLength.value, bufferHandler,length);
				expectedValue+=blockLength.value;
				publishProgress(0);
			}
		}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:22,代码来源:PcapFileLoader.java


示例2: headerLength

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Header length.
 * 
 * @param buffer
 *          the buffer
 * @param offset
 *          the offset
 * @return the int
 */
@HeaderLength
public static int headerLength(JBuffer buffer, int offset) {
	int flags = buffer.getUShort(0);
	int len = 6;
	if ((flags & FLAG_L) != 0) {
		len += 2;
	}

	if ((flags & FLAG_S) != 0) {
		len += 4;
	}

	if ((flags & FLAG_O) != 0) {
		len += 4;
	}

	return len;
}
 
开发者ID:universsky,项目名称:diddler,代码行数:28,代码来源:L2TP.java


示例3: nextPacket

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
public void nextPacket(PcapHeader pcapHdr, JBuffer jbuf, String user) {

		packet.peerHeaderAndData(pcapHdr, jbuf);
		scanner.scan(packet, Ethernet.ID);

		assertTrue(packet.getPacketWirelen() > 0);

		System.out.printf("JHandlerTest::nextPacket() - %s\n", packet.getState()
		    .toDebugString());

		if (packet.hasHeader(ethernet)) {
			System.out.println("ethernet.dst=" + ethernet.destination());
		}

		if (packet.hasHeader(ip4)) {
			System.out.println("ip4.ver=" + ip4.version());
		}

		if (packet.hasHeader(ip6)) {
			System.out.println("ip4.ver=" + ip4.version());
		}
	}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:23,代码来源:JHandlerTest.java


示例4: headerLength

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Header length.
 * 
 * @param buffer
 *          the buffer
 * @param offset
 *          the offset
 * @return the int
 */
@HeaderLength
public static int headerLength(JBuffer buffer, int offset) {

	/*
	 * Since we could be reading from a TCP segment that does not contain a
	 * message header, we check the first character if atleast its a valid
	 * character for any of the possible values. The first line defines a
	 * consise set of chars.
	 */
	if (checkValidFirstChars(buffer, offset) == false) {
		return 0;
	}

	/*
	 * We need to scan the buffer for an empty new line which identifies the end
	 * of the header that would the 2 sets of '\n' '\r' characters.
	 */
	int len = buffer.findUTF8String(offset, HEADER_DELIMITER);

	return len;
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:31,代码来源:AbstractMessageHeader.java


示例5: test1

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
	 * Test1.
	 */
	public void test1() {
		
		JMemoryPacket packet = new JMemoryPacket(64);
		packet.order(ByteOrder.BIG_ENDIAN);
		packet.setUShort(0 + 12, 0x800);
		packet.setUByte(14 + 0, 0x45);
		System.out.println(packet.toHexdump());
		packet.setUByte(14 + 9, 0x11); //UDP
		System.out.println(packet.toHexdump());
		packet.scan(JProtocol.ETHERNET_ID);
		Ethernet eth = packet.getHeader(new Ethernet());
		Ip4 ip = packet.getHeader(new Ip4());
		Udp udp = packet.getHeader(new Udp());
//		udp.transferFrom(getFakeData(1460)); //Generate Random bytes
		eth.destination(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 33});
		eth.source(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 34});
		ip.flags(0);
		ip.tos(0);
		ip.source(new byte[] {(byte) 192, (byte) 168, 18, (byte) 218});
		ip.setByteArray(16, new byte[] {(byte) 192,(byte) 168, 18, (byte) 219});
		
		ip.checksum(0);
		System.out.printf("crc=0x%X ip.len=%d\n", Checksum.inChecksum(ip, 0, ip.size()), ip.size());
		ip.checksum(Checksum.inChecksum(ip, 0, ip.size()));
		System.out.println(packet.getState().toDebugString());
		
		System.out.printf("crc=0x%X\n", Checksum.inChecksum(ip, 0, ip.size()));
		
		JBuffer b = new JBuffer(4);
		
		b.order(ByteOrder.LITTLE_ENDIAN);
		b.setUInt(0, 0x14010100);	
		System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
		
		b.order(ByteOrder.BIG_ENDIAN);
		b.setUInt(0, 0x14010100);	
		System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
	}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:42,代码来源:Bug2878768_jmemory_packet_int.java


示例6: TCPPacket

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
public TCPPacket(PcapPacket packet) {
    packetTime = Instant.now();
    Ip4 ip4 = packet.getHeader(new Ip4());
    Tcp tcp = packet.getHeader(new Tcp());
    connectionInfo = new TCPConnectionInfo(ip4.sourceToInt(), tcp.source(), ip4.destinationToInt(), tcp.destination());
    seqNumber = tcp.seq();
    ackNumber = tcp.ack();
    tcpFlags = tcp.flags();
    JBuffer storage = new JBuffer(JMemory.Type.POINTER);
    JBuffer packetPayload = tcp.peerPayloadTo(storage);
    payload = new byte[packetPayload.size()];
    packetPayload.getByteArray(0, payload);
}
 
开发者ID:vincentzhang96,项目名称:HearthCaptureLib,代码行数:14,代码来源:TCPPacket.java


示例7: WinPcapSendQueue

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Creates a sendqueue by allocating a buffer to hold the supplied data. The
 * data array is copied into the buffer.
 * 
 * @param data
 *          data to be copied into the queue
 */
public WinPcapSendQueue(byte[] data) {
	super(STRUCT_NAME, sizeof());

	this.buffer = new JBuffer(data.length);
	this.buffer.order(ByteOrder.nativeOrder()); // Force byte ordering

	this.buffer.setByteArray(0, data);
	setMaxLen(data.length);
	setLen(data.length);
}
 
开发者ID:universsky,项目名称:diddler,代码行数:18,代码来源:WinPcapSendQueue.java


示例8: checkSignature

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Check signature.
 * 
 * @param method
 *          the method
 */
private static void checkSignature(Method method) {

	Class<?> declaringClass = method.getDeclaringClass();

	if (method.isAnnotationPresent(HeaderLength.class) == false) {
		throw new AnnotatedMethodException(declaringClass,
		    "@HeaderLength annotation missing for " + method.getName() + "()");
	}

	/*
	 * Now make sure it has the right signature of: <code>static int
	 * name(JBuffer, int)</code.
	 */
	Class<?>[] t = method.getParameterTypes();
	if (t.length != 2 || t[0] != JBuffer.class || t[1] != int.class
	    || method.getReturnType() != int.class) {

		throw new AnnotatedMethodException(declaringClass,
		    "Invalid signature for " + method.getName() + "()");
	}

	if ((method.getModifiers() & Modifier.STATIC) == 0) {
		throw new AnnotatedMethodException(declaringClass, method.getName()
		    + "()" + " must be declared static");

	}
}
 
开发者ID:universsky,项目名称:diddler,代码行数:34,代码来源:AnnotatedHeaderLengthMethod.java


示例9: readChunk

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Reads and setups chunk objects
 * 
 * @param offset
 *            start of this chunk with the packet
 * @param chunk
 *            a chunk object that will be initialized to point to chunk data
 *            within buffer
 * @return length of this chunk in bytes
 */
private int readChunk(JBuffer buffer, int start, RtcpSDESChunk chunk) {
	int chunkLength = 4;

	chunk.list.clear(); // Our setup storage

	int offset = start + 4;
	for (int i = 0; i < 255; i++) {
		int itemType = RtcpSDESItem.readType(buffer, offset);
		int itemLen = RtcpSDESItem.readLength(buffer, offset);
		chunk.list.add(new RtcpSDESItem(buffer, offset, itemLen + 2));

		chunkLength += itemLen + 2;
		offset += itemLen + 2;

		if (itemType == 0) {

			chunkLength = pad4(chunkLength);
			offset = pad4(offset);
			break;
		}
	}

	chunk.setCount(chunk.list.size());
	chunk.peer(buffer, start, chunkLength);

	return chunkLength;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:38,代码来源:RtcpSDES.java


示例10: headerLength

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Determines the length of the header in octets. The value is calculated by
 * adding to the length of the static part of the header the length of the
 * CSRC table. The CC field contains number of 32-bit entries within the
 * table.
 * 
 * @param buffer
 *          buffer containing the header data
 * @param offset
 *          offset within the buffer of the start of the header
 * @return length of the header in bytes
 */

@HeaderLength
public static int headerLength(final JBuffer buffer, final int offset) {
	final int rtpBaseHeader = baseHeaderLength(buffer, offset);

	if ((buffer.getByte(offset) & EXTENSION_MASK) > 0) {
		return rtpBaseHeader
				+ Rtp.Extension.headerLength(buffer, offset + rtpBaseHeader);
	} else {
		return rtpBaseHeader;
	}
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:25,代码来源:Rtp.java


示例11: headerLength

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Header length.
 * 
 * @param buffer
 *          the buffer
 * @param offset
 *          the offset
 * @return the int
 */
@HeaderLength
public static int headerLength(JBuffer buffer, int offset) {
	switch (buffer.getUByte(offset)) {
	case 0: // EchoReply
	case 8: // EchoRequest
		return buffer.size() - offset - 4;

	case 4: // SourceQuench
	case 5: // Redirect
	case 11: // Timestamp
	default:
		return 4;
	}
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:24,代码来源:Icmp.java


示例12: transferStateAndDataTo

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Deep copy of the this packet to the supplied packet. Contents of the this
 * packet such as pcap header, packet state and packet data are deep copied
 * into the suppliedpacket, allocating memory if necessary or existing memory
 * buffer if it is large enough to hold the new packet with its complete
 * state. In either case, the packet will be stored with its header and state
 * in a single contigues buffer in the supplied packet.
 * 
 * @param packet
 *          destination packet to which to copy header, state and packet data
 * @return number of bytes copied
 */
public int transferStateAndDataTo(PcapPacket packet) {
	JBuffer buffer = packet.getMemoryBuffer(this.getTotalSize());

	int o = header.transferTo(buffer, 0);
	packet.header.peerTo(buffer, 0);

	packet.state.peerTo(buffer, o, state.size());
	o += state.transferTo(packet.state);

	packet.peer(buffer, o, size());
	o += this.transferTo(buffer, 0, size(), o);

	return o;
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:27,代码来源:PcapPacket.java


示例13: headerLength

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Header length.
 * 
 * @param buffer
 *          the buffer
 * @param offset
 *          the offset
 * @return the int
 */
@HeaderLength
public static int headerLength(JBuffer buffer, int offset) {
	switch (buffer.getUByte(offset)) {
		case 0: // EchoReply
		case 8: // EchoRequest
			return buffer.size() - offset - 4;

		case 4: // SourceQuench
		case 5: // Redirect
		case 11: // Timestamp
		default:
			return 4;
	}
}
 
开发者ID:universsky,项目名称:diddler,代码行数:24,代码来源:Icmp.java


示例14: TLV

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
public TLV(JBuffer buffer, int offset, int length) {
	super(Type.POINTER);

	this.peer(buffer, offset, length);
	this.order(ByteOrder.BIG_ENDIAN);
	this.label = "";
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:8,代码来源:SctpInitBaseclass.java


示例15: decodeData

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
public void decodeData(JBuffer payload)
{
	int currentBuffPosition = 0;
	
	// We walk through the payload to decode each data entry
	for (int currentEntry = 0; currentEntry < numEntries; currentEntry++)
	{
		// We decode the current data entry
		this.data[currentEntry].decode(payload, currentBuffPosition);
		
		currentBuffPosition++;
		// We read the current data entry length
		currentBuffPosition += (payload.getByte(currentBuffPosition) +1);		
	}
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:16,代码来源:IEC61850_GOOSE_Data.java


示例16: transferPayloadTo

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Copies into the user supplied buffer, the payload data portion of the
 * packet right after the current header.
 * 
 * @param buffer
 *          buffer to copy the data to
 * @return the same buffer that was passed in
 */
public JBuffer transferPayloadTo(JBuffer buffer) {
	final JPacket packet = getPacket();
	final int offset = getOffset() + size();

	packet.transferTo(buffer, offset, packet.remaining(offset), 0);

	return buffer;
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:17,代码来源:JHeader.java


示例17: run

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
public void run() {
    while ( !(Thread.interrupted() && please_stop)) 
    {          	
        // check if jnetpcap has a packet for us
        int res;
        synchronized (pcapLock) {
            if (pcap == null) {
                return;
            }
            res = pcap.nextEx(pcapPacket);
        }
        if (res == Pcap.NEXT_EX_OK) {
            received++;

            PcapPacket pcapPacketCopy = new PcapPacket(pcapPacket); // deep copy
            pcapPacketCopy.scan(JProtocol.ETHERNET_ID); // parse the headers

            ingress(pcapPacketCopy);
        }

        // flush the egress queue
        while (!egressPackets.isEmpty()) {
            JBuffer packet = egressPackets.poll();

            synchronized (pcapLock) {
                if (pcap == null) {
                    return;
                }
                pcap.sendPacket(packet);
            }

            sent++;
        }
    }
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:36,代码来源:PcapPort.java


示例18: append

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Append.
 * 
 * @param header
 *          the header
 * @param packet
 *          the packet
 */
public void append(PcapHeader header, JBuffer packet) {
	header.transferTo(this, position);
	position += header.sizeof();

	packet.transferTo(this, 0, packet.size(), position);
	position += packet.size();

	count++;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:18,代码来源:JPcapRecordBuffer.java


示例19: testDumpLongIntIntJBuffer

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Test method for {@link org.jnetpcap.PcapDumper#dump(long, int, int, org.jnetpcap.nio.JBuffer)}.
 */
@Test
public void testDumpLongIntIntJBuffer() {
	JBuffer buffer = new JBuffer(data);
	
	dumper.dump(seconds, useconds, wirelen, buffer);
	
	checkFileSize();
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:12,代码来源:TestPcapDumper.java


示例20: peerPayloadTo

import org.jnetpcap.nio.JBuffer; //导入依赖的package包/类
/**
 * Peers, without copy, the user supplied buffer with payload data portion of
 * the packet right after the current header.
 * 
 * @param buffer
 *          buffer to peer the data with
 * @return the same buffer that was passed in
 */
public JBuffer peerPayloadTo(JBuffer buffer) {
	final JPacket packet = getPacket();
	final int offset = getOffset() + size();

	buffer.peer(packet, offset, packet.remaining(offset));

	return buffer;
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:17,代码来源:JHeader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TestEvent类代码示例发布时间:2022-05-22
下一篇:
Java ByteIntConvert类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap