Re: [Jnetstream-users] Error in TCP decode
Brought to you by:
voytechs
|
From: Mark B. <voy...@ya...> - 2008-08-06 16:21:20
|
Thanks Frederic,
I'm still out of commission myself.
I will revist the BitBuffer as that is a core routine that has to be 100%
correct all the time under all circumstances.
Cheers,
mark...
----- Original Message -----
From: "Frédéric Dreier" <fre...@dr...>
Cc: <Jne...@li...>
Sent: Wednesday, August 06, 2008 4:31 PM
Subject: Re: [Jnetstream-users] Error in TCP decode
Good morning Mark,
I will be unreachable until next monday so I already send you what I found.
- my implementation of readBitsOneAtATime(). Perhaps it is not so good
but it just does the trick until the original one will be fixed.
- something in FastScanner didn't work after I changed
readBitsOneAtATime(). 32 kept to be added to the ip header length.
Regards,
Frédéric
Fast Scanner ---------------------------------
/**
*
*/
public final boolean scanIp4() {
addToCache(IP4);
r1 = readUByte(Ip4.StaticField.PROTOCOL);
if (DEBUG) {
logger.debug(String.format("Ip4 p=%d, r1=%d\n", offset, r1));
}
//offset += bits.getBits(offset + 4, 4) * 4 * 8 + 32; <<== why +32 ?
offset += bits.getBits(offset + 4, 4) * 32;
switch (r1) {
case 1:
return scanIcmp();
case 6:
return scanTcp();
case 17:
return scanUdp();
}
return true;
}
BitBuffer -------------------------------------
private static final int[] RIGHT_BIT_MASK = new int[33];
static {
// initialize mask used by readBitsOneAtATime()
for (int i = 1; i < RIGHT_BIT_MASK.length; i++) {
RIGHT_BIT_MASK[i] = (RIGHT_BIT_MASK[i - 1] << 1) | 1;
}
}
private int readBitsOneAtATime(int length) {
// basic checks to avoid unnecessary computation
if (length == 0) {
return 0;
}
if (length > 32) {
throw new IndexOutOfBoundsException("0 >= range <= 32bits");
}
// value is stored in long since length+posBits
// could be greater than 32.
long value = current;
int acc = 8 - posBits;
// concatenate buffer byte per byte
for (; acc < length; acc += 8) {
// fetch next byte
posBits = 8;
fetch();
// append new current byte
value = (value << 8) | (current & 0xFF);
}
// right-align the bits and mask high bits
value = (value >> (acc - length)) & RIGHT_BIT_MASK[length];
// update posBits value
posBits = (posBits + length) % 8;
// return
return (int) value;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jnetstream-users mailing list
Jne...@li...
https://lists.sourceforge.net/lists/listinfo/jnetstream-users
|