By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,484 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,484 IT Pros & Developers. It's quick & easy.

How to code such function, thanks for any comments

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"yezi" <ye*****@hotmail.com> wrote

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.
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.