I have a problem to get databytes into my struct. I am programming in C. My received bytes looks like that:
Byte1 | Byte 2 | Byte 3| lengthData (2 Bytes) | data (variable)
My structure looks like that:
struct Packet {
unsigned char byte1[1];
unsigned char byte2[1];
unsigned char byte3[1];
unsigned char length[2];
unsigned char * data;
}*Packet
Via the read command I have the data in replay.
char * replay;
replay = (char*) malloc (MAX_DATA_LENGTH);
memset(replay, 0x00, MAX_DATA_LENGTH);
read(fd, replay, MAX_DATA_LENGTH)
Now I want to get my data bytes into the structure. Firstly I have to allocate memory for the pointer data. My question, how can I get the data with no big effort in the struct?