networking · intermediate · ~15 min
Read the TLS record type byte.
A TLS record header is type(1) + version(2) + length(2). The first byte is the content type (22 = handshake, 23 = application data). Read it.
Implement int tls_record_type(const unsigned char *rec) that returns the record's content type byte, rec[0].
A pointer rec to the TLS record bytes (at least 1 byte).
Returns the content type byte rec[0].
{22, 0x03,0x03, 0x00,0x05} -> 22 (handshake)
{23, 0x03,0x03, 0x01,0x00} -> 23 (application data)
A pointer rec to the TLS record bytes (at least 1 byte).
The content type byte rec[0].
The content type is the first byte of the record.
int tls_record_type(const unsigned char *rec) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.