]> mj.ucw.cz Git - nwho.git/commitdiff
Let save_pkt() calculates the packet length internally
authorMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:28:47 +0000 (16:28 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:28:47 +0000 (16:28 +0100)
nwhod.c

diff --git a/nwhod.c b/nwhod.c
index af38e85e93bc10953229e91f0f4e51ff4d2d26f3..9447d6a93bf7d129766c577bda3a7931797f5ee7 100644 (file)
--- 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