[Devel] Patch: nathelper.c session-level c= enhancement

Bayan Towfiq bayan at towfiq.com
Tue Mar 28 10:00:07 CEST 2006


Skipped content of type multipart/alternative-------------- next part --------------
--- sip-server-old/modules/nathelper/nathelper.c	2006-03-27 23:52:16.000000000 -0800
+++ sip-server/modules/nathelper/nathelper.c	2006-03-27 23:54:50.000000000 -0800
@@ -146,6 +146,9 @@
  *             add_rcv_param() may take as parameter a flag telling if the
  *              parameter should go to the contact URI or contact header;
  *             (bogdan)
+ *
+ * 2006-03-27 Support for changing session-level SDP connection (c=) IP when
+ *            media-description also includes connection information (bayan)
  */
 
 #include <sys/types.h>
@@ -1873,19 +1876,12 @@
 			/* c2p will point to per-media "c=" */
 			c2p = find_sdp_line(m1p, m2p, 'c');
 			/* Extract address and port */
-			tmpstr1.s = c2p ? c2p : c1p;
-			if (tmpstr1.s == NULL) {
+			if (!c1p && !c2p) {
 				/* No "c=" */
 				LOG(L_ERR, "ERROR: force_rtp_proxy2: can't"
 				    " find media IP in the message\n");
 				return -1;
 			}
-			tmpstr1.len = v2p - tmpstr1.s; /* limit is session limit text */
-			if (extract_mediaip(&tmpstr1, &oldip, &pf,"c=") == -1) {
-				LOG(L_ERR, "ERROR: force_rtp_proxy2: can't"
-				    " extract media IP from the message\n");
-				return -1;
-			}
 			tmpstr1.s = m1p;
 			tmpstr1.len = m2p - m1p;
 			if (extract_mediaport(&tmpstr1, &oldport) == -1) {
@@ -1980,13 +1976,36 @@
 			 * Alter IP. Don't alter IP common for the session
 			 * more than once.
 			 */
-			if (c2p != NULL || !c1p_altered) {
-				body1.s = c2p ? c2p : c1p;
+			if (c2p) {
+				tmpstr1.s = c2p;
+				tmpstr1.len = v2p - tmpstr1.s; /* limit is session limit text */
+				if (extract_mediaip(&tmpstr1, &oldip, &pf,"c=") == -1) {
+					LOG(L_ERR, "ERROR: force_rtp_proxy2: can't"
+					    " extract media IP from the message\n");
+					return -1;
+				}
+				body1.s = c2p;
+				body1.len = bodylimit - body1.s;
+				if (alter_mediaip(msg, &body1, &oldip, pf, &newip, pf1, 0)==-1)
+					return -1;
+			}
+			/*
+			 * Bayan Towfiq: Hack to mangle c1p in addition to c2p when we have
+			 * both in a message
+			 */
+			if(c1p && !c1p_altered) { 
+				tmpstr1.s = c1p;
+				tmpstr1.len = v2p - tmpstr1.s; /* limit is session limit text */
+				if (extract_mediaip(&tmpstr1, &oldip, &pf,"c=") == -1) {
+					LOG(L_ERR, "ERROR: force_rtp_proxy2: can't"
+						" extract media IP from the first 'c' in the message\n");
+					return -1;
+				}
+				body1.s = c1p;
 				body1.len = bodylimit - body1.s;
 				if (alter_mediaip(msg, &body1, &oldip, pf, &newip, pf1, 0)==-1)
 					return -1;
-				if (!c2p)
-					c1p_altered = 1;
+				c1p_altered = 1;
 			}
 			/*
 			 * Alter the IP in "o=", but only once per session


More information about the Devel mailing list