Aligning for boundary conditions

Hi,

I have tcp/ip client server programs which will communicate through reqest,reply c-structures.

As the sizeof(struct) may give different value between client and server programs, how do i align properly for boundary conditions.

Could anybody please give some suggestion.

Thanks in advance.

You could use the packed attribute, which basically means you'll mandate that all fields are next to each other with no gaps.

Don't forget to specify (i) a byte order and (ii) the width of each field.

As the sizeof(struct) may give different value between client and server programs, how do i align properly for boundary conditions.

You cannot unless the application is only used on platforms with exactly the same programming model i.e. LP64, IPL32, LP16, etc. You need to select a data interchange format and then encode or decode to that format.

Thanks JohnGraham and fpmurphy

Actually, both the client and server programs are running on solaris SPARC arch and I'm doing:

client side: write(fd,req_structure,sizeof(req_structure));
server side: read(fd,req_structure,sizeof(req_structure));

Do I really need to worry about the data exchange format?

Because one of my friend told me to ALIGN the structure on 1K boundary on server program. Because if the structure starts at odd address, read may fail on some systems. Could you please clarify...