diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-20 17:51:20 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-20 17:51:20 +0200 |
commit | 6da79ddb9bfe5e9e6042e644ff00666912b644c3 (patch) | |
tree | d59e666a0c11fa7801674eba34f6f26afc06c5a8 /src/handshake.h | |
parent | 50390abdeea337b67402107e67bfdaff3bafaa59 (diff) | |
download | fastd-6da79ddb9bfe5e9e6042e644ff00666912b644c3.tar fastd-6da79ddb9bfe5e9e6042e644ff00666912b644c3.zip |
Some handshake fixes for future protocol extensions
Extensions for arbitrary-length integers.
Diffstat (limited to 'src/handshake.h')
-rw-r--r-- | src/handshake.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/handshake.h b/src/handshake.h index 2ea7166..a77b730 100644 --- a/src/handshake.h +++ b/src/handshake.h @@ -159,3 +159,34 @@ static inline void fastd_handshake_add_uint16(fastd_buffer_t *buffer, fastd_hand dst[0] = value; dst[1] = value >> 8; } + +/** Adds an uint24 TLV record of given type and value to a handshake buffer */ +static inline void fastd_handshake_add_uint24(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) { + uint8_t *dst = fastd_handshake_extend(buffer, type, 3); + + dst[0] = value; + dst[1] = value >> 8; + dst[2] = value >> 16; +} + +/** Adds an uint32 TLV record of given type and value to a handshake buffer */ +static inline void fastd_handshake_add_uint32(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) { + uint8_t *dst = fastd_handshake_extend(buffer, type, 4); + + dst[0] = value; + dst[1] = value >> 8; + dst[2] = value >> 16; + dst[3] = value >> 24; +} + +/** Adds an TLV record of given type and value to a handshake buffer, automatically using a 1- to 4-byte value */ +static inline void fastd_handshake_add_uint(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) { + if (value > 0xffffff) + fastd_handshake_add_uint32(buffer, type, value); + if (value > 0xffff) + fastd_handshake_add_uint24(buffer, type, value); + if (value > 0xff) + fastd_handshake_add_uint16(buffer, type, value); + else + fastd_handshake_add_uint8(buffer, type, value); +} |