Add alloca_packet() macro
This commit is contained in:
parent
de428f0b8f
commit
e099bddc24
2 changed files with 10 additions and 6 deletions
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
|
@ -41,6 +43,13 @@ struct __attribute__((packed)) gp_babel_packet {
|
|||
uint8_t tlv[];
|
||||
};
|
||||
|
||||
#define alloca_packet(size) ({ \
|
||||
gp_babel_packet_t *__packet = alloca(sizeof(gp_babel_packet_t)+size); \
|
||||
__packet->version = htons(GP_BABEL_VERSION); \
|
||||
__packet->len = 0; \
|
||||
__packet; \
|
||||
})
|
||||
|
||||
static inline size_t gp_babel_packet_size(const gp_babel_packet_t *packet) {
|
||||
return sizeof(gp_babel_packet_t)+ntohs(packet->len);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#include "tlv.h"
|
||||
#include "tlv_types.h"
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
|
||||
static void add_ihus(gmrf_t *gmrf, gp_babel_packet_t *packet, size_t max_len, const gp_babel_iface_t *iface) {
|
||||
const gp_babel_neigh_t *neigh;
|
||||
|
@ -52,10 +50,7 @@ static void add_ihus(gmrf_t *gmrf, gp_babel_packet_t *packet, size_t max_len, co
|
|||
void gp_babel_send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx) {
|
||||
gmrf_logf(gmrf, LOG_DEBUG, "sending hellos...");
|
||||
|
||||
gp_babel_packet_t *packet = alloca(sizeof(gp_babel_packet_t)+GP_BABEL_PACKET_MAX);
|
||||
|
||||
packet->version = htons(GP_BABEL_VERSION);
|
||||
packet->len = 0;
|
||||
gp_babel_packet_t *packet = alloca_packet(GP_BABEL_PACKET_MAX);
|
||||
|
||||
gp_babel_tlv_hello_t *hello = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_HELLO, sizeof(gp_babel_tlv_hello_t));
|
||||
if (!hello)
|
||||
|
|
Reference in a new issue