[SR-Dev] git:master: port from kamailio 1.5 branch r5795, related to bug #2416621

Henning Westerholt henning.westerholt at 1und1.de
Thu Apr 16 14:11:25 CEST 2009


Module: sip-router
Branch: master
Commit: 4ae3936acf4cf24fd28abcf46826277cb85c3a8a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4ae3936acf4cf24fd28abcf46826277cb85c3a8a

Author: Henning Westerholt <henning.westerholt at 1und1.de>
Committer: Henning Westerholt <henning.westerholt at 1und1.de>
Date:   Thu Apr 16 14:11:04 2009 +0200

port from kamailio 1.5 branch r5795, related to bug #2416621

---

 modules_k/nat_traversal/nat_traversal.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/modules_k/nat_traversal/nat_traversal.c b/modules_k/nat_traversal/nat_traversal.c
index 86e2731..dfe7e4d 100644
--- a/modules_k/nat_traversal/nat_traversal.c
+++ b/modules_k/nat_traversal/nat_traversal.c
@@ -1,6 +1,6 @@
 /* $Id$
  *
- * Copyright (C) 2007-2008 Dan Pascu
+ * Copyright (C) 2007-2009 Dan Pascu
  *
  * This file is part of Kamailio, a free SIP server.
  *
@@ -1406,23 +1406,26 @@ NAT_Keepalive(struct sip_msg *msg)
 static int
 FixContact(struct sip_msg *msg)
 {
-    str before_host, after;
+    str before_host, after, newip;
+    unsigned short port, newport;
     contact_t* contact;
     struct lump* anchor;
     struct sip_uri uri;
-    char *newip, *buf;
-    int len, newiplen, offset;
+    int len, offset;
+    char *buf;
 
     if (!get_contact_uri(msg, &uri, &contact))
         return -1;
 
-    newip = ip_addr2a(&msg->rcv.src_ip);
-    newiplen = strlen(newip);
+    newip.s = ip_addr2a(&msg->rcv.src_ip);
+    newip.len = strlen(newip.s);
+    newport = msg->rcv.src_port;
 
-    // Don't do anything if the IP's are the same, just return success.
-    if (newiplen==uri.host.len && memcmp(uri.host.s, newip, newiplen)==0) {
+    port = uri.port_no ? uri.port_no : 5060;
+
+    // Don't do anything if the address is the same, just return success.
+    if (STR_MATCH_STR(uri.host, newip) && port==newport)
         return 1;
-    }
 
     if (uri.port.len == 0)
         uri.port.s = uri.host.s + uri.host.len;
@@ -1432,7 +1435,7 @@ FixContact(struct sip_msg *msg)
     after.s   = uri.port.s + uri.port.len;
     after.len = contact->uri.s + contact->uri.len - after.s;
 
-    len = before_host.len + newiplen + after.len + 20;
+    len = before_host.len + newip.len + after.len + 20;
 
     // first try to alloc mem. if we fail we don't want to have the lump
     // deleted and not replaced. at least this way we keep the original.
@@ -1451,7 +1454,7 @@ FixContact(struct sip_msg *msg)
     }
 
     len = sprintf(buf, "%.*s%s:%d%.*s", before_host.len, before_host.s,
-                  newip, msg->rcv.src_port, after.len, after.s);
+                  newip.s, newport, after.len, after.s);
 
     if (insert_new_lump_after(anchor, buf, len, HDR_CONTACT_F) == 0) {
         pkg_free(buf);




More information about the sr-dev mailing list