]> mj.ucw.cz Git - nwho.git/commitdiff
More nwho_pkt_size()
authorMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:55:29 +0000 (16:55 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:55:29 +0000 (16:55 +0100)
nwho.h
nwhod.c

diff --git a/nwho.h b/nwho.h
index 8413e9d19a59927f68f7fd969c32b3586eea45f0..91a4e73c99cd418061b4d9e82b780af8dec0aa44 100644 (file)
--- a/nwho.h
+++ b/nwho.h
@@ -5,6 +5,7 @@
  */
 
 #include <inttypes.h>
+#include <netinet/in.h>
 
 typedef uint32_t u32;
 
diff --git a/nwhod.c b/nwhod.c
index caa9f8f04fc2fda271a8e0426fbf73b05b852119..02e6a3f825e34f8e5e3792b654abb2dd6c111968 100644 (file)
--- 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;