Subject: Re: sizeof() problem in ISO CLNP kernel driver
To: None <fr30@dial.pipex.com>
From: Ignatios Souvatzis <ignatios@cs.uni-bonn.de>
List: port-amiga
Date: 10/31/1997 13:13:33
> I have been trying to bring up Isode 8.0 using the OSI network
> layer in the NetBSD kernel (NetBSD 1.2 on an Amiga 3000). In the
> process, I have identified some bugs in the CLNP and ESIS code:
> 
> The problems relate to two structures:
> 	clnp_fixed	defined in netiso/clnp.h
> 	esis_fixed	defined in netiso/esis.h
> 
> The affected sources include
> 	netiso/clnp_er.c
> 	netiso/clnp_input.c
> 	netiso/clnp_output.c
> 	netiso/esis.c
> 
> Both structures are 9 bytes but 'sizeof()' returns a value of 10.
> The way the size is used, is to calculate offsets to the start
> of the NSAP addresses in the packet header. The extra byte then
> causes the addresses to be inserted in the wrong position in the 
> output routines and incorrectly decoded in the input routines.

I propose, as a workaround, to use gcc's __attribute__((packed)) in the
structure declaration. Can you test if it works for that problem, please?

\begin{sigh}
However, basically, the code should be rewritten.

The way this code is written is inherently non-portable; it will only
work for certain compilers, and not for others (a compiler is free to
use any padding it likes within structs, as long as it does it consistently).

When you have to access structures on disk or in hardware or on the wire,
the only portable construct is to use an array of u_int8_t, and offsets
therein, and build your multi-byte-data yourself, unfortunately. 

If you can choose the layout, you can define it in a way that all data items
are aligned to their natural size; but for network protocols we have no choice.
\end{sigh}

Regards,
	Ignatios