From: Martin Mares Date: Fri, 31 Dec 2010 15:52:57 +0000 (+0100) Subject: Moved calculation of packet size to an extra function X-Git-Tag: v1.13~11 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=690ef49a417fb0c519624ce4ee463e96625aff7f;p=nwho.git Moved calculation of packet size to an extra function --- diff --git a/nwho.h b/nwho.h index 1c22c54..8413e9d 100644 --- 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 b5fc22d..caa9f8f 100644 --- 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); }