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

SourceForge.net noreply at sourceforge.net
Wed Dec 13 15:42:18 CET 2006


Bugs item #1614192, was opened at 2006-12-12 13:43
Message generated for change (Comment added) made by osas
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: Invalid
Priority: 5
Private: No
Submitted By: Ovidiu Sas (osas)
Assigned to: Bogdan (bogdan_iancu)
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++) = ':';

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

>Comment By: Ovidiu Sas (osas)
Date: 2006-12-13 09:42

Message:
Logged In: YES 
user_id=1395524
Originator: YES

Hi Bogdan,

I was compiling on arm big endian and It didn't come up properly for me. 
I noticed when I was trying to use dbtext for usrloc (this is how I noticed
and that's why I submitted the other patch for the output of the fifo
usrloc show command).  With this patch, I was able to use the dbtext.

Regards,
Ovidiu Sas

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

Comment By: Bogdan (bogdan_iancu)
Date: 2006-12-13 09:12

Message:
Logged In: YES 
user_id=1275325
Originator: NO

Ovidiu,

I am not so sure if it a bug. First of all the htonl function is used,
which gives you arch. independency. Secondly, I just tried on a sparc
machine (big endian) and the string was properly generated.

regards,
bogdan

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

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