Need Help in Protocol Analyzer

Dec 1 2010 9:29 AM

Hi,

 

We are building a protocol analyzer. I am new to C#(has worked with C).

 

We have a byte stream which has to be parsed and filled in to multiple structures. The data comes in and upon each data only we can decide which structure and the size of it (data can be array of structures also). I am finding difficulty in coming out with the a generic  design of the structures where in I can just map the incoming bytes as is in to the structures. In C this is easy as we can use the void * and type cast it as and when required and store them in respective structures.

 

The typical data structures is like

 

Typedef struct DATA_PKT

{

intu16 choice;  //this tells which one of the below union to use !

intu16 length;

 

union

{

Data_Type_A DataA;

Data_Type_B DataB;

Data_Type_C DataC;

}

}

 

Typedef struct Data_Type_A

{

                Ver_t  version;

                Params_t param;

}

 

Typedef struct  Vert_t

{

Int Verlen;

VersData_t *versions;   //here starts versions info of length= Verlen

}

 

Typedef struct  VersData_t

{

                Int VerID;            //we have a variety of version info. This id tells which version info

                ANY_t ver;

}

 

Typedef struct ANY_t

{

                Int len;

                Char *data;

}

 

Typedef struct  Params_t

{

Int Len;                                 //total length if the structure

Int ParamCount;               // # of params present in this structure

Param_t *params

}

 

Typedef struct Param_t

{

                Int ParamID;                       //we have a variety of param info. This id tells which param info

                ANY_t param;

}

 

 

If anybody had come across similar probs please help us to resolve it. Please share any code samples if you have.

 

Appreciate your efforts to help.

 

Thanks and Regards

Abhayadev S.

[email protected]