From: Martin Mares Date: Fri, 31 Dec 2010 15:55:29 +0000 (+0100) Subject: More nwho_pkt_size() X-Git-Tag: v1.13~10 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c6980635231ca7b6aebdb4ec27efe3c8e3fd55b5;p=nwho.git More nwho_pkt_size() --- 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;