From 8fe8ed1942b6d7ff029a5a02e3352009d31f2ee2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 21 Mar 2013 20:34:51 +0100 Subject: Save maximum length in packet buffers --- src/packet.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/packet.h') diff --git a/src/packet.h b/src/packet.h index df22dd6..09b6dc0 100644 --- a/src/packet.h +++ b/src/packet.h @@ -43,11 +43,17 @@ struct __attribute__((packed)) gp_babel_packet { uint8_t tlv[]; }; +struct gp_babel_packet_buf { + size_t max_len; + gp_babel_packet_t packet; +}; + #define gp_babel_packet_alloca(size) ({ \ - gp_babel_packet_t *__packet = alloca(sizeof(gp_babel_packet_t)+size); \ - __packet->version = htons(GP_BABEL_VERSION); \ - __packet->len = 0; \ - __packet; \ + gp_babel_packet_buf_t *__buf = alloca(sizeof(gp_babel_packet_buf_t) + size - sizeof(gp_babel_packet_t)); \ + __buf->max_len = size - sizeof(gp_babel_packet_t); \ + __buf->packet.version = htons(GP_BABEL_VERSION); \ + __buf->packet.len = 0; \ + __buf; \ }) static inline size_t gp_babel_packet_size(const gp_babel_packet_t *packet) { -- cgit v1.2.3