[sr-dev] git:master:814c08f3: nathelper: enclode IPv6 in square branckets for fix_nated_contact()

Daniel-Constantin Mierla miconda at gmail.com
Thu Jan 22 22:37:28 CET 2015


Module: kamailio
Branch: master
Commit: 814c08f36f13ace21e52181da3039402f951b0a8
URL: https://github.com/kamailio/kamailio/commit/814c08f36f13ace21e52181da3039402f951b0a8

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-01-22T22:37:16+01:00

nathelper: enclode IPv6 in square branckets for fix_nated_contact()

- even there is no nat in ipv6

---

Modified: modules/nathelper/nathelper.c

---

Diff:  https://github.com/kamailio/kamailio/commit/814c08f36f13ace21e52181da3039402f951b0a8.diff
Patch: https://github.com/kamailio/kamailio/commit/814c08f36f13ace21e52181da3039402f951b0a8.patch

---

diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c
index 3123751..20500d2 100644
--- a/modules/nathelper/nathelper.c
+++ b/modules/nathelper/nathelper.c
@@ -803,6 +803,8 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
 
 	cp = ip_addr2a(&msg->rcv.src_ip);
 	len = c->uri.len + strlen(cp) + 6 /* :port */ - hostport.len + 1;
+	if(msg->rcv.src_ip.af==AF_INET6)
+		len += 2;
 	buf = pkg_malloc(len);
 	if (buf == NULL) {
 		LM_ERR("out of pkg memory\n");
@@ -812,8 +814,13 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
 	temp[1] = c->uri.s[c->uri.len];
 	c->uri.s[c->uri.len] = hostport.s[0] = '\0';
 	if(uri.maddr.len<=0) {
-		len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp, msg->rcv.src_port,
-		    hostport.s + hostport.len);
+		if(msg->rcv.src_ip.af==AF_INET6) {
+			len1 = snprintf(buf, len, "%s[%s]:%d%s", c->uri.s, cp,
+					msg->rcv.src_port, hostport.s + hostport.len);
+		} else {
+			len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp,
+					msg->rcv.src_port, hostport.s + hostport.len);
+		}
 	} else {
 		/* skip maddr parameter - makes no sense anymore */
 		LM_DBG("removing maddr parameter from contact uri: [%.*s]\n",
@@ -827,8 +834,15 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
 			params1.len--;
 		params2.s = uri.maddr.s + uri.maddr.len;
 		params2.len = c->uri.s + c->uri.len - params2.s;
-		len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp, msg->rcv.src_port,
-		    params1.len, params1.s, params2.len, params2.s);
+		if(msg->rcv.src_ip.af==AF_INET6) {
+			len1 = snprintf(buf, len, "%s[%s]:%d%.*s%.*s", c->uri.s, cp,
+					msg->rcv.src_port, params1.len, params1.s,
+					params2.len, params2.s);
+		} else {
+			len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp,
+					msg->rcv.src_port, params1.len, params1.s,
+					params2.len, params2.s);
+		}
 	}
 	if (len1 < len)
 		len = len1;




More information about the sr-dev mailing list