[Devel] [ openser-Bugs-1614192 ] Socket str description is malformed on big-endian platforms

SourceForge.net noreply at sourceforge.net
Tue Dec 12 19:43:46 CET 2006


Bugs item #1614192, was opened at 2006-12-12 13:43
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743020&aid=1614192&group_id=139143

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: core
Group: ver devel
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Ovidiu Sas (osas)
Assigned to: Nobody/Anonymous (nobody)
Summary: Socket str description is malformed on big-endian platforms

Initial Comment:
The way that socket string description is constructed is not compatible with big endian platforms.
Here's a patch that will fix the problem:

# cvs diff -Nu socket_info.h
Index: socket_info.h
===================================================================
RCS file: /cvsroot/openser/sip-server/socket_info.h,v
retrieving revision 1.4
diff -u -r1.4 socket_info.h
--- socket_info.h	13 Dec 2005 13:38:30 -0000	1.4
+++ socket_info.h	12 Dec 2006 18:42:12 -0000
@@ -241,11 +241,6 @@
 
 static inline char* socket2str(struct socket_info *sock, char *s, int* len)
 {
-#define PROTOC2UINT(a, b, c, d) htonl((	(((unsigned int)(a))<<24)+ \
-								(((unsigned int)(b))<<16)+  \
-								(((unsigned int)(c))<<8)+  \
-								((unsigned int)(d)) ) | 0x20202020)
-
 	static char buf[MAX_SOCKET_STR];
 	char *p,*p1;
 
@@ -262,26 +257,31 @@
 
 	switch (sock->proto) {
 		case PROTO_UDP:
-			*((unsigned int*)p) = PROTOC2UINT('u', 'd', 'p', ':');
-			p += 4;
+			*(p++) = 'u';
+			*(p++) = 'd';
+			*(p++) = 'p';
 			break;
 		case PROTO_TCP:
-			*((unsigned int*)p) = PROTOC2UINT('t', 'c', 'p', ':');
-			p += 4;
+			*(p++) = 't';
+			*(p++) = 'c';
+			*(p++) = 'p';
 			break;
 		case PROTO_TLS:
-			*((unsigned int*)p) = PROTOC2UINT('t', 'l', 's', ':');
-			p += 4;
+			*(p++) = 't';
+			*(p++) = 'l';
+			*(p++) = 's';
 			break;
 		case PROTO_SCTP:
-			*((unsigned int*)p) = PROTOC2UINT('s', 'c', 't', 'p');
-			p += 4;
-			*(p++) = ':';
+			*(p++) = 's';
+			*(p++) = 'c';
+			*(p++) = 't';
+			*(p++) = 'p';
 			break;
 		default:
 			LOG(L_CRIT,"BUG:socket2str: unsupported proto %d\n", sock->proto);
 			return 0;
 	}
+	*(p++) = ':';
 	memcpy( p, sock->address_str.s, sock->address_str.len);
 	p += sock->address_str.len;
 	*(p++) = ':';

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743020&aid=1614192&group_id=139143



More information about the Devel mailing list