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

Andrei Pelinescu-Onciul andrei at iptel.org
Sat Apr 30 01:03:12 CEST 2011


Module: sip-router
Branch: 3.1
Commit: 66af75fcdda45ed383f8493ea9b3d8b9b8c2cf47
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=66af75fcdda45ed383f8493ea9b3d8b9b8c2cf47

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
(cherry picked from commit 263ee122bc55f81db878ddea9ad4aa2bfd8afbae)

---

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

diff --git a/ser_stun.h b/ser_stun.h
index 1e6051b..c0356bc 100644
--- a/ser_stun.h
+++ b/ser_stun.h
@@ -126,8 +126,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