Re: [Jnetstream-users] Error in TCP decode
Brought to you by:
voytechs
|
From: Frédéric D. <fre...@dr...> - 2008-08-05 17:10:11
|
Hi,
I checkout the code from SVN and I thing there is something odd in the
"BitBuffer.readBitsOneAtATime()" method. Its probably about the posBits
which ich not always added to the offset.
I temporary use the following implementation until a fix is commited in
SVN (This concats the buffer byte per byte instead bit per bit)
Regards,
Frédéric
private static final int[] RIGHT_BIT_MASK = new int[32];
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;
}
Frédéric Dreier a écrit :
> Hi,
>
> I have some trouble decoding IP and TCP headers. the header length and
> the offset are wrongly decoded in most of the packets.
>
> Did I do something wrong?
>
> Regards,
> Frederic Dreier
>
>
>
> Console output -------------------------------
> PACKET DUMP::
> 00 12 3F 19 FC 3F 00 07
> 84 BC A0 C0 08 00 45 00
> 00 28 9D 7A 40 00 2B 06
> 25 94 D0 50 98 03 81 AD
> A2 C0 00 50 D7 59 29 F4
> BC EF 33 C8 F3 C5 50 11
> Vers : 4
> Hlen : 4 <----- should be 5
> TOS : 0
> Lgt : 40
> ident: 40314
> flags: 2
> offs : 1 <---- should be 0
> TTL : 43
> Prot : 6
> Src : 208.80.152.3
> Dst : 129.173.162.192
> Console output -------------------------------
>
>
>
> Code snipet ------------------------------
> Ip4 ipHd = packet.getHeader(Ip4.class);
> Tcp tcpHd = packet.getHeader(Tcp.class);
> System.out.println("PACKET DUMP::");
> for (int i = 0; i < 6; i++) {
> for (int k = i * 8; k < ((i + 1) * 8);
> k++) {
> System.out.printf("%02X ",
> packet.getBuffer().getBackingBuffer().get(k) & 0xFF);
> }
> System.out.println();
> }
> System.out.printf("Vers : %d\n", ipHd.ver());
> System.out.printf("Hlen : %d\n", ipHd.hlen());
> System.out.printf("TOS : %d\n", ipHd.tos());
> System.out.printf("Lgt : %d\n", ipHd.length());
> System.out.printf("ident: %d\n",
> ipHd.id()&0xFFFF);
> System.out.printf("flags: %d\n", ipHd.flags());
> System.out.printf("offs : %d\n", ipHd.offset());
> System.out.printf("TTL : %d\n", ipHd.ttl());
> System.out.printf("Prot : %d\n",
> ipHd.protocol());
> System.out.printf("Src : %s\n", ipHd.source());
> System.out.printf("Dst : %s\n",
> ipHd.destination());
> --------------------------------------------
>
> -------------------------------------------------------------------------
> 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
>
|