--- ../openser-1.0.0/modules/nathelper/nathelper.c.orig	2006-02-04 15:32:01.000000000 +0100
+++ nathelper.c	2006-02-12 12:40:15.081572563 +0100
@@ -267,6 +267,7 @@
 static const char sbuf[4] = {0, 0, 0, 0};
 static char *rtpproxy_sock = "unix:/var/run/rtpproxy.sock"; /* list */
 static char *force_socket_str = 0;
+static str contact_expander = { NULL, 0 };
 static int rtpproxy_disable = 0;
 static int rtpproxy_disable_tout = 60;
 static int rtpproxy_retr = 5;
@@ -321,6 +322,7 @@
 	{"force_socket",          STR_PARAM, &force_socket_str      },
 	{"sipping_from",          STR_PARAM, &sipping_from.s        },
 	{"sipping_method",        STR_PARAM, &sipping_method.s      },
+	{"contact_expander",      STR_PARAM, &contact_expander.s    },
 
 	{0, 0, 0}
 };
@@ -350,6 +352,11 @@
 		force_socket=grep_sock_info(&socket_str,0,0);
 	}
 
+	if (contact_expander.s) {
+		contact_expander.len = strlen(contact_expander.s);
+		LOG(L_INFO, "Expander String set to %s (%d)\n", contact_expander.s, contact_expander.len);
+	}
+
 	if (natping_interval > 0) {
 		bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
 		if (!bind_usrloc) {
@@ -704,16 +711,35 @@
 
 	cp = ip_addr2a(&msg->rcv.src_ip);
 	len = c->uri.len + strlen(cp) + 6 /* :port */ - hostport.len + 1;
+
+	if (contact_expander.len) {
+		LOG(L_DBG, "Expanding Contact: %s\n", contact_expander.s);
+		len += contact_expander.len + hostport.len + 20;
+	}
 	buf = pkg_malloc(len);
+
 	if (buf == NULL) {
 		LOG(L_ERR, "ERROR: fix_nated_contact: out of memory\n");
 		return -1;
 	}
+
 	temp[0] = hostport.s[0];
 	temp[1] = c->uri.s[c->uri.len];
 	c->uri.s[c->uri.len] = hostport.s[0] = '\0';
-	len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp, msg->rcv.src_port,
-	    hostport.s + hostport.len);
+
+	if (contact_expander.len) {
+		// sip:user:password@host:port ->
+		// sip:user:password@HOST:PORT;x-orig=host:port
+		len1 = snprintf(buf, len, "%s%s;x-orig=%s:%d;x-orig-nat=%c%s", c->uri.s,
+			contact_expander.s,
+			cp, msg->rcv.src_port,
+			temp[0],
+			hostport.s + 1);
+	} else {
+		len1 = snprintf(buf, len, "%s%s:%d%s", c->uri.s, cp, msg->rcv.src_port,
+			hostport.s + hostport.len);
+	}
+
 	if (len1 < len)
 		len = len1;
 	hostport.s[0] = temp[0];
