How to code such function, thanks for any comments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yezi

    How to code such function, thanks for any comments

    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

  • Malcolm

    #2
    Re: How to code such function, thanks for any comments


    "yezi" <ye_line@hotmai l.com> wrote[color=blue]
    >
    > 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 ?
    >[/color]
    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.


    Comment

    Working...