0

Main structure

typedef struct {
   uint8 u8Status;
   uint8 u8NeighborTableEntries;
   uint8 u8StartIndex;
   uint8 u8NeighborTableListCount;
   /* Rest of the message is variable length */
   ZPS_tsAplZdpDiscNtEntry* pNetworkTableList;
                                              //pNetworkTableList is a pointer to 
                                              //the first   
                                              //entry in the list of reported
                                              //Neighbour table entries
 } ZPS_tsAplZdpMgmtLqiRsp;


typedef struct
{
   uint64 u64ExtPanId;
   uint64 u64ExtendedAddress;
   uint16 u16NwkAddr;
   uint8 u8LinkQuality;
   uint8 u8Depth;
   union
   {
     struct
     {
       unsigned u2DeviceType:2;
       unsigned u2RxOnWhenIdle:2;
       unsigned u2Relationship:3;
       unsigned u1Reserved1:1;
       unsigned u2PermitJoining:2;
       unsigned u6Reserved2:6;
    } ;
    uint8 au8Field[2];
 } uAncAttrs;
} ZPS_tsAplZdpDiscNtEntry;

i have defined ZPS_tsAplZdpMgmtLqiRsp *pointer;

this seems to be okay..

pointer->u8Status
pointer->u8NeighborTableEntries
pointer->u8StartIndex
pointer->u8NeighborTableListCount

but how can i access those values inside the ZPS_tsAplZdpDiscNtEntry structure

Shantanu Banerjee
  • 1,417
  • 6
  • 31
  • 51

2 Answers2

0

you get access to the array with: pointer->pNetworkTableList so from there you can access all elements of the structure..

e.g. access to the u64ExtPanId of the the element with index 0:

pointer->pNetworkTableList[0].u64ExtPanId = 1232;
Bort
  • 2,423
  • 14
  • 22
  • if you have a stack dump, than you have not allocated memory for the structures, see Jurlies answer how to do so. – Bort Feb 02 '12 at 11:37
0

You have the pointer, but you haven't the instance of the structure itself. Do the next:

ZPS_tsAplZdpMgmtLqiRsp *pointer = (ZPS_tsAplZdpMgmtLqiRsp *)malloc(sizeof(ZPS_tsAplZdpMgmtLqiRsp));

... and yes you should allocate the memory for pNetworkTableList as well:

pointer->pNetworkTableList = (ZPS_tsAplZdpDiscNtEntry *)malloc(sizeof(ZPS_tsAplZdpDiscNtEntry));

then you may

do

 pointer->pNetworkTableList->u8Status = 12; 

and so on.

don't forget to do

free(pointer->pNetworkTableList);
free(pointer);

in the end of work.

Jurlie
  • 1,014
  • 10
  • 27
  • The return value of malloc shouldn't be cast and I would prefer calloc. – Bort Feb 02 '12 at 11:38
  • I worked in pure C many years ago. I may forget some details :-). Is void* type implicitly casted to any other in C? – Jurlie Feb 02 '12 at 11:47
  • yes, many years ago that was necessary but nowadays it isn't. it's implictly casted to the correct type, which avoids code cluttering and wrong casts. See http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc – Bort Feb 02 '12 at 11:52