本文整理汇总了Java中org.jnetpcap.nio.JBuffer类的典型用法代码示例。如果您正苦于以下问题:Java JBuffer类的具体用法?Java JBuffer怎么用?Java JBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JBuffer类属于org.jnetpcap.nio包,在下文中一共展示了JBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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());
}
}
示例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;
}
示例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());
}
示例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);
}
示例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);
}
示例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");
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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 = "";
}
示例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);
}
}