Browse code

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

Henning Westerholt authored on 16/04/2009 12:11:04
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /* $Id$
2 2
  *
3
- * Copyright (C) 2007-2008 Dan Pascu
3
+ * Copyright (C) 2007-2009 Dan Pascu
4 4
  *
5 5
  * This file is part of Kamailio, a free SIP server.
6 6
  *
... ...
@@ -1406,23 +1406,26 @@ NAT_Keepalive(struct sip_msg *msg)
1406 1406
 static int
1407 1407
 FixContact(struct sip_msg *msg)
1408 1408
 {
1409
-    str before_host, after;
1409
+    str before_host, after, newip;
1410
+    unsigned short port, newport;
1410 1411
     contact_t* contact;
1411 1412
     struct lump* anchor;
1412 1413
     struct sip_uri uri;
1413
-    char *newip, *buf;
1414
-    int len, newiplen, offset;
1414
+    int len, offset;
1415
+    char *buf;
1415 1416
 
1416 1417
     if (!get_contact_uri(msg, &uri, &contact))
1417 1418
         return -1;
1418 1419
 
1419
-    newip = ip_addr2a(&msg->rcv.src_ip);
1420
-    newiplen = strlen(newip);
1420
+    newip.s = ip_addr2a(&msg->rcv.src_ip);
1421
+    newip.len = strlen(newip.s);
1422
+    newport = msg->rcv.src_port;
1421 1423
 
1422
-    // Don't do anything if the IP's are the same, just return success.
1423
-    if (newiplen==uri.host.len && memcmp(uri.host.s, newip, newiplen)==0) {
1424
+    port = uri.port_no ? uri.port_no : 5060;
1425
+
1426
+    // Don't do anything if the address is the same, just return success.
1427
+    if (STR_MATCH_STR(uri.host, newip) && port==newport)
1424 1428
         return 1;
1425
-    }
1426 1429
 
1427 1430
     if (uri.port.len == 0)
1428 1431
         uri.port.s = uri.host.s + uri.host.len;
... ...
@@ -1432,7 +1435,7 @@ FixContact(struct sip_msg *msg)
1432 1435
     after.s   = uri.port.s + uri.port.len;
1433 1436
     after.len = contact->uri.s + contact->uri.len - after.s;
1434 1437
 
1435
-    len = before_host.len + newiplen + after.len + 20;
1438
+    len = before_host.len + newip.len + after.len + 20;
1436 1439
 
1437 1440
     // first try to alloc mem. if we fail we don't want to have the lump
1438 1441
     // deleted and not replaced. at least this way we keep the original.
... ...
@@ -1451,7 +1454,7 @@ FixContact(struct sip_msg *msg)
1451 1454
     }
1452 1455
 
1453 1456
     len = sprintf(buf, "%.*s%s:%d%.*s", before_host.len, before_host.s,
1454
-                  newip, msg->rcv.src_port, after.len, after.s);
1457
+                  newip.s, newport, after.len, after.s);
1455 1458
 
1456 1459
     if (insert_new_lump_after(anchor, buf, len, HDR_CONTACT_F) == 0) {
1457 1460
         pkg_free(buf);