summaryrefslogtreecommitdiffstats
path: root/src/handshake.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 22:18:22 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 22:18:22 +0200
commit14d6915f098c6d51a6e879b81f70d9b9dba0b867 (patch)
tree8f5aa91f201016b187e480d5a3e68bf586181a96 /src/handshake.h
parent9be0a607eb2e452958e4128803ace2e3aaad19cc (diff)
downloadfastd-14d6915f098c6d51a6e879b81f70d9b9dba0b867.tar
fastd-14d6915f098c6d51a6e879b81f70d9b9dba0b867.zip
Use 2 bytes to encode handshake field types and lengths; breaks compatiblity with v0.1-rc2 and earlier
Diffstat (limited to 'src/handshake.h')
-rw-r--r--src/handshake.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/handshake.h b/src/handshake.h
index c59d141..d540de0 100644
--- a/src/handshake.h
+++ b/src/handshake.h
@@ -72,29 +72,33 @@ void fastd_handshake_handle(fastd_context *ctx, fastd_peer *peer, fastd_buffer b
static inline void fastd_handshake_add(fastd_context *ctx, fastd_buffer *buffer, fastd_handshake_record_type type, size_t len, const void *data) {
- if ((uint8_t*)buffer->data + buffer->len + 2 + len > (uint8_t*)buffer->base + buffer->base_len)
+ if ((uint8_t*)buffer->data + buffer->len + 4 + len > (uint8_t*)buffer->base + buffer->base_len)
exit_bug(ctx, "not enough buffer allocated for handshake");
uint8_t *dst = (uint8_t*)buffer->data + buffer->len;
dst[0] = type;
- dst[1] = len;
- memcpy(dst+2, data, len);
+ dst[1] = type >> 8;
+ dst[2] = len;
+ dst[3] = len >> 8;
+ memcpy(dst+4, data, len);
- buffer->len += 2 + len;
+ buffer->len += 4 + len;
}
static inline void fastd_handshake_add_uint8(fastd_context *ctx, fastd_buffer *buffer, fastd_handshake_record_type type, uint8_t value) {
- if ((uint8_t*)buffer->data + buffer->len + 3 > (uint8_t*)buffer->base + buffer->base_len)
+ if ((uint8_t*)buffer->data + buffer->len + 5 > (uint8_t*)buffer->base + buffer->base_len)
exit_bug(ctx, "not enough buffer allocated for handshake");
uint8_t *dst = (uint8_t*)buffer->data + buffer->len;
dst[0] = type;
- dst[1] = 1;
- dst[2] = value;
+ dst[1] = type >> 8;
+ dst[2] = 1;
+ dst[3] = 0;
+ dst[4] = value;
- buffer->len += 3;
+ buffer->len += 5;
}