From 0d4c8b594a61af4343d27ee4b4053cdc4bb3a65d Mon Sep 17 00:00:00 2001 From: Heikki Hannikainen Date: Thu, 27 Jun 2013 00:54:30 +0300 Subject: [PATCH] aprsis2: write header and tail around outgoing message --- src/aprsis2.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/aprsis2.c b/src/aprsis2.c index 40cf222..3a29c66 100644 --- a/src/aprsis2.c +++ b/src/aprsis2.c @@ -5,6 +5,22 @@ #include "aprsis2.pb-c.h" #include "version.h" +#define IS2_HEAD_LEN 4 +#define IS2_TAIL_LEN 1 + +static void *is2_allocate_buffer(int len) +{ + int nlen = len + IS2_HEAD_LEN + IS2_TAIL_LEN; + char *buf = hmalloc(nlen); + uint32_t *ip = (uint32_t *)buf; + + *ip = htonl(len); + + buf[nlen-1] = '\n'; + + return (void *)buf; +} + int is2_out_server_signature(struct worker_t *self, struct client_t *c) { ServerSignature sig = SERVER_SIGNATURE__INIT; @@ -14,17 +30,17 @@ int is2_out_server_signature(struct worker_t *self, struct client_t *c) sig.app_name = verstr_progname; sig.app_version = version_build; len = server_signature__get_packed_size(&sig); - buf = hmalloc(len); - server_signature__pack(&sig, buf); + buf = is2_allocate_buffer(len); + server_signature__pack(&sig, buf + IS2_HEAD_LEN); - c->write(self, c, buf, len); + c->write(self, c, buf, len + IS2_HEAD_LEN + IS2_TAIL_LEN); hfree(buf); return 0; } -int is2_in_server_signature(struct worker_t *self, struct client_t *c) +int is2_data_in(struct worker_t *self, struct client_t *c) { return 0; }