So far in my application, I was only sending keep-alive packets and small replies. Now, I want to include my big frames which consist of a packet header and the payload. What I do is simply:
// Get the packet header.
memset(&rxPacketHeader, 0, sizeof(rxPacketHeader));
nbByteReceived = netbuf_copy(_pIncomingNetBuffer, (void*)&rxPacketHeader, sizeof(rxPacketHeader));
Then, I verify the checksum and everything and the header contains the payload type and size. So using this information, I can do another netbuf_copy to get the payload:
// Get the payload data.
memset(&rxInitPacket, 0, sizeof(rxInitPacket));
nbByteReceived = netbuf_copy(_pIncomingNetBuffer, (void*)&rxInitPacket, sizeof(rxInitPacket));
I found out that my payload was corrupted, well that's what I thought. But then, I figured that doing this second netbuf_copy was actually not giving me only the payload, but also the header packet again. I was under the assumption that netbuf_copy() was flushing the bytes upon reading, like in serial communication or streaming.
My questions are:
- Is there a way or option to make the IP stack flush the data when read?
- Should I use something else that netbuf_copy() ?
- Is there a known trick to offset the netbuf_copy()?
Thanks again!
DT