Thread: maping an unsigned char ofer a structure

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    maping an unsigned char ofer a structure

    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("&#37;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
    Last edited by spank; 11-08-2007 at 07:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  2. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  3. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM
  4. ANY BODY WILLING TO HELP ME WITH Microsoft Visual C++
    By BiG pImPiN fOoL in forum C++ Programming
    Replies: 12
    Last Post: 11-04-2001, 06:03 PM