From 7e96505b7ad68a8c41ca15482835881d19413014 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 31 Dec 2010 16:28:47 +0100 Subject: [PATCH] Let save_pkt() calculates the packet length internally --- nwhod.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nwhod.c b/nwhod.c index af38e85..9447d6a 100644 --- a/nwhod.c +++ b/nwhod.c @@ -170,8 +170,9 @@ cleanup(void) } static void -save_pkt(char *name, struct nwho_pkt *pkt, int len) +save_pkt(char *name, struct nwho_pkt *pkt) { + int len = sizeof(pkt) - (MAX_USERS - ntohl(pkt->num_users))*sizeof(struct userinfo); int fd = open(name, O_WRONLY | O_CREAT, 0666); if (fd < 0) { @@ -267,7 +268,7 @@ receive(void) } e->last_rec = now; - save_pkt(e->name, &pkt, r); + save_pkt(e->name, &pkt); } static void @@ -279,7 +280,7 @@ local_scan(void) make_pkt(&pkt); if (!hostname[0] && gethostname(hostname, sizeof(hostname)) < 0) die("gethostname: %m"); - save_pkt(hostname, &pkt, sizeof(pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo)); + save_pkt(hostname, &pkt); } static void -- 2.39.5