From c6980635231ca7b6aebdb4ec27efe3c8e3fd55b5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 31 Dec 2010 16:55:29 +0100 Subject: [PATCH] More nwho_pkt_size() --- nwho.h | 1 + nwhod.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nwho.h b/nwho.h index 8413e9d..91a4e73 100644 --- a/nwho.h +++ b/nwho.h @@ -5,6 +5,7 @@ */ #include +#include typedef uint32_t u32; diff --git a/nwhod.c b/nwhod.c index caa9f8f..02e6a3f 100644 --- a/nwhod.c +++ b/nwhod.c @@ -176,7 +176,7 @@ cleanup(void) static void save_pkt(char *name, struct nwho_pkt *pkt) { - int len = sizeof(pkt) - (MAX_USERS - ntohl(pkt->num_users))*sizeof(struct userinfo); + int len = nwho_pkt_size(pkt); int fd = open(name, O_WRONLY | O_CREAT, 0666); if (fd < 0) { @@ -230,7 +230,7 @@ receive(void) if (r < n || pkt.magic != htonl(NWHO_MAGIC) || ntohl(pkt.num_users) > MAX_USERS || - r != n + ntohl(pkt.num_users)*sizeof(struct userinfo)) + r < nwho_pkt_size(&pkt)) { syslog(LOG_WARNING, "Malformed packet from %s", inet_ntoa(sa.sin_addr)); return; -- 2.39.2