[olsr-dev] Why padding to 4 bytes in nameservice plugin?

Andreas T√łnnesen (spam-protected)
Sun Apr 9 07:49:32 CEST 2006

Hi Jens,

Here are my $0.05.

Always padding to byte boudaries is a good rule when working with C 
and communications/interfacing. Different targets CPUs will have 
different limitations
when it comes to memory access. Many processors will only allow you to 
read write
32bit values at addresses that are divisible by 4 etc. And also 
compilers on such targets
will automatically pad structures unless explicitly using "packed" et al.
So to avoid problems when interfacing between different architectures it 
is a good idea
to pad to the next 32 bit offset, generally it saves one a lot of 
trouble when working
only localy on such CPUs as well. Even on CPUs that allow access on none 
4 byte boundaries
always padding to the next bondary makes for more effective code(memory 
access) IMO.

Padding should be used in the nameservice msg simply because it is good 
style(IMO) and more important since there might be another name struct 
following any
name struct.

- Andreas

Jens Nachtigall wrote:

>Hi all,
>I am extending the nameservice plugin at the moment (more on this if it is 
>The nameservice plugin does basically send a char* name over the network, 
>however all these char *name are padded to  bytes boundaries with somethiing 
>    for (k = name->len; (k & 3) != 0; k++)
>        *pos++ = '\0';
>I wonder if this necessary? Why is it padded to 4 bytes? Unfortunately, Bruno 
>(the author of these lines) is on a world trip, so I cannot ask him. Does 
>anybody of you know?
>olsr-dev mailing list

More information about the Olsr-dev mailing list