From 475971cb15e2ae97f8e90ffa76c7d455103c4901 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandresavard@alexandresavard-desktop.(none)>
Date: Tue, 5 Jan 2010 11:30:00 -0500
Subject: [PATCH] [#2623] Fix published address for TLS transport if default
 interface selected

---
 sflphone-common/src/sip/sipvoiplink.cpp | 38 +++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index 8e40585318..51b6beb62c 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -2691,11 +2691,25 @@ pj_status_t SIPVoIPLink::createTlsTransport (AccountID id)
         local_addr.sin_port = pj_htons (localTlsPort);
     }
 
+    /*
+    std::string localAddress;
+    if (account->getLocalInterface() == "default"){
+
+        // Current selected interface address is 0.0.0.0, resolve local address using  
+        loadSIPLocalIP (&localAddress);
+    }
+    else {
+
+        // Specific interface selected, reslove it
+        localAddress = getInterfaceAddrFromName(account->getLocalInterface());
+    }
+    */
+
     std::string localAddress = getInterfaceAddrFromName(account->getLocalInterface());
 
     if (!localAddress.empty()) {
         pj_str_t pjAddress;
-        pj_cstr (&pjAddress, (getInterfaceAddrFromName(account->getLocalInterface())).c_str());
+        pj_cstr (&pjAddress, localAddress.c_str());
 
         pj_status_t success;
         success = pj_sockaddr_in_set_str_addr (&local_addr, &pjAddress);
@@ -2705,10 +2719,30 @@ pj_status_t SIPVoIPLink::createTlsTransport (AccountID id)
         }
     }
 
+    std::string publishedAddress;
+    if (account->getPublishedSameasLocal()) {
+
+        // if "default" interface is selected, loadSIPLocalIP() is used to get local address
+        if (account->getLocalInterface() == "default"){
+
+	    loadSIPLocalIP (&publishedAddress);
+	}
+	else {
+
+	    // Specific interface selected
+	    publishedAddress = localAddress;
+	}   
+    }
+    else {
+
+        publishedAddress = account->getPublishedAddress();
+    }
+
+
     /* Init published name */
     pj_bzero (&a_name, sizeof (pjsip_host_port));
 
-    pj_cstr (&a_name.host, (account->getPublishedAddress()).c_str());
+    pj_cstr (&a_name.host, publishedAddress.c_str());
 
     a_name.port = account->getPublishedPort();
 
-- 
GitLab