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, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ded6ba3fc5b87b66 X-Google-Attributes: gid103376,public From: wv12@my-deja.com Subject: Re: First time Ada has let me down Date: 2000/10/25 Message-ID: <8t60eo$m0m$1@nnrp1.deja.com>#1/1 X-Deja-AN: 685545597 References: <8FD7DEBEEsynoptikdamudderfuck@news> X-Http-Proxy: 1.1 x62.deja.com:80 (Squid/1.1.22) for client 199.173.190.106 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Oct 25 07:00:42 2000 GMT X-MyDeja-Info: XMYDJUIDwv12 Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt) Date: 2000-10-25T00:00:00+00:00 List-Id: 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; the TCP header length occupies the 4 MSB. the length in this case is then ((*p)&0xf0)>>4; Things just have to be easy in C, don't they. No wonder 99.99% of the IP stacks in the world are in C and not Ada. Sent via Deja.com http://www.deja.com/ Before you buy.