Thread: Header struct
View Single Post
  #11 (permalink)  
Old April 30th, 2002
tshdos tshdos is offline
Gnutella Veteran
 
Join Date: March 24th, 2002
Location: Virginia
Posts: 101
tshdos is flying high
Default

Cerebro:

If you could post the code you are having problems with we can tell you how to fix it.

Here is an example though:

struct GHEADER
{
unsigned char MsgID[16];
unsigned char FuncID;
unsigned char TTL;
unsigned char Hops;
unsigned long PayloadLen;
};

// Assume hdr is a GHEADER struct that has been filled

// Method 1
// copy from struct to buffer
char buffer[23];
memcpy( buffer, (char*)&hdr, 23 );

// Method 2
// copy struct member by member to buffer
char buffer2[23];
memcpy( &buffer[0], hdr.MsgID, 16 );
memcpy( &buffer[16], hdr.FuncID, 1 );
memcpy( &buffer[17], hdr.TTL, 1 );
memcpy( &buffer[18], hdr.Hops, 1 );
memcpy( &buffer[19], hdr.PayloadLen, 4 );
Reply With Quote