I am trying to use the first bit of an unsigned int as a flag if the client as server should re-key for their encryption keys. I would like to use the rest of the unsigned int as the length for the remaining data that is being sent.
Currently I am trying this but it doesn't seem to work.
unsigned int payloadLength;
read(sock, &payloadLength, sizeof(payloadLength));
short bit = (payloadLength >> 0) & 1U; // get first bit
payloadLength &= 1UL << 0; // set first bit to 0
payloadLength = ntohl(payloadLength);
if (bit == 1)
//rekey
else
//read more data
The rekey flag seems to be set right, but when trying to get the length it always ends up as the wrong number.
Aucun commentaire:
Enregistrer un commentaire