I need to two byte message length indicator at the beginning of a message I'm sending to a server. The message length will be an unsigned short in network byte order.
The following is how I plan on doing it:
snprintf(pBuffer, sizeofbuffer, "%u", htons(sizeof(ReqMsgTemp)));
RegMsgTemp is the message I'm sending to the server. pBuffer will be prepended to ReqMsgTemp.
Is this the right way of doing it?