On Sun, Oct 07, 2012 at 06:13:35PM -0500, Bob Tanner wrote:
> On 2012-09-19 17:23:24 +0000, Bob Tanner said:
> 
> >  SP_YOU, indicates slot number assigned
> 
> Just want to double check some things.
> 
> On osx (10.8) the "struct you_spacket" is 48 bytes.
> 
> struct you_spacket
> {
>    char    type;                                /* SP_YOU */
>    char    pnum;                                /* Guy needs to know this...
>    char    hostile;
>    char    swar;
>    char    armies;
>    char    tractor;
>    char    pad2;
>    char    pad3;
>    unsigned flags;
>    LONG    damage;
>    LONG    shield;
>    LONG    fuel;
>    unsigned short etemp;
>    unsigned short wtemp;
>    unsigned short whydead;
>    unsigned short whodead;
> };

48 bytes is wrong.  32 bytes is right.  Your compiler might be
aligning the structure members for performance.  Give a suitable
alignment directive to your compiler.  We use __attribute__((packed))
in the server code.  Check the offset to each member using whatever
language facilities are available.  In C we can use sizeof() and
offsetof().

> 
> Packet dump after the MOTD stuff looks like this for me.
> 
> 0c100000 00000000 08000000 00000000 00000000 00000000 00000000
> 00000000 18000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 16000000 02000000 03000000 00000000 14000000 12000000 00000000
> 04000000 00000000 00000000 18010000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 16010000 02010000 03010000 00000000 14010000
> 12010000 00000000

Looks correct, there are 32 bytes of SP_YOU in this dump.

> 
> Byte 0x0c (12) is SP_YOU
> 
> #define SP_YOU          12                       /* info on you? */
> 
> The next 48 bytes should fill in the "struct you_spacket" but that
> leaves 2 nybles of null bytes before the byte 0x18 (24) SP_PL_LOGIN
> is seen
> 
> #define SP_PL_LOGIN     24                       /* new player logs in */
> 
> In my code I replaced the (I assume) autoconf figured out LONG with
> long is that right?

Um, sure, if your compiler agrees with mine and uses four bytes or
32-bits for it.  It isn't a long long.

> 
> I'd look at MacTrek but that's a 32-bit project and I'm attempting
> to write my stuff as a 64-bit project.
> 
> Why I'm confused is the MacTrek project has the SP_YOU structure at
> 32 bytes, which would even leave more null bytes.

I think you miscounted on the dump.  There are only 7 columns to it.

> 
> Just trying to figure out why I'm ending up 2 nybles short.
> 
> Thanks.
> 
> -- 
> Bob Tanner <basic at us.netrek.org>          Key fingerprint = 9906
> 320A 8BB6 64AD 96A7  7785 CBFB 10BF 568B F98C
> 
> 
> _______________________________________________
> netrek-dev mailing list
> netrek-dev at us.netrek.org
> http://mailman.us.netrek.org/mailman/listinfo/netrek-dev
> 

Also, check against the Gytha format string for the packet, and
against this table:

http://docs.python.org/library/struct.html#format-characters

It tends to be more precise than the C structure definitions, since C
structs have long since stopped being portable for network packets.  ;-)

-- 
James Cameron
http://quozl.linux.org.au/