networking · intermediate · ~15 min
Read the big-endian record length.
After the content type and 2-byte version, a TLS record header carries a big-endian 16-bit length at offset 3. It tells you how many bytes of record body follow the header. Read it.
Implement int tls_record_length(const unsigned char *rec) that returns the big-endian length, (rec[3] << 8) | rec[4].
A pointer rec to the TLS record bytes (at least 5 bytes).
Returns the 16-bit record length.
{22, 0x03,0x03, 0x00,0x05} -> 5
{23, 0x03,0x03, 0x01,0x2C} -> 300
A pointer rec to the TLS record bytes (at least 5 bytes).
The 16-bit record length (rec[3] << 8) | rec[4].
The length is a big-endian u16 at offset 3.
int tls_record_length(const unsigned char *rec) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.