How to code such function, thanks for any comments

Y

yezi

HI :

The following code is
typedef struct nlpPkt
{
int source:4;
int destin:4;
unsigned int control:1;
unsigned int contype:5;
int length:10;
int checksum:16;
char nlpData[1500];
} NLPPKT; //same size

typedef struct tlpPkt
{
int sequence:7;
int ack:8;
int lenghth:10;
int blankbit:5;
int End:1;
char tlpData[1469];
} TLPPKT;

What I want to realize it to pack the whole TLPPKT into the NLPPKT
->nlpData [1500],
what confused me is the TLPPKT is a structure and includes different
type of variable.So how to put all these infor to just one char
*nlpData ?

Thanks for any comments.

bin YE
 
M

Malcolm

yezi said:
The following code is
typedef struct nlpPkt
{
int source:4;
int destin:4;
unsigned int control:1;
unsigned int contype:5;
int length:10;
int checksum:16;
char nlpData[1500];
} NLPPKT; //same size

typedef struct tlpPkt
{
int sequence:7;
int ack:8;
int lenghth:10;
int blankbit:5;
int End:1;
char tlpData[1469];
} TLPPKT;

What I want to realize it to pack the whole TLPPKT into the NLPPKT
->nlpData [1500],
what confused me is the TLPPKT is a structure and includes different
type of variable.So how to put all these infor to just one char
*nlpData ?
The cheeze way

memcpy( nlppkt.nlpData, &tlppkt, sizeof(TLPPKT));

( nlppkt and tlppkt structures)

The better way - define function to convert the bitfields, which could have
any layout in memory, to a serial sequence of unsigned chars.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top