[Asterisk-cvs] asterisk aesopt.h, 1.8, 1.9 dns.c, 1.11, 1.12 md5.c, 1.9, 1.10 rtp.c, 1.116, 1.117

markster at lists.digium.com markster at lists.digium.com
Mon Mar 28 22:55:39 CST 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv6904

Modified Files:
	aesopt.h dns.c md5.c rtp.c 
Log Message:
Simplify endianness and fix for unaligned reads (bug #3867)


Index: aesopt.h
===================================================================
RCS file: /usr/cvsroot/asterisk/aesopt.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- aesopt.h	14 Dec 2004 23:36:29 -0000	1.8
+++ aesopt.h	29 Mar 2005 04:49:24 -0000	1.9
@@ -136,6 +136,7 @@
 #define _AESOPT_H
 
 #include <asterisk/aes.h>
+#include <asterisk/endian.h>
 
 /*  CONFIGURATION - USE OF DEFINES
 
@@ -146,27 +147,6 @@
     #if clauses.
 */
 
-/*  PLATFORM SPECIFIC INCLUDES */
-
-#if defined( __OpenBSD__ )
-#  include <machine/types.h>
-#  include <sys/endian.h>
-#elif defined( __FreeBSD__ ) || defined( __NetBSD__ )
-#  include <sys/types.h>
-#  include <sys/endian.h>
-#elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__)
-#  include <machine/endian.h>
-#elif defined ( SOLARIS )
-#  include <solaris-compat/compat.h>
-#elif defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
-#  include <endian.h>
-#if !defined(__APPLE__)
-#  include <byteswap.h>
-#endif
-#elif defined( linux )
-#  include <endian.h>
-#endif
-
 /*  BYTE ORDER IN 32-BIT WORDS
 
     To obtain the highest speed on processors with 32-bit words, this code

Index: dns.c
===================================================================
RCS file: /usr/cvsroot/asterisk/dns.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dns.c	2 Mar 2005 05:17:13 -0000	1.11
+++ dns.c	29 Mar 2005 04:49:24 -0000	1.12
@@ -19,12 +19,13 @@
 #include <asterisk/logger.h>
 #include <asterisk/channel.h>
 #include <asterisk/dns.h>
+#include <asterisk/endian.h>
 
 #define MAX_SIZE 4096
 
 typedef struct {
 	unsigned	id :16;		/* query identification number */
-#if BYTE_ORDER == BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
 			/* fields in third byte */
 	unsigned	qr: 1;		/* response flag */
 	unsigned	opcode: 4;	/* purpose of message */
@@ -38,7 +39,7 @@
 	unsigned	cd: 1;		/* checking disabled by resolver */
 	unsigned	rcode :4;	/* response code */
 #endif
-#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN
 			/* fields in third byte */
 	unsigned	rd :1;		/* recursion desired */
 	unsigned	tc :1;		/* truncated message */

Index: md5.c
===================================================================
RCS file: /usr/cvsroot/asterisk/md5.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- md5.c	14 Dec 2004 23:36:29 -0000	1.9
+++ md5.c	29 Mar 2005 04:49:24 -0000	1.10
@@ -1,22 +1,5 @@
 /* MD5 checksum routines used for authentication.  Not covered by GPL, but
    in the public domain as per the copyright below */
-#if defined( __OpenBSD__ )
-#  include <machine/types.h>
-#  include <sys/endian.h>
-#elif defined( __FreeBSD__ ) || defined( __NetBSD__ )
-#  include <sys/types.h>
-#  include <sys/endian.h>
-#elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__)
-#  include <machine/endian.h>
-#elif defined( __sparc__ ) && defined( SOLARIS )
-#  define BIG_ENDIAN 4321
-#  define BYTE_ORDER BIG_ENDIAN
-#else
-#  include <endian.h>
-#endif
-# if __BYTE_ORDER == __BIG_ENDIAN || BYTE_ORDER == BIG_ENDIAN
-#  define HIGHFIRST 1
-# endif
 
 /*
  * This code implements the MD5 message-digest algorithm.
@@ -35,8 +18,12 @@
  * will fill a supplied 16-byte array with the digest.
  */
 #include <string.h>		/* for memcpy() */
+#include <asterisk/endian.h>
 #include <asterisk/md5.h>
 
+# if __BYTE_ORDER == __BIG_ENDIAN
+#  define HIGHFIRST 1
+# endif
 #ifndef HIGHFIRST
 #define byteReverse(buf, len)	/* Nothing */
 #else

Index: rtp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/rtp.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- rtp.c	25 Mar 2005 21:01:11 -0000	1.116
+++ rtp.c	29 Mar 2005 04:49:24 -0000	1.117
@@ -37,6 +37,7 @@
 #include <asterisk/lock.h>
 #include <asterisk/utils.h>
 #include <asterisk/cli.h>
+#include <asterisk/unaligned.h>
 
 #define MAX_TIMESTAMP_SKEW	640
 
@@ -1173,18 +1174,6 @@
 	return 0;
 }
 
-#if defined(SOLARIS) && defined(__sparc__)
-static void put_uint32(unsigned char *buf, int i)
-{
-	buf[0] = (i>>24) & 0xff;
-	buf[1] = (i>>16) & 0xff;
-	buf[2] = (i>>8)  & 0xff;
-	buf[3] = i       & 0xff;
-}
-#else
-#define put_uint32(p,v) ((*((unsigned int *)(p))) = (v))
-#endif
-
 static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec)
 {
 	unsigned char *rtpheader;
@@ -1270,9 +1259,9 @@
 	/* Get a pointer to the header */
 	rtpheader = (unsigned char *)(f->data - hdrlen);
 
-	put_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (rtp->seqno) | (mark << 23)));
-	put_uint32(rtpheader + 4, htonl(rtp->lastts));
-	put_uint32(rtpheader + 8, htonl(rtp->ssrc)); 
+	put_unaligned_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (rtp->seqno) | (mark << 23)));
+	put_unaligned_uint32(rtpheader + 4, htonl(rtp->lastts));
+	put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc)); 
 
 	if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
 		res = sendto(rtp->s, (void *)rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));




More information about the svn-commits mailing list