From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ded6ba3fc5b87b66 X-Google-Attributes: gid103376,public From: gisle@kondor.ii.uib.no (Gisle =?iso-8859-1?Q?S=E6lensminde?=) Subject: Re: First time Ada has let me down Date: 2000/10/25 Message-ID: #1/1 X-Deja-AN: 685621158 Content-Transfer-Encoding: 8bit References: <8FD7DEBEEsynoptikdamudderfuck@news> <8t60eo$m0m$1@nnrp1.deja.com> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@uib.no X-Trace: toralf.uib.no 972473819 1856 129.177.17.63 (25 Oct 2000 11:36:59 GMT) Organization: University of Bergen Mime-Version: 1.0 User-Agent: slrn/0.9.6.2 (SunOS) NNTP-Posting-Date: 25 Oct 2000 11:36:59 GMT Newsgroups: comp.lang.ada Date: 2000-10-25T11:36:59+00:00 List-Id: In article <8t60eo$m0m$1@nnrp1.deja.com>, wv12@my-deja.com wrote: >In article <8FD7DEBEEsynoptikdamudderfuck@news>, > avlogue@home.com (Shifty) wrote: >> OK, here's the story: >> >> I had a problem at work where I needed to calculate the offset of a >> "magic number" within a buffer containing an IP datagram. >> >> The magic number is 3 protocol headers deep within the datagram, and >> all three headers are variable length. I needed to find the HLEN >> fields of the IP and TCP headers in memory. Turns out both of these >> are stored in 4 bits. The data in the other 4 bits of the octet >> belong to another field in the header. >> >the IP header length occupies the 4 LSB. Assuming p pointing to the >byte offset, >the length is just len = (*p)&0xf; Or len = P and 16#0F# in Ada95 >the TCP header length occupies the 4 MSB. the length in this case >is then ((*p)&0xf0)>>4; Or Shift_Left(P and #16#F0#, 4) in Ada 95. Or if P is represented as a packed boolean array, i.e. it's a bit-array, you can index the bits directly: P(5..8) What you writes is simply wrong. Ada95 is IMHO better than C on bit manipulation. There are more examples then those above. -- Gisle S�lensminde ( gisle@ii.uib.no ) With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. (from RFC 1925)