I tried to serialize a structure field (int) to a char* buffer but I think I am doing things wrong.
This is what I am using to copy this field.
memcpy(payload + offset, &packet->payload.offset, sizeof(long int));
packet->payload.offset is a long int and contains the value '5' (hardcoded), note that:
If I print: printf("offset: %ld \n", packet->payload.offset);
I get: offset: 5
But if I print: printf("offset: %ld \n",&packet->payload.offset)
, I get: offset: 167120959
If in memcopy I remove the '&' to the second argument to write '5' to the buffer it causes Segmentation Fault, but if I don't, it copies 167120959 (which I supose it is it's address) to the buffer instead of the actual value.
Thank you very much for your help! I tried to be as descriptive as possible, hope you can help me out.