Re: [Jnetstream-users] Error in TCP decode
Brought to you by:
voytechs
From: Frédéric D. <fre...@dr...> - 2008-08-05 18:19:39
|
Actually I will fligh back in europe tomorrow and also have to visit my chiro :-) Actually the "readBitsOneAtATime()" I posted correct something but break the TCP decoding (start offset is wrong). so I will look at it again (I find the exercise quite interessting) and I could wait some days. No problem, really. I will share my thoughts if I find something pertinent. Regards, Frederic Mark Bednarczyk a écrit : > I made changes in there recently. Its possible I screwed up. > > I hurt my back coming back from Europe yesterday and I can barely sit at the > computer right now. Hopefully tomorrow I'll feel better after my visit to > the chiropractor today and be able to take a look at the problem quickly. I > do have some jUnit test cases checked in that test various BitBuffer > conditions in the CommonUtils module. > > Cheers, > mark... > > >> -----Original Message----- >> From: jne...@li... >> [mailto:jne...@li...] On >> Behalf Of Frédéric Dreier >> Sent: Tuesday, August 05, 2008 1:10 PM >> To: Jne...@li... >> Subject: Re: [Jnetstream-users] Error in TCP decode >> >> 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 >>> >>> >> -------------------------------------------------------------- >> ----------- >> 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 >> > > > |