I want to pass structure over a socket in C. I read about it here:
Passing a structure through Sockets in C
but mine problem is that I have inside of a structure array of integers, and I don't know how can I serialize and deserialize it, any advice?
struct packet{
int id;
char buffer[512];
int array[4];
}
Serialize function , it is working but array of integers is missing
size_t encode_pack(packet pack, char *buf){
size_t pack_len;
unsigned char *pt = buf;
*pt++ = (pack.id >> 24) & 255 ;
*pt++ = (pack.id >> 16)& 255;
*pt++ = (pack.id >> 8) & 255;
*pt++ = (pack.id & 255);
strcpy(pt,pack.buffer);
pt += strlen(pack.buffer)+1;
pack_len = sizeof(pack.id) + strlen(pack.buffer);
return pack_len;
}