Re: Using structs as custom protocol headers

From: Derk Gwen (
Date: 04/02/03

From: Derk Gwen <>
Date: Wed, 02 Apr 2003 03:26:45 -0000

# Ok. He (the lecturer) thinks structs can be used if "youre carefull",
# i'd like to use them but if you and he say it's difficult then I'd
# probably be foolish to try.

If you're using the same compiler on the same hardware with the same options,
that would be being careful. The problem is that a C compiler will layout the
fields in the same order, but is allowed to put invisible padding bytes in the
layout as well. And different compilers, or different versions of the same
compiler can pad a structure in different ways.

# Ive done a bit of reading on endian-ness and know I have to convert
# the IP and port number, but do I have to convert all the data as
# well?

I try do it on all integers I output to a file or socket. That way I know I
can read in on any other machine.

Derk Gwen
I have no respect for people with no shopping agenda.