Ethereal-dev: Re: [Ethereal-dev] Van Jacobson dissector.

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Gilbert Ramirez <gram@xxxxxxxxxxxxxxx>
Date: Wed, 19 Dec 2001 15:53:24 -0600
On Tue, 18 Dec 2001 15:01:48 Irfan Khan wrote:
> 

> 
> /* IP and TCP header types */
> typedef struct {
> #if BYTE_ORDER == LITTLE_ENDIAN 
>   guint8  ihl:4,
>           version:4;
> #else 
>   guint8  version:4,
>           ihl:4;
> #endif

You should stay away from using bitfields like this
in portable code. ANSI says that only unsigned ints can
hold bitfields. GCC accepts the above, but not all
compilers do (e.g., IBM's C compiler).
Look at the code in packet-ip.c to see what we did
to make this portable.


>   /* Copy header and form tvb */
>   hdr_len  = ((iphdr_type *)hdr_buf)->ihl * 4;
>   hdr_len += ((tcphdr_type *)(hdr_buf + hdr_len))->doff * 4;

We just had an issue with this type of struct-casting
in tcp_graph.c. We stay away from this. Because hdr_buf is
being allocated from a GMemChunk, it might be aligned
properly for what you're doing. Any opinions on this?

> 
>   /* Store the reconstructed header in frame data area */
>   buf_hdr = g_mem_chunk_alloc(vj_header_memchunk);

I don't see a g_mem_chunk_free() call for the buf_hdr's that
are allocated.

--gilbert