You are missing the conversion of your values from network byte order to host byte order. 64000
is 11111010 00000000
in binary. You need to use the byte order conversion routines.
payloadLength = ntohs(payloadLength16b);
payloadLength = (size_t)ntohll(payloadLength64b);
If your system lacks a definition for ntohll
, you can follow the suggested answers to this question. But, a possible implementation might be:
uint64_t ntohll (uint64_t x) {
const unsigned t = 1;
if (*(const unsigned char *)&t) {
x = ((uint64_t)ntohl(x & 0xffffffffU) << 32)
| ntohl((uint32_t)(x >> 32));
}
return x;
}