[sr-dev] git:master: stun: fix padd macros

Andrei Pelinescu-Onciul andrei at iptel.org
Sat Apr 30 00:53:53 CEST 2011


Module: sip-router
Branch: master
Commit: 263ee122bc55f81db878ddea9ad4aa2bfd8afbae
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=263ee122bc55f81db878ddea9ad4aa2bfd8afbae

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Sat Apr 30 00:08:11 2011 +0200

stun: fix padd macros

The PADDED_TO_* macros did not work when the length was a multiple
of the pad value.
(FS#129)

Reported-by: Francesco Castellano

---

 ser_stun.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ser_stun.h b/ser_stun.h
index b287a78..55e8145 100644
--- a/ser_stun.h
+++ b/ser_stun.h
@@ -124,8 +124,13 @@ typedef unsigned long	ULONG_T;
 #define XOR				1
 #define TRANSACTION_ID	12
 
-#define PADDED_TO_FOUR(len) (len == 0) ? 0 : len + (PAD4 - len%PAD4)
-#define PADDED_TO_SIXTYFOUR(len) (len == 0) ? 0 : len + (PAD64 - len%PAD64)
+/** padd len to a multiple of sz.
+ *  sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...)
+ */
+#define PADD_TO(len, sz)	(((len) + (sz)-1) & (~((sz) - 1)))
+
+#define PADDED_TO_FOUR(len) PADD_TO(len, 4)
+#define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64)
 
 struct transaction_id {
 	UINT_T	magic_cookie;




More information about the sr-dev mailing list