]> mj.ucw.cz Git - nwho.git/commitdiff
Moved calculation of packet size to an extra function
authorMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:52:57 +0000 (16:52 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 31 Dec 2010 15:52:57 +0000 (16:52 +0100)
nwho.h
nwhod.c

diff --git a/nwho.h b/nwho.h
index 1c22c54f4e611b14768e0b6e7e49d9b4509d0dad..8413e9d19a59927f68f7fd969c32b3586eea45f0 100644 (file)
--- a/nwho.h
+++ b/nwho.h
@@ -40,3 +40,8 @@ struct nwho_pkt {
 
 #define STRINGIFY(x) STRINGIFY2(x)
 #define STRINGIFY2(x) #x
+
+static inline int nwho_pkt_size(struct nwho_pkt *pkt)
+{
+  return sizeof(struct nwho_pkt) - (MAX_USERS - ntohl(pkt->num_users))*sizeof(struct userinfo);
+}
diff --git a/nwhod.c b/nwhod.c
index b5fc22d288df218a6a023ffbfef165e28da99506..caa9f8f04fc2fda271a8e0426fbf73b05b852119 100644 (file)
--- a/nwhod.c
+++ b/nwhod.c
@@ -359,7 +359,7 @@ client(char *serv)
     {
       now = time(NULL);
       make_pkt(&pkt);
-      if (send(sock, &pkt, sizeof(pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo), 0) < 0)
+      if (send(sock, &pkt, nwho_pkt_size(&pkt), 0) < 0)
        syslog(LOG_ERR, "sendmsg: %m");
       sleep(DEFAULT_SEND_TIME);
     }