My problem is the following. I have an unsigned char array packet[] and the following structures:
Code:
typedef struct set_serv_prop_s
{
byte serviceType;
union
{
heartbeatCommand_t *heartbeatCommand;
announcement_t *announcement;
} set_serv_propType;
} set_serv_prop_t;
typedef struct announcement_s
{
union
{
announAllocCommand_t *announAllocCommand;
announAllocResponse_t *announAllocResponse;
announDownloadCommand_t *announDownloadCommand;
announRemCommand_t *announRemCommand;
announRemResponse_t *announRemResponse;
announMarkRemCommand_t *announMarkRemCommand;
announDownAbortCommand_t *announDownAbortCommand;
} announcementType;
} announcement_t;
typedef struct announAllocCommand_s
{
byte encodingLaw;
uint16 reserved;
uint32 announcementSize;
} announAllocCommand_t;
the service type field tells what king of package it is.
i try to map it:
Code:
void read_set_serv_prop_from_pkt(set_serv_prop_t **head,
unsigned char* packet)
{
int i;
*head = (set_serv_prop_t*) packet.payload;
for(i=0;i<packet.size;i++)
printf("%x ",packet.payload[i]);
printf("\n");
if((*head)->serviceType==0x05)
{
announAllocCommand_t *allocCommand = (*head)->set_serv_propType.announcement->announcementType.announAllocCommand;
fprintf(OUTPUT, "\t%d\n",allocCommand->encodingLaw);
fprintf(OUTPUT, "\t%d\n",allocCommand->reserved);
fprintf(OUTPUT, "\t%d\n\n", allocCommand->announcementSize);
}
}
and i get the output:
Code:
5 0 0 0 0 0 fa 0
49
12846
-2147446592
5 - Service Type
0 - Encoding law
0 0 - Reserved
0 0 fa 0 -Announcement size
the output is totally wrong. What is the problem here? and how can I solve it ?
Please help... I'm very pressed by time