From d413cc68dcb269551f0677b7c04da49f470d421b Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Thu, 20 Dec 2018 10:56:13 +0100 Subject: [PATCH] chg: [client] Fixed memory aligment artefacts --- client/d4.c | 15 +++++++++++++-- client/d4.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/d4.c b/client/d4.c index 941a2a2..db0ef2b 100644 --- a/client/d4.c +++ b/client/d4.c @@ -181,6 +181,7 @@ void d4_update_header(d4_t* d4, ssize_t nread) { void d4_transfert(d4_t* d4) { ssize_t nread; + ssize_t n; char* buf; unsigned char* hmac; @@ -204,8 +205,18 @@ void d4_transfert(d4_t* d4) hmac_sha256_final(d4->ctx, hmac, SZHMAC); //Add it to the header memcpy(d4->header.hmac, hmac, SZHMAC); - write(d4->destination.fd, &d4->header, sizeof(d4->header)); - write(d4->destination.fd,buf,nread); + n = 0; + n+=write(d4->destination.fd, &d4->header.version, sizeof(uint8_t)); + n+=write(d4->destination.fd, &d4->header.type, sizeof(uint8_t)); + n+=write(d4->destination.fd, &d4->header.uuid, SZUUID); + n+=write(d4->destination.fd, &d4->header.timestamp, sizeof(uint64_t)); + n+=write(d4->destination.fd, &d4->header.hmac, SZHMAC); + n+=write(d4->destination.fd, &d4->header.size, sizeof(uint32_t)); + n+=write(d4->destination.fd,buf,nread); + if (n != SZD4HDR + nread) { + fprintf(stderr,"Incomplete header written. abort to let consumer known that the packet is corrupted\n"); + abort(); + } } else{ //FIXME no data available, sleep, abort, retry break; diff --git a/client/d4.h b/client/d4.h index 7c91fc8..86912c9 100644 --- a/client/d4.h +++ b/client/d4.h @@ -14,6 +14,7 @@ #define MAXSNAPLEN 65535 #define SZUUID 16 #define SZUUID_TEXT 37 +#define SZD4HDR 62 #define INSERT_ERROR(...) do { \ if (d4->err_idx < NERRORS) \ snprintf(d4->errors[d4->err_idx],SZERRVALUE,__VA_ARGS__); \